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.
This commit is contained in:
parent
a517a5d96c
commit
a406f79209
1 changed files with 32 additions and 26 deletions
|
|
@ -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();
|
||||
|
|
|
|||
Loading…
Reference in a new issue