feat(web): hold a Screen Wake Lock while reading or listening
Release / build-and-push (push) Successful in 3m12s

New wake-lock.ts engine (sanctioned island, dependency-injected for
tests): feature-detected navigator.wakeLock, silent no-op when
unsupported or denied, and the spec-mandated force-release-on-hide →
re-acquire-on-visible loop handled via the sentinel release event.
The player acquires on play and releases on pause (sleep-timer fades
ride the same path); the reader holds the lock for the session. Both
gate on the keep_screen_awake preference — data-keep-awake on the
player root, keepScreenAwake in readerInitExpr.

Hidden-tab playback intentionally does not keep the screen awake:
the spec forbids screen wake locks for hidden documents.
This commit is contained in:
John O'Keefe committed 2026-10-26 13:59:37 -04:00
1 parent c645b8e207
commit afbf1029a9
8 files changed
+375 -56

No files matched your search

+9
View File
@@ -7,6 +7,7 @@ import { getToken } from "../storage";
import { showToast } from "../toast";
import { renderNoteHtml, richPasteToMarkdown } from "../markdown";
import { extractPdfPages, searchPdfPages, type PdfPageText } from "./pdf-search";
import { WakeLockManager } from "../wake-lock";
const HIGHLIGHT_COLORS = ["#ffd54f", "#a5d6a7", "#90caf9", "#f48fb1", "#ce93d8"];
@@ -398,6 +399,10 @@ document.addEventListener("alpine:init", () => {
// comic reader treatment — bookmarks only, no text-selection
// highlights, no in-book search.
treatAsComic: false as boolean,
// Screen wake lock (keep_screen_awake profile preference): held for
// the whole reading session; the browser force-releases it when the
// page hides and the manager re-acquires on visibility regain.
wakeLock: new WakeLockManager(),
comicFlow: "paged" as string,
fxBrightness: 1 as number,
fxContrast: 1 as number,
@@ -627,9 +632,13 @@ document.addEventListener("alpine:init", () => {
readingDirection: string;
mangaType: string;
treatAsComic: boolean;
keepScreenAwake: boolean;
}) {
this.mediaItemId = config.mediaItemId;
this.treatAsComic = config.treatAsComic;
// Hold the display awake for the reading session (best-effort;
// unsupported browsers and power-saver denials are silent no-ops).
if (config.keepScreenAwake) void this.wakeLock.acquire();
// Reading state (position, bookmarks, annotations) is never baked
// into the rendered page: the web reader is intrinsically tied to
// the server, so it reads all of it from the APIs at open time —