Fix 'install now' click after download
This commit is contained in:
parent
81c57107ce
commit
d80e738fb1
5 changed files with 82 additions and 83 deletions
|
@ -60,13 +60,18 @@ try {
|
||||||
window.getAppInstance = () => config.appInstance;
|
window.getAppInstance = () => config.appInstance;
|
||||||
window.getVersion = () => config.version;
|
window.getVersion = () => config.version;
|
||||||
window.getExpiration = () => {
|
window.getExpiration = () => {
|
||||||
|
const sixtyDays = 60 * 86400 * 1000;
|
||||||
const remoteBuildExpiration = window.storage.get('remoteBuildExpiration');
|
const remoteBuildExpiration = window.storage.get('remoteBuildExpiration');
|
||||||
|
const localBuildExpiration = window.Events.getAutoDownloadUpdate()
|
||||||
|
? config.buildExpiration
|
||||||
|
: config.buildExpiration - sixtyDays;
|
||||||
|
|
||||||
if (remoteBuildExpiration) {
|
if (remoteBuildExpiration) {
|
||||||
return remoteBuildExpiration < config.buildExpiration
|
return remoteBuildExpiration < config.buildExpiration
|
||||||
? remoteBuildExpiration
|
? remoteBuildExpiration
|
||||||
: config.buildExpiration;
|
: localBuildExpiration;
|
||||||
}
|
}
|
||||||
return config.buildExpiration;
|
return localBuildExpiration;
|
||||||
};
|
};
|
||||||
window.getNodeVersion = () => config.node_version;
|
window.getNodeVersion = () => config.node_version;
|
||||||
window.getHostName = () => config.hostname;
|
window.getHostName = () => config.hostname;
|
||||||
|
|
|
@ -20,7 +20,6 @@ import {
|
||||||
getPrintableError,
|
getPrintableError,
|
||||||
setUpdateListener,
|
setUpdateListener,
|
||||||
UpdaterInterface,
|
UpdaterInterface,
|
||||||
UpdateInformationType,
|
|
||||||
} from './common';
|
} from './common';
|
||||||
import { LoggerType } from '../types/Logging';
|
import { LoggerType } from '../types/Logging';
|
||||||
import { hexToBinary, verifySignature } from './signature';
|
import { hexToBinary, verifySignature } from './signature';
|
||||||
|
@ -75,13 +74,23 @@ async function checkForUpdatesMaybeInstall(
|
||||||
|
|
||||||
const { fileName: newFileName, version: newVersion } = result;
|
const { fileName: newFileName, version: newVersion } = result;
|
||||||
|
|
||||||
setUpdateListener(createUpdater(getMainWindow, result, logger));
|
|
||||||
|
|
||||||
if (fileName !== newFileName || !version || gt(newVersion, version)) {
|
if (fileName !== newFileName || !version || gt(newVersion, version)) {
|
||||||
const autoDownloadUpdates = await getAutoDownloadUpdateSetting(
|
const autoDownloadUpdates = await getAutoDownloadUpdateSetting(
|
||||||
getMainWindow()
|
getMainWindow()
|
||||||
);
|
);
|
||||||
if (!autoDownloadUpdates) {
|
if (!autoDownloadUpdates) {
|
||||||
|
setUpdateListener(async () => {
|
||||||
|
logger.info(
|
||||||
|
'performUpdate: have not downloaded update, going to download'
|
||||||
|
);
|
||||||
|
await downloadAndInstall(
|
||||||
|
newFileName,
|
||||||
|
newVersion,
|
||||||
|
getMainWindow,
|
||||||
|
logger,
|
||||||
|
true
|
||||||
|
);
|
||||||
|
});
|
||||||
getMainWindow().webContents.send(
|
getMainWindow().webContents.send(
|
||||||
'show-update-dialog',
|
'show-update-dialog',
|
||||||
DialogType.DownloadReady,
|
DialogType.DownloadReady,
|
||||||
|
@ -166,6 +175,11 @@ async function downloadAndInstall(
|
||||||
// because Squirrel has cached the update file and will do the right thing.
|
// because Squirrel has cached the update file and will do the right thing.
|
||||||
logger.info('downloadAndInstall: showing update dialog...');
|
logger.info('downloadAndInstall: showing update dialog...');
|
||||||
|
|
||||||
|
setUpdateListener(() => {
|
||||||
|
logger.info('performUpdate: calling quitAndInstall...');
|
||||||
|
markShouldQuit();
|
||||||
|
autoUpdater.quitAndInstall();
|
||||||
|
});
|
||||||
getMainWindow().webContents.send('show-update-dialog', DialogType.Update, {
|
getMainWindow().webContents.send('show-update-dialog', DialogType.Update, {
|
||||||
version,
|
version,
|
||||||
});
|
});
|
||||||
|
@ -380,28 +394,3 @@ function shutdown(
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function createUpdater(
|
|
||||||
getMainWindow: () => BrowserWindow,
|
|
||||||
info: Pick<UpdateInformationType, 'fileName' | 'version'>,
|
|
||||||
logger: LoggerType
|
|
||||||
) {
|
|
||||||
return async () => {
|
|
||||||
if (updateFilePath) {
|
|
||||||
logger.info('performUpdate: calling quitAndInstall...');
|
|
||||||
markShouldQuit();
|
|
||||||
autoUpdater.quitAndInstall();
|
|
||||||
} else {
|
|
||||||
logger.info(
|
|
||||||
'performUpdate: have not downloaded update, going to download'
|
|
||||||
);
|
|
||||||
await downloadAndInstall(
|
|
||||||
info.fileName,
|
|
||||||
info.version,
|
|
||||||
getMainWindow,
|
|
||||||
logger,
|
|
||||||
true
|
|
||||||
);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
|
@ -18,7 +18,6 @@ import {
|
||||||
getPrintableError,
|
getPrintableError,
|
||||||
setUpdateListener,
|
setUpdateListener,
|
||||||
UpdaterInterface,
|
UpdaterInterface,
|
||||||
UpdateInformationType,
|
|
||||||
} from './common';
|
} from './common';
|
||||||
import { LoggerType } from '../types/Logging';
|
import { LoggerType } from '../types/Logging';
|
||||||
import { hexToBinary, verifySignature } from './signature';
|
import { hexToBinary, verifySignature } from './signature';
|
||||||
|
@ -78,13 +77,23 @@ async function checkForUpdatesMaybeInstall(
|
||||||
|
|
||||||
const { fileName: newFileName, version: newVersion } = result;
|
const { fileName: newFileName, version: newVersion } = result;
|
||||||
|
|
||||||
setUpdateListener(createUpdater(getMainWindow, result, logger));
|
|
||||||
|
|
||||||
if (fileName !== newFileName || !version || gt(newVersion, version)) {
|
if (fileName !== newFileName || !version || gt(newVersion, version)) {
|
||||||
const autoDownloadUpdates = await getAutoDownloadUpdateSetting(
|
const autoDownloadUpdates = await getAutoDownloadUpdateSetting(
|
||||||
getMainWindow()
|
getMainWindow()
|
||||||
);
|
);
|
||||||
if (!autoDownloadUpdates) {
|
if (!autoDownloadUpdates) {
|
||||||
|
setUpdateListener(async () => {
|
||||||
|
logger.info(
|
||||||
|
'performUpdate: have not downloaded update, going to download'
|
||||||
|
);
|
||||||
|
await downloadAndInstall(
|
||||||
|
newFileName,
|
||||||
|
newVersion,
|
||||||
|
getMainWindow,
|
||||||
|
logger,
|
||||||
|
true
|
||||||
|
);
|
||||||
|
});
|
||||||
getMainWindow().webContents.send(
|
getMainWindow().webContents.send(
|
||||||
'show-update-dialog',
|
'show-update-dialog',
|
||||||
DialogType.DownloadReady,
|
DialogType.DownloadReady,
|
||||||
|
@ -138,6 +147,23 @@ async function downloadAndInstall(
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.info('downloadAndInstall: showing dialog...');
|
logger.info('downloadAndInstall: showing dialog...');
|
||||||
|
setUpdateListener(async () => {
|
||||||
|
try {
|
||||||
|
await verifyAndInstall(updateFilePath, newVersion, logger);
|
||||||
|
installing = true;
|
||||||
|
} catch (error) {
|
||||||
|
logger.info('createUpdater: showing general update failure dialog...');
|
||||||
|
getMainWindow().webContents.send(
|
||||||
|
'show-update-dialog',
|
||||||
|
DialogType.Cannot_Update
|
||||||
|
);
|
||||||
|
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
|
||||||
|
markShouldQuit();
|
||||||
|
app.quit();
|
||||||
|
});
|
||||||
getMainWindow().webContents.send('show-update-dialog', DialogType.Update, {
|
getMainWindow().webContents.send('show-update-dialog', DialogType.Update, {
|
||||||
version,
|
version,
|
||||||
});
|
});
|
||||||
|
@ -253,40 +279,3 @@ async function spawn(
|
||||||
setTimeout(resolve, 200);
|
setTimeout(resolve, 200);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function createUpdater(
|
|
||||||
getMainWindow: () => BrowserWindow,
|
|
||||||
info: Pick<UpdateInformationType, 'fileName' | 'version'>,
|
|
||||||
logger: LoggerType
|
|
||||||
) {
|
|
||||||
return async () => {
|
|
||||||
if (updateFilePath) {
|
|
||||||
try {
|
|
||||||
await verifyAndInstall(updateFilePath, version, logger);
|
|
||||||
installing = true;
|
|
||||||
} catch (error) {
|
|
||||||
logger.info('createUpdater: showing general update failure dialog...');
|
|
||||||
getMainWindow().webContents.send(
|
|
||||||
'show-update-dialog',
|
|
||||||
DialogType.Cannot_Update
|
|
||||||
);
|
|
||||||
|
|
||||||
throw error;
|
|
||||||
}
|
|
||||||
|
|
||||||
markShouldQuit();
|
|
||||||
app.quit();
|
|
||||||
} else {
|
|
||||||
logger.info(
|
|
||||||
'performUpdate: have not downloaded update, going to download'
|
|
||||||
);
|
|
||||||
await downloadAndInstall(
|
|
||||||
info.fileName,
|
|
||||||
info.version,
|
|
||||||
getMainWindow,
|
|
||||||
logger,
|
|
||||||
true
|
|
||||||
);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,9 +1,12 @@
|
||||||
// Copyright 2020 Signal Messenger, LLC
|
// Copyright 2020 Signal Messenger, LLC
|
||||||
// SPDX-License-Identifier: AGPL-3.0-only
|
// SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
|
||||||
const env = window.getEnvironment();
|
import { Environment, getEnvironment } from '../environment';
|
||||||
|
import { isInPast } from './timestamp';
|
||||||
|
|
||||||
const NINETY_ONE_DAYS = 86400 * 91 * 1000;
|
const ONE_DAY_MS = 86400 * 1000;
|
||||||
|
const NINETY_ONE_DAYS = 91 * ONE_DAY_MS;
|
||||||
|
const THIRTY_ONE_DAYS = 31 * ONE_DAY_MS;
|
||||||
|
|
||||||
export function hasExpired(): boolean {
|
export function hasExpired(): boolean {
|
||||||
const { getExpiration, log } = window;
|
const { getExpiration, log } = window;
|
||||||
|
@ -21,7 +24,13 @@ export function hasExpired(): boolean {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
const tooFarIntoFuture = Date.now() + NINETY_ONE_DAYS < buildExpiration;
|
if (getEnvironment() === Environment.Production) {
|
||||||
|
const safeExpirationMs = window.Events.getAutoDownloadUpdate()
|
||||||
|
? NINETY_ONE_DAYS
|
||||||
|
: THIRTY_ONE_DAYS;
|
||||||
|
|
||||||
|
const buildExpirationDuration = buildExpiration - Date.now();
|
||||||
|
const tooFarIntoFuture = buildExpirationDuration > safeExpirationMs;
|
||||||
|
|
||||||
if (tooFarIntoFuture) {
|
if (tooFarIntoFuture) {
|
||||||
log.error(
|
log.error(
|
||||||
|
@ -30,9 +39,8 @@ export function hasExpired(): boolean {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (env === 'production') {
|
return tooFarIntoFuture || isInPast(buildExpiration);
|
||||||
return Date.now() > buildExpiration && tooFarIntoFuture;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return buildExpiration !== 0 && Date.now() > buildExpiration;
|
return buildExpiration !== 0 && isInPast(buildExpiration);
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,3 +8,11 @@ export function isMoreRecentThan(timestamp: number, delta: number): boolean {
|
||||||
export function isOlderThan(timestamp: number, delta: number): boolean {
|
export function isOlderThan(timestamp: number, delta: number): boolean {
|
||||||
return timestamp <= Date.now() - delta;
|
return timestamp <= Date.now() - delta;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function isInPast(timestamp: number): boolean {
|
||||||
|
return isOlderThan(timestamp, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function isInFuture(timestamp: number): boolean {
|
||||||
|
return isMoreRecentThan(timestamp, 0);
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue