electron/spec/fixtures/crash-cases/utility-process-app-ready/index.js
trop[bot] 6126cc2bfe
fix: UtilityProcess.fork crash before app ready (#46404)
fix: UtilityProcess.fork crash before app ready

Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com>
Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com>
2025-04-01 09:32:43 -05:00

31 lines
705 B
JavaScript

const { app, BrowserWindow, utilityProcess } = require('electron');
const path = require('node:path');
function createWindow () {
const mainWindow = new BrowserWindow();
mainWindow.loadFile('about:blank');
}
app.whenReady().then(() => {
createWindow();
app.on('activate', function () {
if (BrowserWindow.getAllWindows().length === 0) createWindow();
});
});
app.on('window-all-closed', function () {
if (process.platform !== 'darwin') app.quit();
});
try {
utilityProcess.fork(path.join(__dirname, 'utility.js'));
} catch (e) {
if (/utilityProcess cannot be created before app is ready/.test(e.message)) {
app.exit(0);
} else {
console.error(e);
app.exit(1);
}
}