Skip to content

Commit 30b3a37

Browse files
committed
Updates: don't attempt to apply updates if it's not newer.
When we check for updates, we set an `isInstallable` flag in our cache if the new version has been downloaded. However, that flag isn't being cleared right after an update (because Squirrel.Mac etc. doesn't know about it). Sanity check that flag by comparing the app version against the staged app version, to make sure that we only abort startup for updates that we may actually apply. Signed-off-by: Mark Yen <mark.yen@suse.com>
1 parent a4b6b72 commit 30b3a37

1 file changed

Lines changed: 23 additions & 2 deletions

File tree

src/main/update/LonghornProvider.ts

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@ import path from 'path';
44
import { URL } from 'url';
55

66
import { newError, PublishConfiguration } from 'builder-util-runtime';
7+
import Electron from 'electron';
78
import { AppUpdater, Provider, ResolvedUpdateFileInfo, UpdateInfo } from 'electron-updater';
89
import { ProviderRuntimeOptions } from 'electron-updater/out/providers/Provider';
910
import fetch from 'node-fetch';
11+
import semver from 'semver';
1012

1113
import Logging from '@/utils/logging';
1214
import paths from '@/utils/paths';
@@ -125,9 +127,28 @@ export async function hasQueuedUpdate(): Promise<boolean> {
125127
const rawCache = await fs.promises.readFile(gCachePath, 'utf-8');
126128
const cache: LonghornCache = JSON.parse(rawCache);
127129

128-
if (cache.isInstallable) {
129-
return true;
130+
if (!cache.isInstallable) {
131+
return false;
130132
}
133+
134+
// The isInstallable flag isn't going to get clear _right_ after an update;
135+
// in which case, we need to check that the release is newer than the
136+
// current version.
137+
const currentVersion = semver.parse(Electron.app.getVersion(), { loose: true });
138+
const stagedVersion = semver.parse(cache.release.tag, { loose: true });
139+
140+
if (!currentVersion || !stagedVersion) {
141+
console.log(`Error parsing staged versions: ${ currentVersion } -> ${ stagedVersion }`);
142+
143+
return false;
144+
}
145+
if (currentVersion.compare(stagedVersion) >= 0) {
146+
console.log(`Staged version ${ stagedVersion } not greater than current version ${ currentVersion }, skipping.`);
147+
148+
return false;
149+
}
150+
151+
return true;
131152
} catch (error) {
132153
if (error.code !== 'ENOENT') {
133154
console.error('Could not check for queued update:', error);

0 commit comments

Comments
 (0)