Update the app while a timer runs

When a new service worker takes control, the app shows an UPDATE
button. If the page is hidden, the app reloads into the new version.
It does not reload while the entry editor is open or while a save or
import runs. A running timer continues after the reload, because it is
stored with its start time in IndexedDB.

The app asks for a new version when it becomes visible and one time
each hour, because an installed PWA can stay open for days.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
minhtrannhatandClaude Opus 5.5 committed 2026-11-08 14:49:29 -05:00
1 parent a6ca255835
commit 9fba5de6d7
4 files changed
+87 -5

No files matched your search

+26
View File
@@ -0,0 +1,26 @@
import { describe, expect, test } from "bun:test";
import { readyToReload } from "../src/client/update.ts";
const safe = { updateReady: true, hidden: true, editing: false, busy: false };
describe("app update reload", () => {
test("reloads a hidden page when an update is ready and nothing is open", () => {
expect(readyToReload(safe)).toBe(true);
});
test("does not reload without an update", () => {
expect(readyToReload({ ...safe, updateReady: false })).toBe(false);
});
test("does not reload while the user looks at the page", () => {
expect(readyToReload({ ...safe, hidden: false })).toBe(false);
});
test("does not reload while the entry editor is open", () => {
expect(readyToReload({ ...safe, editing: true })).toBe(false);
});
test("does not reload while a save or import runs", () => {
expect(readyToReload({ ...safe, busy: true })).toBe(false);
});
});