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); });