Skip to content

armgit / bento

Public Imported from GitHub
0

Bento, the office suite that fits in a file

Keep the screen awake while presenting, and stop over-claiming the backup

nyblnet489d8d110701
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 52e9a943..548d0c67 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -24,6 +24,11 @@ pre-1.0.
a document name — it shows in the window title and becomes the suggested
filename — so it reads better in title case. The `bento/slides` wordmark is
unchanged.
+- **The screen stays awake while you present.** Phones and laptops used to dim
+ and lock partway through a talk if you left a slide up for a couple of
+ minutes. Bento now holds the screen on for the length of the show and lets go
+ when you exit — and takes the lock again if you switch away and come back.
+
- **Safari and Firefox are told the truth about saving.** Those browsers (and
every browser on iPhone and iPad) can't rewrite a file in place — Bento hands
back an updated copy instead. The editor used to say the opposite in its
diff --git a/kernel/src/autosave.ts b/kernel/src/autosave.ts
index b194f7cb..7b8fea83 100644
--- a/kernel/src/autosave.ts
+++ b/kernel/src/autosave.ts
@@ -67,9 +67,22 @@ function tx<T>(store: string, mode: IDBTransactionMode, fn: (s: IDBObjectStore)
})
}
-export async function putRecovery(doc: KernelDoc): Promise<void> {
- await tx(RECOVERY, 'readwrite', (s) =>
+/**
+ * Write the single latest recovery snapshot for this doc.
+ *
+ * Returns whether it ACTUALLY stored. `tx()` resolves null on every failure
+ * rather than throwing — no IndexedDB at all, a blocked open, a failed
+ * transaction — which is right for a best-effort backstop but means a caller
+ * cannot assume success. That distinction is load-bearing now that the editor
+ * tells the author their work is "backed up in this browser": Safari in private
+ * browsing and some `file://` contexts have no usable IndexedDB, and on iOS
+ * that is exactly where a shared deck tends to be opened. Claiming a backstop
+ * that isn't there would be worse than saying nothing.
+ */
+export async function putRecovery(doc: KernelDoc): Promise<boolean> {
+ const key = await tx(RECOVERY, 'readwrite', (s) =>
s.put({ docId: doc.docId, at: Date.now(), title: doc.title, json: JSON.stringify(doc) } as Snapshot))
+ return key != null
}
export async function getRecovery(docId: string): Promise<Snapshot | null> {
diff --git a/slides/src/editor/editor.ts b/slides/src/editor/editor.ts
index c0513801..cd6bf793 100644
--- a/slides/src/editor/editor.ts
+++ b/slides/src/editor/editor.ts
@@ -1625,8 +1625,9 @@ export class Editor {
// write-back below stays encrypted via serializeAuto.
let snapshotted = false
if (!isEncryptionActive()) {
- await putRecovery(doc)
- snapshotted = true
+ // only true if it REALLY stored — see putRecovery; no IndexedDB (Safari
+ // private browsing, some file:// contexts) must not read as "backed up"
+ snapshotted = await putRecovery(doc)
if (Date.now() - this.lastVersionAt > 120_000) { this.lastVersionAt = Date.now(); await addVersion(doc) }
}
// Silent file write-back once we hold a writable handle (Chrome/Edge).
diff --git a/slides/src/present.ts b/slides/src/present.ts
index e223b351..7993177a 100644
--- a/slides/src/present.ts
+++ b/slides/src/present.ts
@@ -443,6 +443,35 @@ export function startPresentation(
// element is what goes fullscreen, so the speaker popup stays independent.
// Requests can be denied (iframes, no user activation) — tab-fill mode is
// the graceful floor, and stays the mode for testing/sharing via F.
+ /**
+ * Keep the screen awake for the length of the show.
+ *
+ * This matters most on a PHONE, which is where a shared deck usually gets
+ * presented from: iOS dims and locks on its own idle timer, and a presenter
+ * advancing a slide every couple of minutes trips it mid-talk. Desktop
+ * benefits too — fullscreen alone does not defeat a screensaver.
+ *
+ * Best-effort by construction: the API is absent on older iOS (<16.4) and
+ * Firefox, and the request is REJECTED unless the page is visible, so this
+ * must never throw into the caller. The lock is also dropped by the browser
+ * whenever the tab is hidden — switching apps mid-show and coming back would
+ * otherwise leave the screen sleeping again — so re-acquire on visibility.
+ */
+ let wakeLock: { release(): Promise<void> } | null = null
+ const acquireWakeLock = async () => {
+ const wl = (navigator as any).wakeLock
+ if (!wl || wakeLock || document.visibilityState !== 'visible') return
+ try { wakeLock = await wl.request('screen') } catch { /* denied or unsupported */ }
+ }
+ const releaseWakeLock = () => {
+ const held = wakeLock
+ wakeLock = null
+ void held?.release?.().catch(() => {})
+ }
+ const onVisibility = () => { if (document.visibilityState === 'visible') void acquireWakeLock() }
+ document.addEventListener('visibilitychange', onVisibility)
+ void acquireWakeLock()
+
const enterFullscreen = () => {
overlay.requestFullscreen?.({ navigationUI: 'hide' }).catch(() => {})
}
@@ -480,6 +509,8 @@ export function startPresentation(
window.removeEventListener('resize', onResize)
document.removeEventListener('keydown', onKeydown, true)
document.removeEventListener('fullscreenchange', onFsChange)
+ document.removeEventListener('visibilitychange', onVisibility)
+ releaseWakeLock()
reduceQuery.removeEventListener?.('change', onMotionQuery)
clearInterval(speakerTimer)
if (speaker && !speaker.closed) {