From affc71bd0f1c7de43c214e0e5dcc23415c97ff9c Mon Sep 17 00:00:00 2001 From: Josh Knapp Date: Sun, 26 Apr 2026 09:49:20 -0700 Subject: [PATCH] Harden Electron main: re-entrancy guard, tray destroy, loadURL error log Co-Authored-By: Claude Sonnet 4.6 --- desktop-client/index.js | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/desktop-client/index.js b/desktop-client/index.js index d869aeb..f93e8b4 100644 --- a/desktop-client/index.js +++ b/desktop-client/index.js @@ -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); });