Skip to content

Open-source Grok Bot alternative with a virtual machine that bots can use

Updater: count a failed check once, and keep the failure notice up during quiet checks (#3966)

Caleb Arumugam9519c4ccdc3b
diff --git a/electron/updater-coordinator.mjs b/electron/updater-coordinator.mjs
index 8b02976b24..faeeebf1e2 100644
--- a/electron/updater-coordinator.mjs
+++ b/electron/updater-coordinator.mjs
@@ -110,7 +110,8 @@ export function createUpdaterCoordinator(
}
updater.on("checking-for-update", () => {
- if (checkOwnsState()) setState({ status: "checking" });
+ // The banner shows nothing while checking, so a quiet check must not replace the notice; a manual retry still shows it.
+ if (checkOwnsState() && (checkOperation?.manual || quietFailures < QUIET_FAILURES_BEFORE_NOTICE)) setState({ status: "checking" });
});
updater.on("update-available", (info) => {
quietFailures = 0;
@@ -184,13 +185,13 @@ export function createUpdaterCoordinator(
try {
operation.promise = Promise.resolve(updater.checkForUpdates())
.catch((error) => {
- if (!operation.supersededByDownload && !(operation.recheck && !operation.manual)) handleRejectedOperation(operation.manual, error);
+ if (!operation.failed && !operation.supersededByDownload && !(operation.recheck && !operation.manual)) handleRejectedOperation(operation.manual, error);
})
.finally(() => {
if (checkOperation === operation) checkOperation = null;
});
} catch (error) {
- if (!operation.supersededByDownload && !(operation.recheck && !operation.manual)) handleRejectedOperation(operation.manual, error);
+ if (!operation.failed && !operation.supersededByDownload && !(operation.recheck && !operation.manual)) handleRejectedOperation(operation.manual, error);
checkOperation = null;
operation.promise = Promise.resolve();
}
diff --git a/electron/updater-coordinator.node-test.mjs b/electron/updater-coordinator.node-test.mjs
index bce4e2c99f..1f41d71acb 100644
--- a/electron/updater-coordinator.node-test.mjs
+++ b/electron/updater-coordinator.node-test.mjs
@@ -925,3 +925,43 @@ test("the check-failure notice never covers a staged update: hourly re-checks th
for (let i = 0; i < 4; i++) await h.coordinator.check();
assert.deepEqual(h.getState(), staged);
});
+
+test("a check that emits an error and rejects with a different one counts as one quiet failure", async () => {
+ const h = harness();
+ h.updater.checkForUpdates = () => {
+ h.updater.emit("error", new Error("offline"));
+ return Promise.reject(new Error("offline"));
+ };
+
+ await h.coordinator.check();
+ await h.coordinator.check();
+ assert.equal(h.getState().status, "idle");
+ assert.equal(errorStates(h.states).length, 0);
+
+ await h.coordinator.check();
+ assert.equal(h.getState().status, "error");
+ assert.match(h.getState().message, /Couldn't check for updates/);
+});
+
+test("the check-failure notice stays up while the next hourly check runs, and a manual retry still shows checking", async () => {
+ const h = harness();
+ h.updater.checkForUpdates = () => Promise.reject(new Error("offline"));
+ for (let i = 0; i < 3; i++) await h.coordinator.check();
+ assert.equal(h.getState().status, "error");
+
+ let before = h.states.length;
+ h.updater.checkForUpdates = () => {
+ h.updater.emit("checking-for-update");
+ return Promise.reject(new Error("offline"));
+ };
+ await h.coordinator.check();
+ assert.deepEqual(h.states.slice(before).map((entry) => entry.status), ["error"]);
+
+ before = h.states.length;
+ h.updater.checkForUpdates = async () => {
+ h.updater.emit("checking-for-update");
+ h.updater.emit("update-not-available");
+ };
+ await h.coordinator.check(true);
+ assert.deepEqual(h.states.slice(before).map((entry) => entry.status), ["checking", "idle"]);
+});