Skip to content

Commit b1fd12e

Browse files
authored
Merge pull request #884 from mook-as/mac-update-restart
Updates: don't attempt to apply updates if it's not newer.
2 parents 449b5c3 + c0a56a9 commit b1fd12e

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

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 ?? '<none>' } -> ${ stagedVersion ?? '<none>' }`);
142+
143+
return false;
144+
}
145+
if (semver.gte(currentVersion, stagedVersion)) {
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)