mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Broadcast update available only after downloading update (#2232)
* broadcast update available only after downloading update * remove unnecessary downloads, force silent and restart modes if user chooses to install update immediately * add app.exit() for installing (fixes bug on Windows) Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
parent
852aa1147f
commit
35e6065487
@ -3,8 +3,8 @@ import logger from "./logger";
|
|||||||
import { isDevelopment, isTestEnv } from "../common/vars";
|
import { isDevelopment, isTestEnv } from "../common/vars";
|
||||||
import { delay } from "../common/utils";
|
import { delay } from "../common/utils";
|
||||||
import { areArgsUpdateAvailableToBackchannel, AutoUpdateLogPrefix, broadcastMessage, onceCorrect, UpdateAvailableChannel, UpdateAvailableToBackchannel } from "../common/ipc";
|
import { areArgsUpdateAvailableToBackchannel, AutoUpdateLogPrefix, broadcastMessage, onceCorrect, UpdateAvailableChannel, UpdateAvailableToBackchannel } from "../common/ipc";
|
||||||
import { ipcMain } from "electron";
|
|
||||||
import { once } from "lodash";
|
import { once } from "lodash";
|
||||||
|
import { app, ipcMain } from "electron";
|
||||||
|
|
||||||
let installVersion: null | string = null;
|
let installVersion: null | string = null;
|
||||||
|
|
||||||
@ -12,13 +12,11 @@ function handleAutoUpdateBackChannel(event: Electron.IpcMainEvent, ...[arg]: Upd
|
|||||||
if (arg.doUpdate) {
|
if (arg.doUpdate) {
|
||||||
if (arg.now) {
|
if (arg.now) {
|
||||||
logger.info(`${AutoUpdateLogPrefix}: User chose to update now`);
|
logger.info(`${AutoUpdateLogPrefix}: User chose to update now`);
|
||||||
autoUpdater.on("update-downloaded", () => autoUpdater.quitAndInstall());
|
autoUpdater.quitAndInstall(true, true);
|
||||||
autoUpdater.downloadUpdate().catch(error => logger.error(`${AutoUpdateLogPrefix}: Failed to download or install update`, { error }));
|
app.exit(); // this is needed for the installer not to fail on windows.
|
||||||
} else {
|
} else {
|
||||||
logger.info(`${AutoUpdateLogPrefix}: User chose to update on quit`);
|
logger.info(`${AutoUpdateLogPrefix}: User chose to update on quit`);
|
||||||
autoUpdater.autoInstallOnAppQuit = true;
|
autoUpdater.autoInstallOnAppQuit = true;
|
||||||
autoUpdater.downloadUpdate()
|
|
||||||
.catch(error => logger.error(`${AutoUpdateLogPrefix}: Failed to download update`, { error }));
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
logger.info(`${AutoUpdateLogPrefix}: User chose not to update`);
|
logger.info(`${AutoUpdateLogPrefix}: User chose not to update`);
|
||||||
@ -39,10 +37,10 @@ export const startUpdateChecking = once(function (interval = 1000 * 60 * 60 * 24
|
|||||||
autoUpdater.autoInstallOnAppQuit = false;
|
autoUpdater.autoInstallOnAppQuit = false;
|
||||||
|
|
||||||
autoUpdater
|
autoUpdater
|
||||||
.on("update-available", (args: UpdateInfo) => {
|
.on("update-available", (info: UpdateInfo) => {
|
||||||
if (autoUpdater.autoInstallOnAppQuit) {
|
if (autoUpdater.autoInstallOnAppQuit) {
|
||||||
// a previous auto-update loop was completed with YES+LATER, check if same version
|
// a previous auto-update loop was completed with YES+LATER, check if same version
|
||||||
if (installVersion === args.version) {
|
if (installVersion === info.version) {
|
||||||
// same version, don't broadcast
|
// same version, don't broadcast
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -54,10 +52,14 @@ export const startUpdateChecking = once(function (interval = 1000 * 60 * 60 * 24
|
|||||||
* didn't ask for.
|
* didn't ask for.
|
||||||
*/
|
*/
|
||||||
autoUpdater.autoInstallOnAppQuit = false;
|
autoUpdater.autoInstallOnAppQuit = false;
|
||||||
installVersion = args.version;
|
installVersion = info.version;
|
||||||
|
|
||||||
|
autoUpdater.downloadUpdate()
|
||||||
|
.catch(error => logger.error(`${AutoUpdateLogPrefix}: failed to download update`, { error: String(error) }));
|
||||||
|
})
|
||||||
|
.on("update-downloaded", (info: UpdateInfo) => {
|
||||||
try {
|
try {
|
||||||
const backchannel = `auto-update:${args.version}`;
|
const backchannel = `auto-update:${info.version}`;
|
||||||
|
|
||||||
ipcMain.removeAllListeners(backchannel); // only one handler should be present
|
ipcMain.removeAllListeners(backchannel); // only one handler should be present
|
||||||
|
|
||||||
@ -68,8 +70,8 @@ export const startUpdateChecking = once(function (interval = 1000 * 60 * 60 * 24
|
|||||||
listener: handleAutoUpdateBackChannel,
|
listener: handleAutoUpdateBackChannel,
|
||||||
verifier: areArgsUpdateAvailableToBackchannel,
|
verifier: areArgsUpdateAvailableToBackchannel,
|
||||||
});
|
});
|
||||||
logger.info(`${AutoUpdateLogPrefix}: broadcasting update available`, { backchannel, version: args.version });
|
logger.info(`${AutoUpdateLogPrefix}: broadcasting update available`, { backchannel, version: info.version });
|
||||||
broadcastMessage(UpdateAvailableChannel, backchannel, args);
|
broadcastMessage(UpdateAvailableChannel, backchannel, info);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error(`${AutoUpdateLogPrefix}: broadcasting failed`, { error });
|
logger.error(`${AutoUpdateLogPrefix}: broadcasting failed`, { error });
|
||||||
installVersion = undefined;
|
installVersion = undefined;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user