Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable updates via launch args #1320

Merged
merged 2 commits into from
Apr 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions source/main/ipc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
});

Expand Down
2 changes: 1 addition & 1 deletion source/main/library/build.ts
Original file line number Diff line number Diff line change
@@ -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";
4 changes: 4 additions & 0 deletions source/main/services/arguments.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { app } from "electron";
import { isOSX } from "../../shared/library/platform";
import { disableUpdates } from "./update";

let __autostarted = false,
__showMainWindow = true;
Expand All @@ -22,6 +23,9 @@ export function processLaunchConfiguration() {
if (cl.hasSwitch("autostart")) {
__autostarted = true;
}
if (cl.hasSwitch("no-update")) {
disableUpdates();
}
}

export function shouldShowMainWindow(): boolean {
Expand Down
38 changes: 25 additions & 13 deletions source/main/services/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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();
Expand All @@ -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;
Expand All @@ -74,6 +75,7 @@ function attachEventListeners(updater = autoUpdater) {
}

async function checkForUpdateInternal() {
if (__updatesDisabled) return;
if (!__eventListenersAttached) {
__eventListenersAttached = true;
attachEventListeners();
Expand All @@ -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({
Expand All @@ -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 {
Expand All @@ -120,7 +132,7 @@ export function installUpdate() {
}

export function muteUpdate() {
logInfo("Update notification muted");
logInfo("Updates: Update notification muted");
__updateMuted = true;
}

Expand Down
Loading