Skip to content

armgit / bento

Public Imported from GitHub
0

Bento, the office suite that fits in a file

v0.9.11: dual-screen speaker via a one-click grant button (fixes the activation deadlock)

nyblnet327e33a901d2
diff --git a/slides/package.json b/slides/package.json
index d0effcb4..c4217471 100644
--- a/slides/package.json
+++ b/slides/package.json
@@ -1,7 +1,7 @@
{
"name": "bento-slides",
"private": true,
- "version": "0.9.10",
+ "version": "0.9.11",
"type": "module",
"scripts": {
"dev": "vite",
diff --git a/slides/src/i18n/de.ts b/slides/src/i18n/de.ts
index 8da56a7f..fdcfbad0 100644
--- a/slides/src/i18n/de.ts
+++ b/slides/src/i18n/de.ts
@@ -415,4 +415,8 @@ export const de: Catalog = {
"Make a chart from a table and it stays linked — edit the table, the chart updates.": "Aus einer Tabelle ein Diagramm erstellen — es bleibt verknüpft: Tabelle bearbeiten, Diagramm aktualisiert sich.",
"Your work auto-saves; restore earlier versions from About → Version history.": "Deine Arbeit wird automatisch gespeichert; frühere Versionen unter Über → Versionsverlauf wiederherstellen.",
"Slide copied — ⌘V in any deck to paste it": "Folie kopiert — ⌘V in einer beliebigen Präsentation zum Einfügen",
+ "📺 Use a second screen for notes": "📺 Zweiten Bildschirm für Notizen nutzen",
+ "Second screen ready — press S for speaker notes": "Zweiter Bildschirm bereit — S für die Referentenansicht",
+ "Only one screen detected — notes will open in a window (S)": "Nur ein Bildschirm erkannt — Notizen öffnen in einem Fenster (S)",
+ "Couldn’t access displays — notes will open in a window (S)": "Kein Zugriff auf Bildschirme — Notizen öffnen in einem Fenster (S)",
}
diff --git a/slides/src/i18n/es.ts b/slides/src/i18n/es.ts
index e0a55baa..702ef4a1 100644
--- a/slides/src/i18n/es.ts
+++ b/slides/src/i18n/es.ts
@@ -415,4 +415,8 @@ export const es: Catalog = {
"Make a chart from a table and it stays linked — edit the table, the chart updates.": "Crea un gráfico a partir de una tabla y queda vinculado — edita la tabla y el gráfico se actualiza.",
"Your work auto-saves; restore earlier versions from About → Version history.": "Tu trabajo se guarda automáticamente; restaura versiones anteriores en Acerca de → Historial de versiones.",
"Slide copied — ⌘V in any deck to paste it": "Diapositiva copiada — ⌘V en cualquier presentación para pegarla",
+ "📺 Use a second screen for notes": "📺 Usar una segunda pantalla para las notas",
+ "Second screen ready — press S for speaker notes": "Segunda pantalla lista — pulsa S para las notas del ponente",
+ "Only one screen detected — notes will open in a window (S)": "Solo se detectó una pantalla — las notas se abrirán en una ventana (S)",
+ "Couldn’t access displays — notes will open in a window (S)": "No se pudo acceder a las pantallas — las notas se abrirán en una ventana (S)",
}
diff --git a/slides/src/i18n/fr.ts b/slides/src/i18n/fr.ts
index cce55a76..e14edce2 100644
--- a/slides/src/i18n/fr.ts
+++ b/slides/src/i18n/fr.ts
@@ -415,4 +415,8 @@ export const fr: Catalog = {
"Make a chart from a table and it stays linked — edit the table, the chart updates.": "Créez un graphique à partir d’un tableau : il reste lié — modifiez le tableau, le graphique se met à jour.",
"Your work auto-saves; restore earlier versions from About → Version history.": "Votre travail est enregistré automatiquement ; restaurez d’anciennes versions dans À propos → Historique des versions.",
"Slide copied — ⌘V in any deck to paste it": "Diapositive copiée — ⌘V dans n’importe quel deck pour la coller",
+ "📺 Use a second screen for notes": "📺 Utiliser un second écran pour les notes",
+ "Second screen ready — press S for speaker notes": "Second écran prêt — appuyez sur S pour les notes du présentateur",
+ "Only one screen detected — notes will open in a window (S)": "Un seul écran détecté — les notes s’ouvriront dans une fenêtre (S)",
+ "Couldn’t access displays — notes will open in a window (S)": "Impossible d’accéder aux écrans — les notes s’ouvriront dans une fenêtre (S)",
}
diff --git a/slides/src/i18n/it.ts b/slides/src/i18n/it.ts
index 532c63c0..3c2faaf1 100644
--- a/slides/src/i18n/it.ts
+++ b/slides/src/i18n/it.ts
@@ -415,4 +415,8 @@ export const it: Catalog = {
"Make a chart from a table and it stays linked — edit the table, the chart updates.": "Crea un grafico da una tabella e resta collegato — modifichi la tabella, il grafico si aggiorna.",
"Your work auto-saves; restore earlier versions from About → Version history.": "Il tuo lavoro si salva automaticamente; ripristina versioni precedenti da Informazioni → Cronologia versioni.",
"Slide copied — ⌘V in any deck to paste it": "Diapositiva copiata — ⌘V in qualsiasi deck per incollarla",
+ "📺 Use a second screen for notes": "📺 Usa un secondo schermo per le note",
+ "Second screen ready — press S for speaker notes": "Secondo schermo pronto — premi S per le note del relatore",
+ "Only one screen detected — notes will open in a window (S)": "Rilevato un solo schermo — le note si apriranno in una finestra (S)",
+ "Couldn’t access displays — notes will open in a window (S)": "Impossibile accedere agli schermi — le note si apriranno in una finestra (S)",
}
diff --git a/slides/src/i18n/ja.ts b/slides/src/i18n/ja.ts
index 7759ea4a..245b4dec 100644
--- a/slides/src/i18n/ja.ts
+++ b/slides/src/i18n/ja.ts
@@ -415,4 +415,8 @@ export const ja: Catalog = {
"Make a chart from a table and it stays linked — edit the table, the chart updates.": "表からグラフを作ると連携が保たれ、表を編集するとグラフも更新されます。",
"Your work auto-saves; restore earlier versions from About → Version history.": "作業は自動保存されます。以前のバージョンは「情報」→「バージョン履歴」から復元できます。",
"Slide copied — ⌘V in any deck to paste it": "スライドをコピーしました — 任意のデッキで ⌘V で貼り付け",
+ "📺 Use a second screen for notes": "📺 ノートに2台目の画面を使う",
+ "Second screen ready — press S for speaker notes": "2台目の画面が準備できました — S で発表者ノート",
+ "Only one screen detected — notes will open in a window (S)": "画面は1台のみ — ノートはウィンドウで開きます(S)",
+ "Couldn’t access displays — notes will open in a window (S)": "ディスプレイにアクセスできません — ノートはウィンドウで開きます(S)",
}
diff --git a/slides/src/i18n/zh-Hans.ts b/slides/src/i18n/zh-Hans.ts
index 364808c0..89012821 100644
--- a/slides/src/i18n/zh-Hans.ts
+++ b/slides/src/i18n/zh-Hans.ts
@@ -415,4 +415,8 @@ export const zhHans: Catalog = {
"Make a chart from a table and it stays linked — edit the table, the chart updates.": "从表格生成图表后会保持关联 — 编辑表格,图表随之更新。",
"Your work auto-saves; restore earlier versions from About → Version history.": "你的工作会自动保存;可从“关于 → 版本历史”恢复较早的版本。",
"Slide copied — ⌘V in any deck to paste it": "已复制幻灯片 — 在任意演示中按 ⌘V 粘贴",
+ "📺 Use a second screen for notes": "📺 用第二块屏幕显示备注",
+ "Second screen ready — press S for speaker notes": "第二块屏幕已就绪 — 按 S 显示演讲者备注",
+ "Only one screen detected — notes will open in a window (S)": "仅检测到一块屏幕 — 备注将在窗口中打开(S)",
+ "Couldn’t access displays — notes will open in a window (S)": "无法访问显示器 — 备注将在窗口中打开(S)",
}
diff --git a/slides/src/i18n/zh-Hant.ts b/slides/src/i18n/zh-Hant.ts
index c4d64684..dd3a7f4d 100644
--- a/slides/src/i18n/zh-Hant.ts
+++ b/slides/src/i18n/zh-Hant.ts
@@ -415,4 +415,8 @@ export const zhHant: Catalog = {
"Make a chart from a table and it stays linked — edit the table, the chart updates.": "從表格產生圖表後會保持關聯 — 編輯表格,圖表隨之更新。",
"Your work auto-saves; restore earlier versions from About → Version history.": "你的工作會自動儲存;可從「關於 → 版本歷程」還原較早的版本。",
"Slide copied — ⌘V in any deck to paste it": "已複製投影片 — 在任意簡報中按 ⌘V 貼上",
+ "📺 Use a second screen for notes": "📺 用第二個螢幕顯示備註",
+ "Second screen ready — press S for speaker notes": "第二個螢幕已就緒 — 按 S 顯示演講者備註",
+ "Only one screen detected — notes will open in a window (S)": "僅偵測到一個螢幕 — 備註將在視窗中開啟(S)",
+ "Couldn’t access displays — notes will open in a window (S)": "無法存取顯示器 — 備註將在視窗中開啟(S)",
}
diff --git a/slides/src/present.ts b/slides/src/present.ts
index 8ee83f50..537e5872 100644
--- a/slides/src/present.ts
+++ b/slides/src/present.ts
@@ -141,20 +141,58 @@ export function startPresentation(
// DIRECTLY on a second display (window.open left/top) — moving it after the
// fact is what left the notes stranded behind the fullscreen slides.
let screenLayout: { screens: any[]; currentScreen: any } | null = null
- const primeScreens = () => {
- const gsd = (window as unknown as { getScreenDetails?: () => Promise<any> }).getScreenDetails
- if (!gsd) { console.info('[bento-speaker] Window Management API unavailable — notes will open on this screen'); return }
- gsd.call(window).then((d: any) => {
- screenLayout = d
- console.info('[bento-speaker] primed screens:', d.screens?.length, '· permission ok')
- d.addEventListener?.('screenschange', () => { screenLayout = d })
- }).catch((e: any) => console.warn('[bento-speaker] screen access denied:', e?.name, e?.message, '— grant “window management” in the site permissions (address-bar icon) to auto-place notes'))
- }
+ let grantBtn: HTMLButtonElement | null = null
+ const hasWM = () => !!(window as unknown as { getScreenDetails?: unknown }).getScreenDetails
const secondScreen = () => {
const s = screenLayout
if (!s || !Array.isArray(s.screens) || s.screens.length < 2) return null
return s.screens.find((x) => x !== s.currentScreen) ?? s.screens.find((x) => !x.isPrimary) ?? s.screens[1]
}
+ // getScreenDetails() returns a LIVE object; we call it once (needs activation
+ // only to prompt) and keep it. Returns true if we now hold a layout.
+ const cacheScreens = async (): Promise<boolean> => {
+ const gsd = (window as unknown as { getScreenDetails?: () => Promise<any> }).getScreenDetails
+ if (!gsd) return false
+ try {
+ screenLayout = await gsd.call(window)
+ console.info('[bento-speaker] screens ready:', screenLayout?.screens?.length)
+ return true
+ } catch (e: any) {
+ console.warn('[bento-speaker] getScreenDetails failed:', e?.name, e?.message)
+ return false
+ }
+ }
+ // A dedicated-gesture button to grant "window management" — the ONLY reliable
+ // way, since the S keypress activation is spent on window.open/fullscreen.
+ const showGrantButton = () => {
+ if (grantBtn || !hasWM()) return
+ const b = document.createElement('button')
+ b.className = 'bento-present-grant'
+ b.textContent = t('📺 Use a second screen for notes')
+ b.addEventListener('click', async () => {
+ const ok = await cacheScreens() // this click IS the activation → prompts once
+ grantBtn?.remove(); grantBtn = null
+ const msg = document.createElement('div')
+ msg.className = 'bento-present-toast'
+ msg.textContent = ok && secondScreen()
+ ? t('Second screen ready — press S for speaker notes')
+ : (ok ? t('Only one screen detected — notes will open in a window (S)') : t('Couldn’t access displays — notes will open in a window (S)'))
+ overlay.appendChild(msg)
+ window.setTimeout(() => msg.remove(), 4000)
+ })
+ overlay.appendChild(b)
+ grantBtn = b
+ }
+ // At present-start: if we can read the layout without a prompt (permission
+ // already granted), cache it; otherwise offer the grant button.
+ const setupSecondScreen = async () => {
+ if (!hasWM()) return
+ let state = 'prompt'
+ try { state = (await (navigator as unknown as { permissions?: { query?: (o: unknown) => Promise<{ state: string }> } }).permissions?.query?.({ name: 'window-management' as PermissionName }))?.state ?? 'prompt' } catch { /* no query api */ }
+ console.info('[bento-speaker] window-management permission:', state)
+ if (state === 'granted' && await cacheScreens()) return
+ if (state !== 'denied') showGrantButton()
+ }
const nextVisibleIndex = (from: number) => {
for (let i = (isState(from) ? anchorOf(from) : from) + 1; i < doc.slides.length; i++) {
if (!isState(i)) return i
@@ -244,56 +282,21 @@ export function startPresentation(
if (clock) clock.textContent = new Date().toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' })
}, 1000)
updateSpeaker()
- // Re-enter fullscreen SYNCHRONOUSLY here, still inside the S-key gesture, so
- // the request isn't rejected for lost user-activation (the #1 macOS failure).
- // Opening the popup drops us out of fullscreen; this puts the slides back on
- // the presenter's screen. Then async-move the notes to a second display.
- if (wasFullscreen) {
- overlay.requestFullscreen?.({ navigationUI: 'hide' }).catch((e: any) =>
- console.warn('[bento-speaker] sync re-fullscreen rejected:', e?.name, e?.message))
- }
- void placeSpeaker(wasFullscreen)
- }
-
- /**
- * Move the notes popup to a second display (Window Management permission).
- * Heavily instrumented: with no two-monitor rig to test on, the console log is
- * how we diagnose. Degrades gracefully — single screen / denied / unsupported
- * keeps the notes visible on the current display. Slides fullscreen is handled
- * synchronously in openSpeaker above (activation-safe).
- */
- const placeSpeaker = async (wasFullscreen: boolean) => {
- const log = (...a: unknown[]) => console.info('[bento-speaker]', ...a)
- try {
- let perm = 'unknown'
- try { perm = (await (navigator as any).permissions?.query?.({ name: 'window-management' }))?.state ?? 'no-api' } catch { perm = 'query-failed' }
- const getScreenDetails = (window as unknown as { getScreenDetails?: () => Promise<any> }).getScreenDetails
- log('permission:', perm, '· getScreenDetails:', !!getScreenDetails, '· wasFullscreen:', wasFullscreen)
- if (!getScreenDetails) {
- log('Window Management API unavailable — notes stay on this screen')
- return
- }
- const details = await getScreenDetails.call(window)
- screenLayout = details // cache so the NEXT open goes straight to screen 2
- const screens: any[] = details.screens ?? []
- log('screens:', screens.length, screens.map((s: any) => ({ label: s.label, primary: s.isPrimary, current: s === details.currentScreen, x: s.availLeft, y: s.availTop, w: s.availWidth, h: s.availHeight })))
- if (screens.length > 1 && speaker) {
- const other = screens.find((s) => s !== details.currentScreen) ?? screens.find((s) => !s.isPrimary) ?? screens[1]
- try {
- // move it even if we already opened there — corrects any clamp
- speaker.moveTo(other.availLeft, other.availTop)
- speaker.resizeTo(Math.min(other.availWidth, 1400), Math.min(other.availHeight, 900))
- window.focus() // keep the presenter screen focused for fullscreen
- log('placed notes → screen:', other.label, 'at', other.availLeft, other.availTop)
- } catch (e: any) { console.warn('[bento-speaker] moveTo/resizeTo failed:', e?.message) }
- } else {
- log('single display — press F to fullscreen slides; drag the notes window where you want it')
- }
- } catch (e: any) {
- console.warn('[bento-speaker] getScreenDetails denied/failed:', e?.name, e?.message, '— grant "window management" for this site to place notes on a 2nd screen')
- } finally {
- window.setTimeout(() => { openingSpeaker = false }, 500)
- }
+ if (other) {
+ // Notes are on the second display. A popup on ANOTHER screen shouldn't
+ // drop this screen's fullscreen; if it did, the presenter can press F
+ // (the S activation is already spent on window.open, so we can't silently
+ // re-enter here). Nothing to do — the good path.
+ console.info('[bento-speaker] notes on 2nd screen; slides', document.fullscreenElement ? 'still fullscreen' : '→ press F for fullscreen')
+ } else if (wasFullscreen) {
+ // No second-screen placement (permission not granted / single screen) —
+ // the notes would sit hidden behind the fullscreen slides. Drop fullscreen
+ // so they're visible, and surface the one-click grant button.
+ console.info('[bento-speaker] no 2nd screen — revealing notes; offering the grant button')
+ document.exitFullscreen?.().catch(() => {})
+ showGrantButton()
+ }
+ window.setTimeout(() => { openingSpeaker = false }, 500)
}
// Real fullscreen (F toggles; Present enters it by default). The overlay
@@ -317,10 +320,10 @@ export function startPresentation(
}
document.addEventListener('fullscreenchange', onFsChange)
if (opts.fullscreen !== false) enterFullscreen()
- // Fetch the screen layout now (prompts for the Window Management permission
- // once, at present-start) so pressing S can open the notes straight onto a
- // second display without an async round-trip.
- primeScreens()
+ // Prepare second-screen support: cache the layout if the permission is already
+ // granted, otherwise show a one-click grant button (the S keypress can't prompt
+ // for it — its activation is spent on window.open/fullscreen).
+ void setupSecondScreen()
const exit = () => {
if (exited) return
diff --git a/slides/src/styles.css b/slides/src/styles.css
index 2e83e1b5..0a1a2eff 100644
--- a/slides/src/styles.css
+++ b/slides/src/styles.css
@@ -561,6 +561,39 @@ html, body {
--r-overlay-element-fg-color: 0, 0, 0;
}
.bento-present-overlay .reveal .slides section { padding: 0; }
+/* dual-screen: one-click permission grant + transient toast */
+.bento-present-grant {
+ position: fixed;
+ left: 50%;
+ bottom: 28px;
+ transform: translateX(-50%);
+ z-index: 100000;
+ border: 0;
+ border-radius: 999px;
+ padding: 11px 20px;
+ font: 600 14px/1 system-ui, sans-serif;
+ color: #0d1b2e;
+ background: #f2f0ea;
+ box-shadow: 0 6px 24px rgb(0 0 0 / 0.4);
+ cursor: pointer;
+ opacity: 0.94;
+}
+.bento-present-grant:hover { opacity: 1; }
+.bento-present-toast {
+ position: fixed;
+ left: 50%;
+ bottom: 28px;
+ transform: translateX(-50%);
+ z-index: 100000;
+ padding: 10px 18px;
+ border-radius: 999px;
+ font: 500 13px/1.3 system-ui, sans-serif;
+ color: #f2f0ea;
+ background: rgb(18 26 40 / 0.92);
+ box-shadow: 0 6px 24px rgb(0 0 0 / 0.4);
+ max-width: 80vw;
+ text-align: center;
+}
.bento-present-overlay .bento-el[data-link] { cursor: pointer; }
.bento-present-overlay .bento-el[data-link]:hover {
outline: 2.5px solid var(--bento-accent, #f7a600);