From 86fdfee5b1eb295ca88eef3f2ec9dc38e8493268 Mon Sep 17 00:00:00 2001 From: Sebastian Richner Date: Fri, 5 Apr 2024 16:25:21 +0200 Subject: [PATCH] [#305] Quit app in case of an error when running app, catch error when checking for updates --- src/electron/electron/main/index.ts | 1 + .../main/services/AppUpdaterService.ts | 39 ++++++++++--------- 2 files changed, 22 insertions(+), 18 deletions(-) diff --git a/src/electron/electron/main/index.ts b/src/electron/electron/main/index.ts index 00bdee9e..6cd8b54d 100644 --- a/src/electron/electron/main/index.ts +++ b/src/electron/electron/main/index.ts @@ -184,6 +184,7 @@ app.whenReady().then(async () => { 'Error during app initialization', `PersonalAnalytics couldn't be started. Please try again or contact us at ${studyConfig.contactEmail} for help. ${error}` ); + app.exit(); } }); diff --git a/src/electron/electron/main/services/AppUpdaterService.ts b/src/electron/electron/main/services/AppUpdaterService.ts index f3537208..40a081f5 100644 --- a/src/electron/electron/main/services/AppUpdaterService.ts +++ b/src/electron/electron/main/services/AppUpdaterService.ts @@ -18,7 +18,6 @@ export default class AppUpdaterService extends EventEmitter { super(); autoUpdater.logger = LOG; autoUpdater.autoDownload = false; - LOG.debug('AppUpdaterService constructor called'); autoUpdater.on('checking-for-update', () => { @@ -103,27 +102,31 @@ export default class AppUpdaterService extends EventEmitter { } public async checkForUpdates({ silent }: { silent: boolean }): Promise { - if (net.isOnline()) { - this.isSilentCheckForUpdates = silent; - this.changeUpdaterMenu({ label: 'Checking for updates...', enabled: false }); - if (this.updateDownloaded) { - const dialogResponse = await dialog.showMessageBox({ - title: 'PersonalAnalytics Update Available', - message: 'New updates are available and ready to be installed.', - defaultId: 0, - cancelId: 1, - buttons: ['Install and restart', 'Close'] - }); - if (dialogResponse.response === 0) { - setImmediate(() => autoUpdater.quitAndInstall()); + try { + if (net.isOnline()) { + this.isSilentCheckForUpdates = silent; + this.changeUpdaterMenu({ label: 'Checking for updates...', enabled: false }); + if (this.updateDownloaded) { + const dialogResponse = await dialog.showMessageBox({ + title: 'PersonalAnalytics Update Available', + message: 'New updates are available and ready to be installed.', + defaultId: 0, + cancelId: 1, + buttons: ['Install and restart', 'Close'] + }); + if (dialogResponse.response === 0) { + setImmediate(() => autoUpdater.quitAndInstall()); + } else { + this.changeUpdaterMenu({ label: 'Updates available', enabled: true }); + } } else { - this.changeUpdaterMenu({ label: 'Updates available', enabled: true }); + await autoUpdater.checkForUpdates(); } } else { - await autoUpdater.checkForUpdates(); + LOG.info('No internet connection, skipping check for updates.'); } - } else { - LOG.info('No internet connection, skipping check for updates.'); + } catch (e) { + LOG.error(e); } }