Bento, the office suite that fits in a file
TypeScript mit-licenseofficeoffice-365office-suiteoffice-toolsoffice365open-sourcepowerpointself-hostedsingle-page-appslidesslideshareslideshowslideshow-galleryslideshow-makerslideshows
webext: an icon, and a surface that says whether the next save will land (#220)
nyblnet71546f5b8209
diff --git a/tray/webext/README.md b/tray/webext/README.mdindex 0f7bcf4a..64023c14 100644--- a/tray/webext/README.md+++ b/tray/webext/README.md@@ -99,8 +99,13 @@ you choose*, so they fall through to the native picker untouched.| `src/page-bridge.js` | MAIN | overrides `showSaveFilePicker`; decides in-place vs native || `src/relay.js` | ISOLATED | pure relay, no logic — the two worlds cannot reach each other || `src/background.js` | service worker | holds the grant; matches the file; writes |+| `src/status.js` | shared | the two preconditions, read by both surfaces below |+| `src/popup.html/js` | toolbar | says whether a save will land, before one is attempted || `src/options.html/js` | extension page | where the folder is granted (needs a gesture) |+The popup and the options page read the same `status.js`, so they cannot tell+the user different stories about whether the next ⌘S will prompt.+Both content-script halves are required: an isolated world can talk to theextension but not touch page globals; a MAIN world can define`showSaveFilePicker` but has no extension APIs.diff --git a/tray/webext/icons/icon-128.png b/tray/webext/icons/icon-128.pngnew file mode 100644index 00000000..392830cfBinary files /dev/null and b/tray/webext/icons/icon-128.png differdiff --git a/tray/webext/icons/icon-16.png b/tray/webext/icons/icon-16.pngnew file mode 100644index 00000000..31df8ac4Binary files /dev/null and b/tray/webext/icons/icon-16.png differdiff --git a/tray/webext/icons/icon-32.png b/tray/webext/icons/icon-32.pngnew file mode 100644index 00000000..94acf924Binary files /dev/null and b/tray/webext/icons/icon-32.png differdiff --git a/tray/webext/icons/icon-48.png b/tray/webext/icons/icon-48.pngnew file mode 100644index 00000000..97a04dc7Binary files /dev/null and b/tray/webext/icons/icon-48.png differdiff --git a/tray/webext/manifest.json b/tray/webext/manifest.jsonindex 6c830a1d..d93ebae1 100644--- a/tray/webext/manifest.json+++ b/tray/webext/manifest.json@@ -33,5 +33,21 @@"world": "ISOLATED","run_at": "document_start"}- ]+ ],+ "icons": {+ "16": "icons/icon-16.png",+ "32": "icons/icon-32.png",+ "48": "icons/icon-48.png",+ "128": "icons/icon-128.png"+ },+ "action": {+ "default_title": "Bento Tray",+ "default_popup": "src/popup.html",+ "default_icon": {+ "16": "icons/icon-16.png",+ "32": "icons/icon-32.png",+ "48": "icons/icon-48.png",+ "128": "icons/icon-128.png"+ }+ }}diff --git a/tray/webext/src/options.html b/tray/webext/src/options.htmlindex 7bfcc84c..bc074611 100644--- a/tray/webext/src/options.html+++ b/tray/webext/src/options.html@@ -7,9 +7,12 @@.sub { color: #586a80; margin-top: 0; }button { font: inherit; padding: .5rem 1rem; border: 1px solid #c8d0dc; border-radius: 8px; background: #fff; cursor: pointer; }button:hover { background: #f5f7fa; }- #state { background: #f5f7fa; border-radius: 8px; padding: .8rem 1rem; margin-top: 1rem; font: 13px/1.5 ui-monospace, monospace; white-space: pre-wrap; }+ #state { background: #f5f7fa; border-radius: 8px; padding: .3rem 1rem; margin-top: 1rem; }+ #state p { margin: .7rem 0; }+ .ok { color: #1d6b39 } .bad { color: #a3322a }+ code { background: #e7ebf0; padding: 1px 5px; border-radius: 4px; font-size: 12.5px }</style>-<h1>Bento Tray</h1>+<h1><img src="../icons/icon-48.png" alt="" width="22" height="22" style="vertical-align:-4px;border-radius:5px"> Bento Tray</h1><p class="sub">Grant the folder your decks live in, once. After that, ⌘S on a deck you openedby double-clicking writes straight back to the file — no destination prompt.diff --git a/tray/webext/src/options.js b/tray/webext/src/options.jsindex 5552c219..a10b683c 100644--- a/tray/webext/src/options.js+++ b/tray/webext/src/options.js@@ -4,40 +4,53 @@// Granting happens here and nowhere else: `showDirectoryPicker` needs a user// gesture, and a save is the wrong moment to discover there isn't one. The// service worker only ever reads the grant it finds.+//+// The popup and this page read the SAME status module, so they cannot tell the+// user different stories about whether a save will land.-const DB = 'bento-tray'-const STORE = 'grant'-const open = () => new Promise((res, rej) => {- const r = indexedDB.open(DB, 1)- r.onupgradeneeded = () => r.result.createObjectStore(STORE)- r.onsuccess = () => res(r.result); r.onerror = () => rej(r.error)-})-const put = async (v) => { const d = await open(); return new Promise((res, rej) => {- const t = d.transaction(STORE, 'readwrite'); t.objectStore(STORE).put(v, 'dir')- t.oncomplete = res; t.onerror = () => rej(t.error) }) }-const get = async () => { const d = await open(); return new Promise((res, rej) => {- const t = d.transaction(STORE, 'readonly'); const q = t.objectStore(STORE).get('dir')- q.onsuccess = () => res(q.result ?? null); q.onerror = () => rej(q.error) }) }+import { getGrant, putGrant, status } from './status.js'const el = document.getElementById('state')-const show = (s) => { el.textContent = s }+const esc = (s) => String(s).replace(/[&<>]/g, (c) => ({ '&': '&', '<': '<', '>': '>' }[c]))async function report() {- const dir = await get()- if (!dir) return show('No folder granted yet.')- const perm = await dir.queryPermission({ mode: 'readwrite' })- show(`folder: ${dir.name}\npermission: ${perm}` +- (perm === 'granted' ? '\n\nDecks in this folder save in place.'- : '\n\nNeeds renewing — choose the folder again.'))+ const s = await status()+ const lines = []++ if (s.files === false) {+ lines.push('<b class="bad">Local file access is off.</b> Open <code>chrome://extensions</code>, ' ++ 'find <b>Bento Tray</b>, and turn on <b>Allow access to file URLs</b>. ' ++ 'No extension can enable this for you, and nothing works until it is on.')+ } else if (s.files === null) {+ lines.push('<b>Local file access: unknown.</b> This browser will not report it. ' ++ 'If saves still prompt for a destination, check <b>Allow access to file URLs</b> ' ++ 'on this extension in <code>chrome://extensions</code>.')+ } else {+ lines.push('<b class="ok">Local file access is on.</b>')+ }++ if (!s.folder) {+ lines.push('<b>No folder granted yet.</b> Choose the folder your decks live in.')+ } else if (s.permission === 'granted') {+ lines.push(`<b class="ok">Folder: ${esc(s.folder)}</b> — decks in here save in place, with no dialog.`)+ } else {+ lines.push(`<b class="bad">Folder: ${esc(s.folder)} — needs renewing.</b> ` ++ 'The grant lapses whenever the extension restarts. Choose it again to restore it.')+ }++ el.innerHTML = lines.map((l) => `<p>${l}</p>`).join('')}document.getElementById('pick').onclick = async () => {try {const dir = await window.showDirectoryPicker({ mode: 'readwrite' })await dir.requestPermission({ mode: 'readwrite' })- await put(dir)+ await putGrant(dir)await report()- } catch (e) { show(`${e.name}: ${e.message}`) }+ } catch (e) {+ el.innerHTML = `<p><b class="bad">${esc(e.name)}</b>: ${esc(e.message)}</p>`+ }}document.getElementById('check').onclick = reportvoid report()+void getGrant // referenced so the import is obviously intentionaldiff --git a/tray/webext/src/popup.html b/tray/webext/src/popup.htmlnew file mode 100644index 00000000..475f7cf0--- /dev/null+++ b/tray/webext/src/popup.html@@ -0,0 +1,25 @@+<!doctype html>+<meta charset="utf-8">+<title>Bento Tray</title>+<style>+ body { font: 13.5px/1.5 -apple-system, system-ui, sans-serif; color: #1e2a3a; margin: 0; width: 290px; }+ header { display: flex; align-items: center; gap: 8px; padding: 12px 14px 8px; }+ header img { width: 20px; height: 20px; border-radius: 5px; }+ header b { font-size: 14px; }+ .rows { padding: 0 14px 4px; }+ .row { display: flex; gap: 8px; align-items: flex-start; padding: 7px 0; border-top: 1px solid #eceff3; }+ .row:first-child { border-top: 0; }+ .dot { width: 8px; height: 8px; border-radius: 50%; margin-top: 5px; flex: none; }+ .ok { background: #2e9e5b } .bad { background: #c2453b } .meh { background: #c9a227 }+ .t { flex: 1 }+ .t b { display: block; font-weight: 600 }+ .t span { color: #6b7a8d; font-size: 12.5px }+ footer { padding: 10px 14px 13px; }+ button { font: inherit; width: 100%; padding: 7px 10px; border: 1px solid #c8d0dc; border-radius: 8px; background: #fff; cursor: pointer; }+ button:hover { background: #f5f7fa }+ code { background: #eef1f5; padding: 1px 4px; border-radius: 4px; font-size: 12px }+</style>+<header><img src="../icons/icon-48.png" alt=""><b>Bento Tray</b></header>+<div class="rows" id="rows"></div>+<footer><button id="open">Settings…</button></footer>+<script type="module" src="popup.js"></script>diff --git a/tray/webext/src/popup.js b/tray/webext/src/popup.jsnew file mode 100644index 00000000..110ca277--- /dev/null+++ b/tray/webext/src/popup.js@@ -0,0 +1,37 @@+// SPDX-License-Identifier: MIT+// Copyright (c) 2026 The Bento authors+//+// The toolbar popup: says whether a save will land in place, BEFORE one is+// attempted. Both preconditions fail silently otherwise — a lapsed folder grant+// and a file-URL permission nothing can request — and a user who cannot see+// them reads "the extension is broken".++import { status } from './status.js'++const esc = (s) => String(s).replace(/[&<>]/g, (c) => ({ '&': '&', '<': '<', '>': '>' }[c]))++const row = (state, title, detail) =>+ `<div class="row"><div class="dot ${state}"></div><div class="t"><b>${esc(title)}</b><span>${detail}</span></div></div>`++const s = await status()++const files = s.files === true+ ? row('ok', 'Local files', 'This extension may read pages opened from disk.')+ : s.files === false+ ? row('bad', 'Local files — off',+ 'Turn on <b>Allow access to file URLs</b> on this extension’s card in <code>chrome://extensions</code>. Nothing works without it, and no extension can turn it on for you.')+ : row('meh', 'Local files — unknown',+ 'This browser will not say. If saves still prompt, check <b>Allow access to file URLs</b>.')++const folder = s.permission === 'granted'+ ? row('ok', `Folder: ${esc(s.folder)}`, 'Decks in here save in place, with no dialog.')+ : s.folder+ ? row('bad', `Folder: ${esc(s.folder)} — needs renewing`,+ 'The grant lapses whenever the extension restarts. One click in Settings restores it.')+ : row('meh', 'No folder yet', 'Choose the folder your decks live in, once.')++document.getElementById('rows').innerHTML = files + folder+document.getElementById('open').addEventListener('click', () => {+ chrome.runtime.openOptionsPage()+ window.close()+})diff --git a/tray/webext/src/status.js b/tray/webext/src/status.jsnew file mode 100644index 00000000..579edd11--- /dev/null+++ b/tray/webext/src/status.js@@ -0,0 +1,75 @@+// SPDX-License-Identifier: MIT+// Copyright (c) 2026 The Bento authors+//+// What the extension can and cannot do right now, in one place.+//+// Two things have to be true before a deck saves in place, and BOTH fail+// silently by nature: a folder grant that lapses whenever the service worker+// restarts, and a file-URL permission that no manifest can request. Neither is+// visible until a save is attempted, which is the worst possible moment to+// discover them — so the popup and the options page read this and say so first.++const DB = 'bento-tray'+const STORE = 'grant'++const open = () => new Promise((res, rej) => {+ const r = indexedDB.open(DB, 1)+ r.onupgradeneeded = () => r.result.createObjectStore(STORE)+ r.onsuccess = () => res(r.result); r.onerror = () => rej(r.error)+})++export const getGrant = async () => {+ const d = await open()+ return new Promise((res, rej) => {+ const t = d.transaction(STORE, 'readonly')+ const q = t.objectStore(STORE).get('dir')+ q.onsuccess = () => res(q.result ?? null); q.onerror = () => rej(q.error)+ })+}++export const putGrant = async (v) => {+ const d = await open()+ return new Promise((res, rej) => {+ const t = d.transaction(STORE, 'readwrite')+ t.objectStore(STORE).put(v, 'dir')+ t.oncomplete = res; t.onerror = () => rej(t.error)+ })+}++/**+ * Is "Allow access to file URLs" enabled?+ *+ * No manifest permission grants it and nothing can prompt for it — the user+ * must set it by hand, per extension, and it stays off after a store install+ * too. It IS readable, which is the difference between a guided step and a+ * mystery. Returns null where the API is unavailable rather than guessing:+ * claiming it is off when it is on would send people to fix a working setting.+ */+export async function fileAccess() {+ try {+ const api = chrome.extension?.isAllowedFileSchemeAccess+ if (!api) return null+ const r = api.call(chrome.extension)+ if (r && typeof r.then === 'function') return await r+ return await new Promise((res) => chrome.extension.isAllowedFileSchemeAccess(res))+ } catch {+ return null+ }+}++/** Everything the UI needs: {files, folder, permission, ready}. */+export async function status() {+ const files = await fileAccess()+ let folder = null+ let permission = 'none'+ try {+ const dir = await getGrant()+ if (dir) {+ folder = dir.name+ permission = await dir.queryPermission({ mode: 'readwrite' })+ }+ } catch {+ permission = 'unreadable'+ }+ return { files, folder, permission, ready: files !== false && permission === 'granted' }+}