From 61204f8d5c1094be8ec714e88b466b67b4eecd78 Mon Sep 17 00:00:00 2001 From: letsandeepio <48636430+letsandeepio@users.noreply.github.com> Date: Mon, 2 Aug 2021 05:05:47 -0400 Subject: [PATCH] Add disableAutoUpdates config option (#5805) Co-authored-by: Labhansh Agrawal --- app/config/config-default.js | 3 +++ app/updater.ts | 37 ++++++++++++++++++++++-------------- lib/config.d.ts | 1 + 3 files changed, 27 insertions(+), 14 deletions(-) diff --git a/app/config/config-default.js b/app/config/config-default.js index 512471f8..3e1206a5 100644 --- a/app/config/config-default.js +++ b/app/config/config-default.js @@ -157,6 +157,9 @@ module.exports = { // if `false` (without backticks and without quotes), Hyper will use ligatures provided by some fonts disableLigatures: true, + // set to true to disable auto updates + disableAutoUpdates: false, + // for advanced config flags please refer to https://hyper.is/#cfg }, diff --git a/app/updater.ts b/app/updater.ts index 47db3489..7cfe4240 100644 --- a/app/updater.ts +++ b/app/updater.ts @@ -14,6 +14,23 @@ const isLinux = platform === 'linux'; const autoUpdater: AutoUpdater = isLinux ? autoUpdaterLinux : electron.autoUpdater; +const getDecoratedConfigWithRetry = async () => { + return await retry(() => { + const content = getDecoratedConfig(); + if (!content) { + throw new Error('No config content loaded'); + } + return content; + }); +}; + +const checkForUpdates = async () => { + const config = await getDecoratedConfigWithRetry(); + if (!config.disableAutoUpdates) { + autoUpdater.checkForUpdates(); + } +}; + let isInit = false; // Default to the "stable" update channel let canaryUpdates = false; @@ -46,15 +63,7 @@ async function init() { console.error('Error fetching updates', `${err.message} (${err.stack})`); }); - const config = await retry(() => { - const content = getDecoratedConfig(); - - if (!content) { - throw new Error('No config content loaded'); - } - - return content; - }); + const config = await getDecoratedConfigWithRetry(); // If defined in the config, switch to the "canary" channel if (config.updateChannel && isCanary(config.updateChannel)) { @@ -66,11 +75,11 @@ async function init() { autoUpdater.setFeedURL({url: feedURL}); setTimeout(() => { - autoUpdater.checkForUpdates(); + void checkForUpdates(); }, ms('10s')); setInterval(() => { - autoUpdater.checkForUpdates(); + void checkForUpdates(); }, ms('30m')); isInit = true; @@ -103,15 +112,15 @@ export default (win: BrowserWindow) => { autoUpdater.quitAndInstall(); }); - app.config.subscribe(() => { - const {updateChannel} = app.plugins.getDecoratedConfig(); + app.config.subscribe(async () => { + const {updateChannel} = await getDecoratedConfigWithRetry(); const newUpdateIsCanary = isCanary(updateChannel); if (newUpdateIsCanary !== canaryUpdates) { const feedURL = buildFeedUrl(newUpdateIsCanary, version); autoUpdater.setFeedURL({url: feedURL}); - autoUpdater.checkForUpdates(); + void checkForUpdates(); canaryUpdates = newUpdateIsCanary; } diff --git a/lib/config.d.ts b/lib/config.d.ts index 9e451a0c..ee637050 100644 --- a/lib/config.d.ts +++ b/lib/config.d.ts @@ -34,6 +34,7 @@ export type configOptions = { cursorColor: string; cursorShape: 'BEAM' | 'UNDERLINE' | 'BLOCK'; defaultSSHApp: boolean; + disableAutoUpdates: boolean; disableLigatures: boolean; env: Record; fontFamily: string;