Skip to content

Commit

Permalink
[#305] Quit app in case of an error when running app, catch error whe…
Browse files Browse the repository at this point in the history
…n checking for updates
  • Loading branch information
SRichner committed Apr 5, 2024
1 parent d480e1e commit 86fdfee
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 18 deletions.
1 change: 1 addition & 0 deletions src/electron/electron/main/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
});

Expand Down
39 changes: 21 additions & 18 deletions src/electron/electron/main/services/AppUpdaterService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down Expand Up @@ -103,27 +102,31 @@ export default class AppUpdaterService extends EventEmitter {
}

public async checkForUpdates({ silent }: { silent: boolean }): Promise<void> {
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);
}
}

Expand Down

0 comments on commit 86fdfee

Please sign in to comment.