43 lines
1.2 KiB
JavaScript
43 lines
1.2 KiB
JavaScript
const { app, BrowserWindow } = require('electron');
|
|
const path = require('path');
|
|
|
|
// Catch unhandled exceptions to prevent crashes
|
|
process.on('uncaughtException', (error) => {
|
|
console.error('Unhandled exception:', error);
|
|
});
|
|
|
|
process.on('unhandledRejection', (reason, promise) => {
|
|
console.error('Unhandled rejection at:', promise, 'reason:', reason);
|
|
});
|
|
|
|
function createWindow() {
|
|
const win = new BrowserWindow({
|
|
width: 1000,
|
|
height: 700,
|
|
webPreferences: {
|
|
preload: path.join(__dirname, 'preload.js'),
|
|
contextIsolation: true,
|
|
nodeIntegration: false,
|
|
sandbox: false // disable sandbox to enable Node built-ins in preload
|
|
}
|
|
});
|
|
|
|
win.webContents.on('preload-error', (event, preloadPath, error) => {
|
|
console.error(`Failed to load preload script from ${preloadPath}:`, error);
|
|
});
|
|
|
|
win.loadFile('index.html');
|
|
}
|
|
|
|
app.whenReady().then(createWindow);
|
|
app.on('window-all-closed', () => {
|
|
if (process.platform !== 'darwin') app.quit();
|
|
});
|
|
app.on('activate', () => {
|
|
if (BrowserWindow.getAllWindows().length === 0) createWindow();
|
|
});
|
|
|
|
app.on('renderer-process-crashed', (event, webContents, killed) => {
|
|
console.error('Renderer process crashed. Restarting...');
|
|
createWindow(); // Restart the renderer process
|
|
}); |