Last active
July 13, 2023 02:22
-
-
Save Lonenso/05b85e1c3814419335916ed6482913ef to your computer and use it in GitHub Desktop.
sentry demo
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="UTF-8"> | |
<!-- https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP --> | |
<meta http-equiv="Content-Security-Policy" content="default-src 'self'; script-src 'self'; style-src 'self' 'unsafe-inline'"> | |
<title>Hello World!</title> | |
</head> | |
<body> | |
<h1>Hello World!</h1> | |
</body> | |
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Modules to control application life and create native browser window | |
const { app, BrowserWindow } = require('electron') | |
const path = require('path') | |
const Sentry = require('@sentry/electron') | |
const fs = require('fs') | |
const file = path.join(__dirname, 'log.txt') | |
const fileStream = fs.createWriteStream(file, {flags:'a'}) | |
console.log(file) | |
console.log = (msg, ...args) => { | |
fileStream.write(`${msg} ${args}\n`) | |
} | |
Sentry.init({ | |
dsn: "replacew with your dsn", | |
release: "peter.xie-1.1", | |
debug: true, | |
autoSessionTracking: true, | |
}); | |
function createWindow () { | |
// Create the browser window. | |
const mainWindow = new BrowserWindow({ | |
width: 800, | |
height: 600, | |
webPreferences: { | |
preload: path.join(__dirname, 'preload.js') | |
} | |
}) | |
// and load the index.html of the app. | |
mainWindow.loadFile('index.html') | |
// Open the DevTools. | |
// mainWindow.webContents.openDevTools() | |
} | |
// This method will be called when Electron has finished | |
// initialization and is ready to create browser windows. | |
// Some APIs can only be used after this event occurs. | |
app.whenReady().then(() => { | |
createWindow() | |
app.on('activate', function () { | |
// On macOS it's common to re-create a window in the app when the | |
// dock icon is clicked and there are no other windows open. | |
if (BrowserWindow.getAllWindows().length === 0) createWindow() | |
}) | |
}) | |
// Quit when all windows are closed, except on macOS. There, it's common | |
// for applications and their menu bar to stay active until the user quits | |
// explicitly with Cmd + Q. | |
app.on('window-all-closed', function () { | |
if (process.platform !== 'darwin') app.quit() | |
}) | |
let events = [ | |
'before-quit', | |
'will-quit', | |
'quit', | |
'render-process-gone', | |
'child-process-gone', | |
] | |
// https://www.gnu.org/software/libc/manual/html_node/Termination-Signals.html | |
// https://nodejs.org/api/process.html#signal-events | |
let signals = [ | |
"SIGINT", | |
"SIGTERM", | |
"SIGQUIT", | |
"SIGHUP", | |
// "SIGKILL", we can not catch this signal because it's used to cause immediate program termination. see | |
// https://github.com/nodejs/node-v0.x-archive/issues/6339 | |
] | |
for (let e of events) { | |
app.on(e, () => { | |
console.log(`[MAIN] received event: ${e}`) | |
}) | |
} | |
for (let s of signals) { | |
process.on(s, () => { | |
console.log(`[MAIN] received signal ${s}`) | |
}) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "obscene-doctor-rhyme-bfpcs", | |
"productName": "obscene-doctor-rhyme-bfpcs", | |
"description": "My Electron application description", | |
"keywords": [], | |
"main": "./main.js", | |
"version": "1.0.0", | |
"author": "peter.xie", | |
"scripts": { | |
"start": "electron ." | |
}, | |
"dependencies": { | |
"@sentry/electron": "4.4.0" | |
}, | |
"devDependencies": { | |
"electron": "20.0.1" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment