Created
July 28, 2023 02:20
-
-
Save Lonenso/5156d8678e206e6af9aa7021867835e1 to your computer and use it in GitHub Desktop.
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> | |
<button id="crash-main"> crash main </button> | |
<script src="./index.js"></script> | |
</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
document.querySelector('#crash-main').addEventListener('click', () => { | |
window.crash.main() | |
}); |
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, ipcMain } = require('electron') | |
const path = require('path') | |
const Sentry = require('@sentry/electron') | |
Sentry.init({ | |
dsn: "replace 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') | |
mainWindow.webContents.on('did-finish-load', (e) => { | |
console.log('did-finish-load'); | |
}) | |
// 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}`) | |
}) | |
} | |
// ipcMain handle begins | |
ipcMain.handle('crash-main', (event) => { | |
console.log('crash-main'); | |
process.crash(); | |
}) |
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": "dull-sponge-spit-px681", | |
"productName": "dull-sponge-spit-px681", | |
"description": "My Electron application description", | |
"keywords": [], | |
"main": "./main.js", | |
"version": "1.0.0", | |
"author": "peter.xie", | |
"scripts": { | |
"start": "electron ." | |
}, | |
"dependencies": { | |
"@sentry/electron": "4.8.0" | |
}, | |
"devDependencies": { | |
"electron": "25.3.2" | |
} | |
} |
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
const { contextBridge, ipcRenderer } = require('electron') | |
// system info begins | |
contextBridge.exposeInMainWorld('crash', { | |
main: () => ipcRenderer.invoke('crash-main'), | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment