Skip to content

armgit / bento

Public Imported from GitHub
0

Bento, the office suite that fits in a file

v0.5.0: launch-time update checks, visible topbar affordance, opt-out

nyblnet7dd268de8afd
diff --git a/CLAUDE.md b/CLAUDE.md
index 675f4007..62e4177c 100644
--- a/CLAUDE.md
+++ b/CLAUDE.md
@@ -40,9 +40,11 @@ One HTML file = the document + viewer + editor. See `README.md` for the vision.
visually on canvas (`editor/patheditor.ts`): draggable anchors auto-smoothed
Catmull-Rom→cubic bezier; the stored path is RELATIVE to the element's rest
position (first anchor = rest position; committing moves the element there).
-- `src/update.ts` — signed self-update: About dialog (topbar logo) checks a
- release manifest ON USER CLICK ONLY (`bento.page`; dev override localStorage
- 'bento-update-url'), verifies ECDSA P-256 signature against the embedded
+- `src/update.ts` — signed self-update: checks a release manifest at LAUNCH
+ by default (localStorage 'bento-auto-check'='off' disables; toggle in the
+ About dialog; found updates badge the topbar sync button) and on demand via
+ About/topbar (`bento.page`; dev override localStorage 'bento-update-url'),
+ verifies ECDSA P-256 signature against the embedded
PUBLIC_KEY_JWK + sha256 of the fetched shell + version monotonicity, then
re-splices the current doc into the new shell (`save.serializeWith`) and
downloads it as a NEW file (original untouched = rollback). APP_VERSION baked
diff --git a/docs/architecture.md b/docs/architecture.md
index 44237988..115122ef 100644
--- a/docs/architecture.md
+++ b/docs/architecture.md
@@ -290,6 +290,7 @@ deliver downloaded as a NEW file — the on-disk original is its own rollback
hashes the built shell and writes the signed manifest. A compromised release
host cannot forge an update without that key. Rotating the key orphans every
shipped file — guard the key instead.
-- Privacy: the check is a bare GET with no identifiers, never automatic.
+- Privacy: the check is a bare GET with no identifiers. It runs at launch by
+ default (per-browser opt-out in the About dialog) or on demand.
- Update channel = signed **code**; future sync channel = inert **data**
(invariant 3). Never mix the two.
diff --git a/slides/package.json b/slides/package.json
index ae52c715..ed770b6d 100644
--- a/slides/package.json
+++ b/slides/package.json
@@ -1,7 +1,7 @@
{
"name": "bento-slides",
"private": true,
- "version": "0.4.2",
+ "version": "0.5.0",
"type": "module",
"scripts": {
"dev": "vite",
diff --git a/slides/src/editor/editor.ts b/slides/src/editor/editor.ts
index 8a0aa313..ffdd2f03 100644
--- a/slides/src/editor/editor.ts
+++ b/slides/src/editor/editor.ts
@@ -8,7 +8,7 @@ import {
instantiateLayout, layoutElementIds, uid,
type ShapeKind, type Slide, type SlideElement,
} from '../model'
-import { APP_VERSION, applyUpdate, applyUpdateInPlace, canUpdateInPlace, checkForUpdates } from '../update'
+import { APP_VERSION, applyUpdate, applyUpdateInPlace, autoCheckEnabled, canUpdateInPlace, checkForUpdates, setAutoCheck } from '../update'
import { CHART_PRESETS } from '../charts'
import { renderSlide, renderThumbnail } from '../render'
import { SlideCanvas } from './canvas'
@@ -34,6 +34,8 @@ export class Editor {
private thumbTimer = 0
private clipboard: SlideElement[] = []
private presenting = false
+ private updatesB!: HTMLElement
+ private updateFound: string | null = null
/** side panel widths (px) — user-resizable, persisted per browser */
private panelW = { left: 188, right: 236 }
@@ -100,6 +102,19 @@ export class Editor {
insert.appendChild(commentB)
const actions = div('ed-group ed-group-right')
+ this.updatesB = btn(ICONS.sync, '', () => this.openAbout(true), 'Check for updates')
+ // launch-time check (opt-out lives in the About dialog); a found update
+ // turns the button into a visible peach chip
+ setTimeout(async () => {
+ if (!autoCheckEnabled()) return
+ const r = await checkForUpdates()
+ if (r.status === 'update') {
+ this.updateFound = r.release.version
+ this.updatesB.classList.add('ed-btn-update')
+ this.updatesB.innerHTML = `${ICONS.sync}<span>v${r.release.version}</span>`
+ this.updatesB.title = `Version ${r.release.version} is available — click to update`
+ }
+ }, 1500)
const undoB = btn(ICONS.undo, '', () => this.store.undo(), 'Undo (⌘Z)')
const redoB = btn(ICONS.redo, '', () => this.store.redo(), 'Redo (⇧⌘Z)')
const presentB = btn(ICONS.play, 'Present', () => this.present(), 'Present from current slide')
@@ -109,7 +124,7 @@ export class Editor {
const pdfB = btn(ICONS.pdf, '', () => this.exportPdf(), 'Export PDF (print)')
const leftT = btn(ICONS.panelLeft, '', () => this.togglePanel('left'), 'Toggle slide list ([)')
const rightT = btn(ICONS.panelRight, '', () => this.togglePanel('right'), 'Toggle properties (])')
- actions.append(undoB, redoB, pdfB, leftT, rightT, presentB, saveB, saveAsB)
+ actions.append(undoB, redoB, pdfB, this.updatesB, leftT, rightT, presentB, saveB, saveAsB)
bar.append(logo, title, this.dirtyDot, insert, actions)
@@ -705,7 +720,7 @@ export class Editor {
// --- about & updates ------------------------------------------------------
/** About dialog: version, user-initiated update check, licenses. */
- private openAbout() {
+ private openAbout(runCheck = false) {
document.querySelector('.ed-about-overlay')?.remove()
const overlay = div('ed-about-overlay')
const box = div('ed-about')
@@ -806,9 +821,18 @@ export class Editor {
row.appendChild(checkB)
box.append(row, status)
+ const autoRow = document.createElement('label')
+ autoRow.className = 'ed-about-auto'
+ const autoCb = document.createElement('input')
+ autoCb.type = 'checkbox'
+ autoCb.checked = autoCheckEnabled()
+ autoCb.addEventListener('change', () => setAutoCheck(autoCb.checked))
+ autoRow.append(autoCb, document.createTextNode(' Check for updates automatically at launch'))
+ box.appendChild(autoRow)
+
const fine = div('ed-about-fine')
fine.innerHTML =
- `Checking contacts the release server once and sends nothing about you or this document.<br>` +
+ `Checks contact the release server and send nothing about you or this document — no ids, no telemetry.<br>` +
`Includes reveal.js, Moveable, Selecto (MIT) · Apache ECharts (Apache-2.0) · zrender (BSD-3) · Fraunces typeface (OFL-1.1) — full notices travel in this file’s source.`
box.appendChild(fine)
@@ -828,6 +852,7 @@ export class Editor {
})
document.addEventListener('keydown', onKey, true)
document.body.appendChild(overlay)
+ if (runCheck || this.updateFound) checkB.click()
}
toast(message: string) {
diff --git a/slides/src/starterdeck.ts b/slides/src/starterdeck.ts
index 208dd20b..95fdd5d9 100644
--- a/slides/src/starterdeck.ts
+++ b/slides/src/starterdeck.ts
@@ -439,7 +439,7 @@ export function starterDoc(): BentoDoc {
}),
text({
x: 600, y: 556, w: 560, h: 50,
- html: 'Updates? The file checks a signed manifest — <b>only when you ask</b> — and rewrites itself.',
+ html: 'Updates? The file checks a signed manifest at launch — <b>you can turn that off</b> — and rewrites itself.',
fontSize: 15, fontWeight: 500, color: INK_SOFT, lineHeight: 1.55,
}),
],
diff --git a/slides/src/styles.css b/slides/src/styles.css
index 14d3d4ac..a18cc009 100644
--- a/slides/src/styles.css
+++ b/slides/src/styles.css
@@ -411,6 +411,21 @@ html, body {
}
.ed-hint code { font-size: 10.5px; word-break: break-all; }
+.ed-btn-update {
+ background: #FF9E8A !important;
+ color: #0D1B2E !important;
+ font-weight: 700;
+}
+.ed-about-auto {
+ display: flex;
+ align-items: center;
+ gap: 7px;
+ font-size: 12px;
+ color: var(--muted);
+ cursor: pointer;
+ user-select: none;
+}
+
/* ————— about dialog ————— */
.ed-about-overlay {
diff --git a/slides/src/update.ts b/slides/src/update.ts
index 6ece2452..b574804e 100644
--- a/slides/src/update.ts
+++ b/slides/src/update.ts
@@ -1,7 +1,8 @@
-// Self-update: a shipped Bento file can, ON USER REQUEST ONLY, ask the
-// release origin whether a newer app shell exists, and rebuild itself as
-// "same document, newer app" — the data block re-spliced into the fetched
-// shell via the exact machinery every save already uses.
+// Self-update: a shipped Bento file asks the release origin whether a newer
+// app shell exists — automatically at launch (per-browser opt-out in the
+// About dialog) or on demand — and rebuilds itself as "same document, newer
+// app": the data block re-spliced into the fetched shell via the exact
+// machinery every save already uses.
//
// Trust model (see docs/architecture.md):
// - The manifest is SIGNED (ECDSA P-256 / SHA-256) with an offline key; the
@@ -10,8 +11,8 @@
// - The manifest pins the new shell's sha256; the download is hashed and
// compared before anything is spliced.
// - Only strictly NEWER versions are ever offered (no downgrade replay).
-// - Nothing is automatic and nothing identifies the user or the document:
-// the check is a bare GET, fired only from the About dialog / scripting.
+// - A check is a bare GET: no identifiers, no telemetry, nothing about the
+// user or the document. The launch check can be disabled (autoCheckEnabled).
//
// The result is always a NEW downloaded file — the update flow never touches
// the file on disk, so the original is its own rollback.
@@ -27,6 +28,13 @@ declare const __APP_VERSION__: string
/** Version of the running app shell (baked in at build from package.json). */
export const APP_VERSION: string = typeof __APP_VERSION__ !== 'undefined' ? __APP_VERSION__ : '0.0.0'
+/** Per-browser preference: check for updates automatically at launch. */
+export const autoCheckEnabled = (): boolean => localStorage.getItem('bento-auto-check') !== 'off'
+export const setAutoCheck = (on: boolean): void => {
+ if (on) localStorage.removeItem('bento-auto-check')
+ else localStorage.setItem('bento-auto-check', 'off')
+}
+
/** Where shipped files look for releases. Dev override: localStorage 'bento-update-url'. */
export const UPDATE_MANIFEST_URL = 'https://bento.page/releases/slides/manifest.json'
@@ -107,7 +115,7 @@ async function verifyManifest(raw: string): Promise<ReleaseInfo> {
return info as ReleaseInfo
}
-/** Ask the release origin for the latest version. User-initiated only. */
+/** Ask the release origin for the latest version. */
export async function checkForUpdates(manifestUrl?: string): Promise<UpdateCheck> {
const url = manifestUrl ?? localStorage.getItem('bento-update-url') ?? UPDATE_MANIFEST_URL
try {