Skip to content

Commit

Permalink
fix(client-electron): catch auto update errors
Browse files Browse the repository at this point in the history
  • Loading branch information
marcincichocki authored Aug 31, 2021
1 parent 113ea9b commit 96dc6f5
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/electron/common/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ export interface AppStats {

export enum UpdateStatus {
Error,
NetworkError,
CheckingForUpdate,
UpdateNotAvailable,
UpdateAvailable,
Expand Down
20 changes: 18 additions & 2 deletions src/electron/main/updater.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,19 @@ export class BreachProtocolAutosolverUpdater {
this.registerListeners();
}

checkForUpdates() {
async checkForUpdates() {
this.autoUpdate = this.store.getState().settings.autoUpdate;
autoUpdater.autoDownload = this.autoUpdate;

autoUpdater.checkForUpdates();
try {
await autoUpdater.checkForUpdates();
} catch (error) {
if (error instanceof Error) {
this.onError(error);
} else {
throw error;
}
}
}

dispose() {
Expand All @@ -42,6 +50,14 @@ export class BreachProtocolAutosolverUpdater {
autoUpdater.on('download-progress', this.onDownloadProgress.bind(this));
}

private onError(error: Error) {
if (error.message === 'net::ERR_INTERNET_DISCONNECTED') {
this.setUpdateStatus(UpdateStatus.NetworkError);
} else {
this.setUpdateStatus(UpdateStatus.Error);
}
}

private onCheckingForUpdates() {
this.setUpdateStatus(UpdateStatus.CheckingForUpdate);
}
Expand Down
1 change: 1 addition & 0 deletions src/electron/renderer/components/StatusBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ function useShowUpdateStatus(status: UpdateStatus, delay = 3000) {

const updateStatusMessage = {
[UpdateStatus.Error]: 'Error occurred',
[UpdateStatus.NetworkError]: 'Offline',
[UpdateStatus.CheckingForUpdate]: 'Checking for updates..',
[UpdateStatus.UpdateNotAvailable]: 'Up to date',
[UpdateStatus.UpdateAvailable]: 'Update available',
Expand Down

0 comments on commit 96dc6f5

Please sign in to comment.