Skip to content
This repository has been archived by the owner on Jun 20, 2022. It is now read-only.

Commit

Permalink
fix: correctly check update safety
Browse files Browse the repository at this point in the history
  • Loading branch information
arielsvg committed Dec 29, 2020
1 parent 16c49c6 commit c07e015
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 13 deletions.
4 changes: 2 additions & 2 deletions app/javascripts/main/backupsManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ import { handle, send } from './testing';
import { isTesting, last } from './utils';

function log(...message: any) {
console.log('ArchiveManager:', ...message);
console.log('BackupsManager:', ...message);
}

function logError(...message: any) {
console.error('ArchiveManager:', ...message);
console.error('BackupsManager:', ...message);
}

export const enum EnsureRecentBackupExists {
Expand Down
18 changes: 7 additions & 11 deletions app/javascripts/main/updateManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ export class UpdateState {
lastCheck: observable,

updateNeeded: computed,
updatingIsSafe: computed,

toggleAutoUpdate: action,
setCheckingForUpdate: action,
Expand All @@ -56,20 +55,12 @@ export class UpdateState {

get updateNeeded(): boolean {
if (this.latestVersion) {
return compareVersions(this.appState.version, this.latestVersion) === 1;
return compareVersions(this.latestVersion, this.appState.version) === 1;
} else {
return false;
}
}

get updatingIsSafe(): boolean {
return (
!this.enableAutoUpdate &&
!!this.appState.lastBackupDate &&
isLessThanOneHourFromNow(this.appState.lastBackupDate)
);
}

toggleAutoUpdate(): void {
this.enableAutoUpdate = !this.enableAutoUpdate;
this.appState.store.set(StoreKeys.EnableAutoUpdate, this.enableAutoUpdate);
Expand Down Expand Up @@ -105,12 +96,17 @@ export function setupUpdates(
autoUpdater.logger = electronLog;

const updateState = appState.updates;

function checkUpdateSafety() {
const isSafeToUpdate = updateState.updatingIsSafe;
const isSafeToUpdate =
updateState.enableAutoUpdate &&
typeof appState.lastBackupDate === 'number' &&
isLessThanOneHourFromNow(appState.lastBackupDate);
autoUpdater.autoInstallOnAppQuit = isSafeToUpdate;
autoUpdater.autoDownload = isSafeToUpdate;
}
autorun(checkUpdateSafety);

const oneHour = 1 * 60 * 60 * 1000;
setInterval(checkUpdateSafety, oneHour);

Expand Down

0 comments on commit c07e015

Please sign in to comment.