From a406f7920915c7036244b84184d9d184c2a9e722 Mon Sep 17 00:00:00 2001 From: matt Date: Fri, 13 Feb 2026 01:37:20 +0900 Subject: [PATCH] fix(startup): improve error handling during app initialization - Wrapped the service initialization and configuration application in a try-catch block to handle potential errors during startup. - Added logging for initialization failures to aid in debugging and ensure the main window is created if initialization fails. This commit enhances the application's resilience by ensuring it can recover from startup errors gracefully. --- src/main/index.ts | 58 ++++++++++++++++++++++++++--------------------- 1 file changed, 32 insertions(+), 26 deletions(-) diff --git a/src/main/index.ts b/src/main/index.ts index c5a22bfd..00e04ab7 100644 --- a/src/main/index.ts +++ b/src/main/index.ts @@ -477,38 +477,44 @@ function createWindow(): void { */ void app.whenReady().then(() => { logger.info('App ready, initializing...'); + try { + // Initialize services first + initializeServices(); - // Initialize services first - initializeServices(); + // Apply configuration settings + const config = configManager.getConfig(); - // Apply configuration settings - const config = configManager.getConfig(); + // Apply launch at login setting + app.setLoginItemSettings({ + openAtLogin: config.general.launchAtLogin, + }); - // Apply launch at login setting - app.setLoginItemSettings({ - openAtLogin: config.general.launchAtLogin, - }); - - // Apply dock visibility and icon (macOS) - if (process.platform === 'darwin') { - if (!config.general.showDockIcon) { - app.dock?.hide(); + // Apply dock visibility and icon (macOS) + if (process.platform === 'darwin') { + if (!config.general.showDockIcon) { + app.dock?.hide(); + } + // macOS app icon is already provided by the signed bundle (.icns) + // so we avoid runtime setIcon calls that can fail and block startup. + } + + // Then create window + createWindow(); + + // Listen for notification click events + notificationManager.on('notification-clicked', (_error) => { + if (mainWindow) { + mainWindow.show(); + mainWindow.focus(); + } + }); + } catch (error) { + logger.error('Startup initialization failed:', error); + if (!mainWindow) { + createWindow(); } - // macOS app icon is already provided by the signed bundle (.icns) - // so we avoid runtime setIcon calls that can fail and block startup. } - // Then create window - createWindow(); - - // Listen for notification click events - notificationManager.on('notification-clicked', (_error) => { - if (mainWindow) { - mainWindow.show(); - mainWindow.focus(); - } - }); - app.on('activate', () => { if (BrowserWindow.getAllWindows().length === 0) { createWindow();