From 5c749f8c6c863d776b25ab38eef62ef52b69f36e Mon Sep 17 00:00:00 2001 From: Perry Mitchell Date: Mon, 1 Apr 2024 11:36:59 +0300 Subject: [PATCH 1/2] Add CLI flag to disable updates - fixes #1050 --- source/main/ipc.ts | 4 ++-- source/main/library/build.ts | 2 +- source/main/services/arguments.ts | 4 ++++ source/main/services/update.ts | 38 ++++++++++++++++++++----------- 4 files changed, 32 insertions(+), 16 deletions(-) diff --git a/source/main/ipc.ts b/source/main/ipc.ts index 6a382c5d..ba6ae80a 100644 --- a/source/main/ipc.ts +++ b/source/main/ipc.ts @@ -351,9 +351,9 @@ ipcMain.handle("start-current-update", async () => { ipcMain.handle("toggle-auto-update", async (_, enable: boolean) => { await toggleAutoUpdate(enable); if (enable) { - logInfo("Enabled auto-update"); + logInfo("Enabled vault auto-update"); } else { - logInfo("Disabled auto-update"); + logInfo("Disabled vault auto-update"); } }); diff --git a/source/main/library/build.ts b/source/main/library/build.ts index b817b022..235e830c 100644 --- a/source/main/library/build.ts +++ b/source/main/library/build.ts @@ -1,3 +1,3 @@ // This file updated automatically: changes made here will be overwritten! -export const VERSION = "2.26.4"; +export const VERSION = "2.26.5"; diff --git a/source/main/services/arguments.ts b/source/main/services/arguments.ts index 290d5c60..b1ccbcfd 100644 --- a/source/main/services/arguments.ts +++ b/source/main/services/arguments.ts @@ -1,5 +1,6 @@ import { app } from "electron"; import { isOSX } from "../../shared/library/platform"; +import { disableUpdates } from "./update"; let __autostarted = false, __showMainWindow = true; @@ -22,6 +23,9 @@ export function processLaunchConfiguration() { if (cl.hasSwitch("autostart")) { __autostarted = true; } + if (cl.hasSwitch("no-update")) { + disableUpdates(); + } } export function shouldShowMainWindow(): boolean { diff --git a/source/main/services/update.ts b/source/main/services/update.ts index 1c239534..15b6f89e 100644 --- a/source/main/services/update.ts +++ b/source/main/services/update.ts @@ -20,16 +20,17 @@ let __eventListenersAttached = false, __readyUpdate: UpdateInfo = null, __updateCheckTimer: string = null, __updateErrored: boolean = false, - __updateMuted: boolean = false; + __updateMuted: boolean = false, + __updatesDisabled: boolean = false; function attachEventListeners(updater = autoUpdater) { updater.on("error", (err: Error) => { __updateErrored = true; if (err?.message === "net::ERR_INTERNET_DISCONNECTED") { - logInfo("Update failed due to no internet connection"); + logInfo("Updates: Update failed due to no internet connection"); return; } - logErr("Error processing update", err); + logErr("Updates: Error processing update", err); const win = getMainWindow(); if (win) { win.webContents.send("update-error", err.message); @@ -42,9 +43,9 @@ function attachEventListeners(updater = autoUpdater) { } }); updater.on("update-available", (updateInfo: UpdateInfo) => { - logInfo(`Update available: ${updateInfo.version} (${updateInfo.releaseDate})`); + logInfo(`Updates: Update available: ${updateInfo.version} (${updateInfo.releaseDate})`); if (__updateMuted) { - logInfo("Updates muted: will not notify"); + logInfo("Updates: Updates muted: will not notify"); return; } const win = getMainWindow(); @@ -53,16 +54,16 @@ function attachEventListeners(updater = autoUpdater) { } }); updater.on("update-not-available", () => { - logInfo("No update available"); + logInfo("Updates: No update available"); }); updater.on("update-downloaded", (updateInfo: UpdateInfo) => { - logInfo(`Update downloaded: ${updateInfo.version}`); + logInfo(`Updates: Updated build downloaded: ${updateInfo.version}`); const win = getMainWindow(); if (win) { win.webContents.send("update-progress", JSON.stringify(null)); } if (__updateErrored) { - logWarn("Skipping update-ready notification due to preview error"); + logWarn("Updates: Skipping update-ready notification due to preview error"); return; } __readyUpdate = updateInfo; @@ -74,6 +75,7 @@ function attachEventListeners(updater = autoUpdater) { } async function checkForUpdateInternal() { + if (__updatesDisabled) return; if (!__eventListenersAttached) { __eventListenersAttached = true; attachEventListeners(); @@ -82,7 +84,9 @@ async function checkForUpdateInternal() { __readyUpdate = null; __updateErrored = false; const prefs = await getConfigValue("preferences"); - logInfo(`Using pre-release channel for updates: ${prefs.prereleaseUpdates ? "yes" : "no"}`); + logInfo( + `Updates: Using pre-release channel for updates: ${prefs.prereleaseUpdates ? "yes" : "no"}` + ); autoUpdater.allowPrerelease = prefs.prereleaseUpdates; autoUpdater.autoDownload = false; autoUpdater.setFeedURL({ @@ -93,18 +97,26 @@ async function checkForUpdateInternal() { if (isDev) { const hasDevConfig = await hasDevUpdate(); if (!hasDevConfig) { - logInfo("Will not check for updates: In dev mode with no dev-app-update.yml"); + logInfo("Updates: Will not check for updates: In dev mode with no dev-app-update.yml"); return; } } logInfo("Checking for updates"); try { await autoUpdater.checkForUpdates(); - } catch (err) {} + } catch (err) { + logErr(`Updates: Update check failed: ${err.message}`); + logErr(err); + } +} + +export function disableUpdates(): void { + __updatesDisabled = true; + logInfo("Updates: Updates have been manually disabled"); } export function getCurrentUpdate(): UpdateInfo { - return !__updateMuted && __currentUpdate ? __currentUpdate : null; + return !__updateMuted && __currentUpdate && !__updatesDisabled ? __currentUpdate : null; } export function getReadyUpdate(): UpdateInfo { @@ -120,7 +132,7 @@ export function installUpdate() { } export function muteUpdate() { - logInfo("Update notification muted"); + logInfo("Updates: Update notification muted"); __updateMuted = true; } From a770174616419bf4b025650470c4d36f9699cfa9 Mon Sep 17 00:00:00 2001 From: Perry Mitchell Date: Mon, 1 Apr 2024 11:38:31 +0300 Subject: [PATCH 2/2] Document --no-update flag --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 7c41e016..4d1b17fd 100644 --- a/README.md +++ b/README.md @@ -92,6 +92,7 @@ The following arguments can be provided to Buttercup, but are all optional. |-----------------------|---------------------------------------| | `--autostart` | Flag passed to Buttercup when launched automatically by the OS. | | `--hidden` | Disables the automatic opening of the main window upon launch. | +| `--no-update` | Disables automatic update checking. **Not recommended**: Use at your own risk. | ### App config