Voice-to-text dictation app with local (Nvidia Parakeet/Whisper) and cloud models (BYOK). Privacy-first and available cross-platform.
JavaScript aianthropiccross-platformgeminigroqlinuxmacosnvidiaopen-sourceopenaiparakeetspeech-to-texttranscribewhisperwindows
fix(updater): stop automatic update checks when the App updates toggle is off — fixes #1605 (#1662)
Aditya Painulia880f2594bee
diff --git a/src/helpers/updateCheckPolicy.js b/src/helpers/updateCheckPolicy.jsnew file mode 100644index 000000000..5c2698f39--- /dev/null+++ b/src/helpers/updateCheckPolicy.js@@ -0,0 +1,10 @@+// The "App updates" toggle gates the automatic checks themselves, not just the+// popup: with it off the app must not reach the update feed, so offline or+// firewalled machines never surface a connection error dialog (#1605).+// Only an explicit false disables — missing prefs (renderer sync not arrived+// yet) keep check-by-default behavior.+function appUpdatesEnabled({ notificationsEnabled, notifyUpdates } = {}) {+ return notificationsEnabled !== false && notifyUpdates !== false;+}++module.exports = { appUpdatesEnabled };diff --git a/src/updater.js b/src/updater.jsindex 4208455f5..0924a528e 100644--- a/src/updater.js+++ b/src/updater.js@@ -1,4 +1,5 @@const { autoUpdater } = require("electron-updater");+const { appUpdatesEnabled } = require("./helpers/updateCheckPolicy");class UpdateManager {constructor() {@@ -86,9 +87,7 @@ class UpdateManager {};}this.notifyRenderers("update-available", info);- const nPrefs = this.windowManager?.notificationPrefs || {};- const notifAllowed =- nPrefs.notificationsEnabled !== false && nPrefs.notifyUpdates !== false;+ const notifAllowed = appUpdatesEnabled(this.windowManager?.notificationPrefs);if (this.windowManager && info && !this._suppressNotification && notifAllowed) {this.windowManager.showUpdateNotification(info).catch((err) => {console.error("Failed to show update notification:", err);@@ -301,21 +300,28 @@ class UpdateManager {}}+ // Prefs are read at fire time, not scheduling time, so flipping the+ // "App updates" toggle takes effect without a restart (#1605).+ _autoCheckForUpdates(label) {+ if (!appUpdatesEnabled(this.windowManager?.notificationPrefs)) {+ console.log(`⏭️ ${label} update check skipped (app updates disabled)`);+ return;+ }+ console.log(`🔄 ${label} update check...`);+ autoUpdater.checkForUpdates().catch((err) => {+ console.error(`${label} update check failed:`, err);+ });+ }+checkForUpdatesOnStartup() {if (process.env.NODE_ENV !== "development") {setTimeout(() => {- console.log("🔄 Checking for updates on startup...");- autoUpdater.checkForUpdates().catch((err) => {- console.error("Startup update check failed:", err);- });+ this._autoCheckForUpdates("Startup");}, 3000);const FOUR_HOURS_MS = 4 * 60 * 60 * 1000;this.updateCheckInterval = setInterval(() => {- console.log("🔄 Periodic update check...");- autoUpdater.checkForUpdates().catch((err) => {- console.error("Periodic update check failed:", err);- });+ this._autoCheckForUpdates("Periodic");}, FOUR_HOURS_MS);}}diff --git a/test/helpers/updateCheckPolicy.test.js b/test/helpers/updateCheckPolicy.test.jsnew file mode 100644index 000000000..e564f269e--- /dev/null+++ b/test/helpers/updateCheckPolicy.test.js@@ -0,0 +1,30 @@+const test = require("node:test");+const assert = require("node:assert/strict");++const load = () => import("../../src/helpers/updateCheckPolicy.js");++test("the App updates toggle gates automatic checks, not just the popup", async () => {+ const { appUpdatesEnabled } = await load();++ // Regression guard for #1605: with the toggle off, the app kept hitting the+ // update feed at startup and every 4 hours, and offline machines surfaced+ // the resulting connection errors as dialogs when Settings opened.+ assert.equal(appUpdatesEnabled({ notifyUpdates: false }), false);+ assert.equal(appUpdatesEnabled({ notificationsEnabled: true, notifyUpdates: false }), false);+});++test("the master notifications switch also disables automatic checks", async () => {+ const { appUpdatesEnabled } = await load();++ assert.equal(appUpdatesEnabled({ notificationsEnabled: false, notifyUpdates: true }), false);+});++test("checks stay enabled by default before renderer prefs arrive", async () => {+ const { appUpdatesEnabled } = await load();++ // Same tri-state convention as the other notification prefs: only an+ // explicit false disables; missing prefs keep check-by-default behavior.+ assert.equal(appUpdatesEnabled(undefined), true);+ assert.equal(appUpdatesEnabled({}), true);+ assert.equal(appUpdatesEnabled({ notificationsEnabled: true, notifyUpdates: true }), true);+});diff --git a/test/helpers/updater.test.js b/test/helpers/updater.test.jsnew file mode 100644index 000000000..150a180a4--- /dev/null+++ b/test/helpers/updater.test.js@@ -0,0 +1,201 @@+const test = require("node:test");+const { afterEach, beforeEach } = require("node:test");+const assert = require("node:assert/strict");+const Module = require("node:module");++process.env.NODE_ENV = "test";++const updaterModulePath = require.resolve("../../src/updater.js");+const originalLoad = Module._load;++const STARTUP_DELAY_MS = 3000;+const PERIODIC_INTERVAL_MS = 4 * 60 * 60 * 1000;++function makeAutoUpdater({ offline = false } = {}) {+ const listeners = {};+ const autoUpdater = {+ calls: 0,+ listeners,+ setFeedURL() {},+ on(event, handler) {+ listeners[event] = handler;+ },+ removeListener() {},+ checkForUpdates() {+ autoUpdater.calls += 1;+ if (offline) {+ // electron-updater emits the error before rejecting+ const error = new Error("net::ERR_INTERNET_DISCONNECTED");+ listeners.error?.(error);+ return Promise.reject(error);+ }+ return Promise.resolve({ isUpdateAvailable: false });+ },+ };+ return autoUpdater;+}++// updater.js requires electron and child_process lazily (constructor, cleanup(),+// Rosetta probe), so the mocks stay installed until afterEach.+function createUpdateManager(autoUpdater) {+ delete require.cache[updaterModulePath];+ Module._load = function loadWithMocks(request, parent, isMain) {+ if (request === "electron-updater") return { autoUpdater };+ if (request === "electron") return { autoUpdater: { on() {}, removeListener() {} } };+ if (request === "child_process") return { execSync: () => "0" };+ return originalLoad.call(this, request, parent, isMain);+ };+ const UpdateManager = require(updaterModulePath);+ return new UpdateManager();+}++function makeRendererWindow(sent) {+ return {+ isDestroyed: () => false,+ webContents: {+ send(channel) {+ sent.push(channel);+ },+ },+ };+}++beforeEach((t) => {+ t.mock.method(console, "log", () => {});+ t.mock.method(console, "error", () => {});+});++afterEach(() => {+ Module._load = originalLoad;+});++test("with App updates off, startup and periodic checks never reach the update feed", (t) => {+ t.mock.timers.enable({ apis: ["setTimeout", "setInterval"] });+ const autoUpdater = makeAutoUpdater();+ const manager = createUpdateManager(autoUpdater);+ manager.setWindowManager({+ notificationPrefs: { notificationsEnabled: true, notifyUpdates: false },+ });++ manager.checkForUpdatesOnStartup();+ t.mock.timers.tick(STARTUP_DELAY_MS);+ assert.equal(autoUpdater.calls, 0, "startup check must be skipped");+ t.mock.timers.tick(PERIODIC_INTERVAL_MS);+ assert.equal(autoUpdater.calls, 0, "periodic check must be skipped");++ manager.cleanup();+});++test("with App updates on, startup and periodic checks run as before", (t) => {+ t.mock.timers.enable({ apis: ["setTimeout", "setInterval"] });+ const autoUpdater = makeAutoUpdater();+ const manager = createUpdateManager(autoUpdater);+ manager.setWindowManager({+ notificationPrefs: { notificationsEnabled: true, notifyUpdates: true },+ });++ manager.checkForUpdatesOnStartup();+ t.mock.timers.tick(STARTUP_DELAY_MS);+ assert.equal(autoUpdater.calls, 1);+ t.mock.timers.tick(PERIODIC_INTERVAL_MS);+ assert.equal(autoUpdater.calls, 2);++ manager.cleanup();+});++test("prefs are read at fire time, so toggling App updates takes effect without a restart", (t) => {+ t.mock.timers.enable({ apis: ["setTimeout", "setInterval"] });+ const autoUpdater = makeAutoUpdater();+ const manager = createUpdateManager(autoUpdater);+ const windowManager = {+ notificationPrefs: { notificationsEnabled: true, notifyUpdates: false },+ };+ manager.setWindowManager(windowManager);+ manager.checkForUpdatesOnStartup();+ t.mock.timers.tick(STARTUP_DELAY_MS);+ assert.equal(autoUpdater.calls, 0);++ windowManager.notificationPrefs.notifyUpdates = true;+ t.mock.timers.tick(PERIODIC_INTERVAL_MS);+ assert.equal(autoUpdater.calls, 1, "next periodic tick runs once re-enabled");++ windowManager.notificationPrefs.notifyUpdates = false;+ t.mock.timers.tick(PERIODIC_INTERVAL_MS);+ assert.equal(autoUpdater.calls, 1, "and is skipped again once disabled");++ manager.cleanup();+});++test("before renderer prefs arrive, checks keep today's check-by-default behavior", (t) => {+ t.mock.timers.enable({ apis: ["setTimeout", "setInterval"] });+ const autoUpdater = makeAutoUpdater();+ const manager = createUpdateManager(autoUpdater);++ manager.checkForUpdatesOnStartup();+ t.mock.timers.tick(STARTUP_DELAY_MS);+ assert.equal(autoUpdater.calls, 1);++ manager.cleanup();+});++test("a manual Check for Updates is never gated by the toggle", async () => {+ const autoUpdater = makeAutoUpdater();+ const manager = createUpdateManager(autoUpdater);+ manager.setWindowManager({+ notificationPrefs: { notificationsEnabled: false, notifyUpdates: false },+ });++ const result = await manager.checkForUpdates();++ assert.equal(autoUpdater.calls, 1);+ assert.equal(result.updateAvailable, false);+});++test("offline with App updates off, no update-error reaches the renderers (#1605)", (t) => {+ t.mock.timers.enable({ apis: ["setTimeout", "setInterval"] });+ const autoUpdater = makeAutoUpdater({ offline: true });+ const manager = createUpdateManager(autoUpdater);+ const sent = [];+ const windowManager = {+ notificationPrefs: { notificationsEnabled: true, notifyUpdates: false },+ mainWindow: makeRendererWindow(sent),+ controlPanelWindow: makeRendererWindow(sent),+ };+ manager.setWindowManager(windowManager);++ manager.checkForUpdatesOnStartup();+ t.mock.timers.tick(STARTUP_DELAY_MS);+ assert.deepEqual(sent, [], "a skipped check produces no renderer traffic at all");++ windowManager.notificationPrefs.notifyUpdates = true;+ t.mock.timers.tick(PERIODIC_INTERVAL_MS);+ assert.ok(sent.includes("update-error"));++ manager.cleanup();+});++test("the update-available popup honors the same App updates gate", () => {+ const cases = [+ { prefs: { notificationsEnabled: true, notifyUpdates: true }, shown: 1 },+ { prefs: { notificationsEnabled: true, notifyUpdates: false }, shown: 0 },+ { prefs: { notificationsEnabled: false, notifyUpdates: true }, shown: 0 },+ ];++ for (const { prefs, shown } of cases) {+ const autoUpdater = makeAutoUpdater();+ const manager = createUpdateManager(autoUpdater);+ const popups = [];+ manager.setWindowManager({+ notificationPrefs: prefs,+ showUpdateNotification(info) {+ popups.push(info);+ return Promise.resolve();+ },+ });++ autoUpdater.listeners["update-available"]({ version: "9.9.9" });++ assert.equal(popups.length, shown, JSON.stringify(prefs));+ manager.cleanup();+ }+});