Skip to content

Commit

Permalink
Updates: don't attempt to apply updates if it's not newer.
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
mook-as committed Oct 28, 2021
1 parent a4b6b72 commit 30b3a37
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions src/main/update/LonghornProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ import path from 'path';
import { URL } from 'url';

import { newError, PublishConfiguration } from 'builder-util-runtime';
import Electron from 'electron';
import { AppUpdater, Provider, ResolvedUpdateFileInfo, UpdateInfo } from 'electron-updater';
import { ProviderRuntimeOptions } from 'electron-updater/out/providers/Provider';
import fetch from 'node-fetch';
import semver from 'semver';

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

if (cache.isInstallable) {
return true;
if (!cache.isInstallable) {
return false;
}

// The isInstallable flag isn't going to get clear _right_ after an update;
// in which case, we need to check that the release is newer than the
// current version.
const currentVersion = semver.parse(Electron.app.getVersion(), { loose: true });
const stagedVersion = semver.parse(cache.release.tag, { loose: true });

if (!currentVersion || !stagedVersion) {
console.log(`Error parsing staged versions: ${ currentVersion } -> ${ stagedVersion }`);

return false;
}
if (currentVersion.compare(stagedVersion) >= 0) {
console.log(`Staged version ${ stagedVersion } not greater than current version ${ currentVersion }, skipping.`);

return false;
}

return true;
} catch (error) {
if (error.code !== 'ENOENT') {
console.error('Could not check for queued update:', error);
Expand Down

0 comments on commit 30b3a37

Please sign in to comment.