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:
2026-04-26 09:49:20 -07:00
co-authored by Claude Sonnet 4.6
parent 7ea303a2ef
commit affc71bd0f
+14 -8
View File
@@ -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;
});
await mainWindow.loadURL(YT_MUSIC_URL);
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?.();
try { await serverHandle.stop(); } catch (_) {}
serverHandle = null;
app.exit(0);
}
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);
});