Harden Electron main: re-entrancy guard, tray destroy, loadURL error log
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
+10
-4
@@ -10,6 +10,7 @@ const YT_MUSIC_URL = 'https://music.youtube.com';
|
||||
let serverHandle = null;
|
||||
let mainWindow = null;
|
||||
let tray = null;
|
||||
let isQuitting = false;
|
||||
|
||||
async function createWindow() {
|
||||
mainWindow = new BrowserWindow({
|
||||
@@ -29,7 +30,11 @@ async function createWindow() {
|
||||
mainWindow = null;
|
||||
});
|
||||
|
||||
try {
|
||||
await mainWindow.loadURL(YT_MUSIC_URL);
|
||||
} catch (err) {
|
||||
console.error('[wtm] Failed to load YT Music:', err.message);
|
||||
}
|
||||
}
|
||||
|
||||
app.whenReady().then(async () => {
|
||||
@@ -47,7 +52,6 @@ app.whenReady().then(async () => {
|
||||
onShow: () => {
|
||||
if (!mainWindow) return;
|
||||
if (mainWindow.isMinimized()) mainWindow.restore();
|
||||
mainWindow.show();
|
||||
mainWindow.focus();
|
||||
},
|
||||
onQuit: () => app.quit(),
|
||||
@@ -59,10 +63,12 @@ app.on('window-all-closed', () => {
|
||||
});
|
||||
|
||||
app.on('before-quit', async (e) => {
|
||||
if (serverHandle) {
|
||||
e.preventDefault?.();
|
||||
if (isQuitting) return;
|
||||
if (!serverHandle) return;
|
||||
e.preventDefault();
|
||||
isQuitting = true;
|
||||
if (tray) { tray.destroy(); tray = null; }
|
||||
try { await serverHandle.stop(); } catch (_) {}
|
||||
serverHandle = null;
|
||||
app.exit(0);
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user