Skip to content

armgit / bento

Public Imported from GitHub
0

Bento, the office suite that fits in a file

tray: the hosts behave the same, and the mark has one source

nyblnet8a9f04a1b1fd
diff --git a/docs/DECISIONS.md b/docs/DECISIONS.md
index 4094e03b..90731f33 100644
--- a/docs/DECISIONS.md
+++ b/docs/DECISIONS.md
@@ -60,6 +60,32 @@ rejected:
`onBackPressed` being called at all on API 33+, so an override alone compiles,
runs, and silently does nothing.
+**A host must implement the page-dialog delegate, and BOTH lacked it.** Building
+the Android host surfaced a bug that had been shipping in `tray/ios` too. Neither
+`WKWebView` nor Android's `WebView` shows `alert`/`confirm`/`prompt` on its own,
+and without the delegate they do not merely skip them — they answer wrongly and
+say nothing: `alert()` is a no-op and **`confirm()` returns `false`**. Every one
+of the runtime's seven uses is shaped `if (!confirm(…)) return`, so delete a
+slide, remove a collaborator, reset access, replace all slides and embed an
+oversized file all silently did nothing when tapped. Fixed on both
+(`WKUIDelegate`, `TrayChromeClient`) and verified on both: iOS through
+"Start from scratch…", Android over CDP (`true` on OK, `false` on Cancel).
+Android additionally needs `onShowFileChooser` or `<input type="file">` cannot
+open at all, which is how images, media and fonts get into a deck — restored
+from #87's `native/android`, which had it.
+
+**Parity is written down, not assumed.** `tray/README.md` § Android carries a
+row-per-behaviour table of iOS against Android, marking each as the same, a
+platform-forced difference, or a gap. The one gap is the status bar (iOS hides it
+on iPad; Android does not on tablets), left undone because it cannot be tested
+without a tablet target.
+
+**The launcher icon is GENERATED from the shared mark**
+(`tray/assets/make-icons.mjs`, with `--check` for CI). Android vector drawables
+have no `<rect>`, so every rounded rectangle has to be re-expressed as path data
+— four opaque `M…A…V…Z` strings nobody would ever diff against the SVG, so a
+change to the mark would land on iOS and silently miss Android.
+
**`tray/bridge.js` is now SHARED** by both native hosts (was
`tray/ios/Resources/bridge.js`). The transport is ~15 lines at the top; the rest
is `FileSystemWritableFileStream` semantics whose comments record the bug that
diff --git a/tray/README.md b/tray/README.md
index 51fa0e22..e78c3b4f 100644
--- a/tray/README.md
+++ b/tray/README.md
@@ -448,6 +448,41 @@ measurement sent it the other way. The architecture changed — a host that
bundles a deck and updates itself over the air is the thing tray exists not to
be — but the question it asked was the right one, and it was asked first.
+### Parity with the iOS host
+
+The two hosts are meant to behave identically from inside the document. Where
+they cannot, it is because the platform forces it — and that is written down
+here rather than discovered later.
+
+| behaviour | `tray/ios` | `tray/android` | |
+|---|---|---|---|
+| FSA polyfill | `tray/bridge.js` | `tray/bridge.js` | **one shared file** |
+| per-document origin | `bento-tray://<sha24>` custom scheme | `https://<sha24>.bento-tray.invalid`, intercepted | same |
+| document served from memory, never parsed | ✓ | ✓ | same |
+| bridge injected at document start | `WKUserScript(.atDocumentStart)` | `addDocumentStartJavaScript` | same |
+| bridge reachable only from the document | `forMainFrameOnly` | `allowedOriginRules` + `isMainFrame` | same |
+| first `begin` = open document, later = export | ✓ | ✓ | same |
+| an export can never address the open file | `exportName` + `targetsOpenDocument` | identical logic | same |
+| page-supplied filenames sanitised | `safeFileName` | `safeFileName` | same |
+| in-place write | `UIDocument.save(.forOverwriting)` | `openOutputStream(uri, "wt")` | same |
+| export destination chosen by the author | `UIDocumentPickerViewController` | `ACTION_CREATE_DOCUMENT` | same |
+| `alert` / `confirm` / `prompt` | `WKUIDelegate` | `WebChromeClient` | same |
+| `<input type="file">` | native | `onShowFileChooser` | same |
+| element fullscreen | declined | declined | same |
+| safe-area insets, natively + `--tray-safe-*` | ✓ | ✓ | same |
+| new document from the bundled seed | ✓ | ✓ | same |
+| way back out | floating exit, fades when idle | system back gesture | platform-forced |
+| root screen | `UIDocumentBrowserViewController` | own recents list over SAF | platform-forced |
+| `<a download>` lands | app's Documents folder, silently | wherever the author picks | platform-forced |
+| write access to an opened document | always | **may be read-only** | platform-forced |
+| status bar while editing | hidden on iPad | always shown | **known gap** |
+
+The last row is the only real gap. iOS hides the status bar on iPad because
+nothing else keeps the page off the whole screen there; the Android equivalent
+would be to hide it on tablets (`smallestScreenWidthDp >= 600`). Not done,
+because it cannot be tested without a tablet target, and shipping an untested
+behaviour is worse than naming an untested one.
+
### What is genuinely different
Three things, and none of them are stylistic.
@@ -524,15 +559,23 @@ The starter shell and `bridge.js` are staged into assets by the build
587KB binary in git would churn on every release, and the seed ages harmlessly
because a new deck self-updates through the normal signed channel.
-The launcher icon is generated from the same mark as iOS. The tray is **56 units
-of the 108 canvas, not the full 72 safe zone** — at 72 it exactly filled the
-visible area, so every launcher mask cut its corners off and the navy frame that
-makes the mark read was never drawn. Regenerate the path data with:
+The launcher icon is **generated from the same mark as iOS**, not redrawn.
+`tray/assets/tray-icon.svg` is the source for both; Android needs the rounded
+rectangles re-expressed as path data because vector drawables have no `<rect>`,
+and doing that by hand produces four opaque `M…A…V…Z` strings nobody will ever
+diff against the SVG — so a change to the mark would land on iOS and silently
+miss Android.
```sh
-node -e 'const f=n=>+n.toFixed(2),rr=(x,y,w,h,r)=>`M${f(x+r)},${f(y)} H${f(x+w-r)} A${f(r)},${f(r)} 0 0 1 ${f(x+w)},${f(y+r)} V${f(y+h-r)} A${f(r)},${f(r)} 0 0 1 ${f(x+w-r)},${f(y+h)} H${f(x+r)} A${f(r)},${f(r)} 0 0 1 ${f(x)},${f(y+h-r)} V${f(y+r)} A${f(r)},${f(r)} 0 0 1 ${f(x+r)},${f(y)} Z`,S=56/23.6,O=26,m=v=>O+(v-4.2)*S;console.log(rr(O,O,56,56,4.8*S));console.log(rr(m(6.8),m(6.8),5.855*S,18.4*S,2.091*S));console.log(rr(m(14.327),m(6.8),10.873*S,8.364*S,2.091*S));console.log(rr(m(14.327),m(16.836),10.873*S,8.364*S,2.091*S))'
+node tray/assets/make-icons.mjs # regenerate the Android drawables
+node tray/assets/make-icons.mjs --check # fail if they drifted (for CI)
```
+The tray is drawn at **56 units of the 108 canvas, not the full 72 safe zone**.
+At 72 it exactly filled the visible area, so every launcher mask cut its corners
+off and the navy frame that makes the mark read was never drawn at all.
+
+
### State: the document cycle works, on an emulator only
Verified end to end on a Pixel 7 / Android 16 emulator, driven through the real
diff --git a/tray/android/app/src/main/java/page/bento/tray/EditorActivity.kt b/tray/android/app/src/main/java/page/bento/tray/EditorActivity.kt
index 6ddf36a0..6438bf85 100644
--- a/tray/android/app/src/main/java/page/bento/tray/EditorActivity.kt
+++ b/tray/android/app/src/main/java/page/bento/tray/EditorActivity.kt
@@ -6,6 +6,7 @@ package page.bento.tray
import android.app.Activity
import android.app.AlertDialog
import android.content.Intent
+import android.content.pm.ApplicationInfo
import android.content.pm.PackageManager
import android.net.Uri
import android.os.Build
@@ -16,8 +17,13 @@ import android.util.Log
import android.view.View
import android.view.ViewGroup
import android.view.WindowInsets
+import android.widget.EditText
import android.widget.FrameLayout
import android.window.OnBackInvokedDispatcher
+import android.webkit.JsPromptResult
+import android.webkit.JsResult
+import android.webkit.ValueCallback
+import android.webkit.WebChromeClient
import android.webkit.WebResourceRequest
import android.webkit.WebResourceResponse
import android.webkit.WebView
@@ -65,6 +71,7 @@ class EditorActivity : Activity() {
const val EXTRA_URI = "page.bento.tray.URI"
private const val TAG = "BentoTray"
private const val REQ_EXPORT = 1
+ private const val REQ_FILE_CHOOSER = 2
/** Reduce a page-supplied filename to ONE plain component, or refuse it.
*
@@ -171,6 +178,15 @@ class EditorActivity : Activity() {
}
private fun startWebView() {
+ // Debug builds only: makes the document inspectable from
+ // chrome://inspect, which is the only way to see what a hosted page is
+ // actually doing. Gated on the manifest flag rather than BuildConfig so a
+ // release build cannot expose a user's document no matter how it was
+ // assembled.
+ if (applicationInfo.flags and ApplicationInfo.FLAG_DEBUGGABLE != 0) {
+ WebView.setWebContentsDebuggingEnabled(true)
+ }
+
web = WebView(this)
// The web view lives in a container whose PADDING carries the system
@@ -256,6 +272,8 @@ class EditorActivity : Activity() {
}
}
+ web.webChromeClient = TrayChromeClient()
+
installBridge()
// `<a download>` and blob: saves — the older, commoner idiom that is not
@@ -310,6 +328,114 @@ class EditorActivity : Activity() {
WebViewCompat.addDocumentStartJavaScript(web, src, rules)
}
+ /**
+ * The things a WebView does NOT do on its own, and fails at silently.
+ *
+ * Without a `WebChromeClient` a WebView does not merely skip these — it
+ * answers them wrongly and says nothing:
+ *
+ * - `alert()` is a no-op, so a warning the document meant to show is
+ * swallowed.
+ * - **`confirm()` returns `false`**, immediately, with no dialog. Every one
+ * of the runtime's seven uses is shaped `if (!confirm(…)) return`, so the
+ * whole feature behind it — delete this slide, remove a collaborator,
+ * reset access, embed a large file — just does nothing when tapped. There
+ * is no error and nothing in the log.
+ * - **`<input type="file">` cannot open at all**, which is how images,
+ * video, audio and fonts get into a deck.
+ *
+ * `tray/ios` had the same hole (`WKUIDelegate` is required there for the
+ * dialogs; WKWebView does handle file inputs itself) and was fixed in the
+ * same change.
+ *
+ * NOTE the omission: `onShowCustomView` is deliberately NOT implemented, so
+ * element fullscreen is declined — the same answer `tray/ios` gives, for the
+ * same reasons. A page refused fullscreen falls back to filling its view,
+ * which is the well-trodden mobile path, and the host has already handed it
+ * the whole screen anyway.
+ */
+ private inner class TrayChromeClient : WebChromeClient() {
+
+ override fun onJsAlert(
+ view: WebView?, url: String?, message: String?, result: JsResult
+ ): Boolean {
+ AlertDialog.Builder(this@EditorActivity)
+ .setMessage(message ?: "")
+ .setCancelable(false)
+ .setPositiveButton(android.R.string.ok) { _, _ -> result.confirm() }
+ .setOnDismissListener { result.cancel() }
+ .show()
+ return true
+ }
+
+ override fun onJsConfirm(
+ view: WebView?, url: String?, message: String?, result: JsResult
+ ): Boolean {
+ AlertDialog.Builder(this@EditorActivity)
+ .setMessage(message ?: "")
+ .setCancelable(false)
+ .setPositiveButton(android.R.string.ok) { _, _ -> result.confirm() }
+ .setNegativeButton(android.R.string.cancel) { _, _ -> result.cancel() }
+ .setOnDismissListener { result.cancel() }
+ .show()
+ return true
+ }
+
+ override fun onJsPrompt(
+ view: WebView?, url: String?, message: String?, defaultValue: String?,
+ result: JsPromptResult
+ ): Boolean {
+ val field = EditText(this@EditorActivity).apply { setText(defaultValue ?: "") }
+ AlertDialog.Builder(this@EditorActivity)
+ .setMessage(message ?: "")
+ .setView(field)
+ .setCancelable(false)
+ .setPositiveButton(android.R.string.ok) { _, _ -> result.confirm(field.text.toString()) }
+ .setNegativeButton(android.R.string.cancel) { _, _ -> result.cancel() }
+ .setOnDismissListener { result.cancel() }
+ .show()
+ return true
+ }
+
+ /** `beforeunload` — the document is served from memory and never
+ * navigates away, so this can only fire on a reload. Confirm it rather
+ * than leaving the page blocked forever waiting for an answer. */
+ override fun onJsBeforeUnload(
+ view: WebView?, url: String?, message: String?, result: JsResult
+ ): Boolean {
+ result.confirm()
+ return true
+ }
+
+ /**
+ * `<input type="file">`. Restored from #87's `native/android`, which had
+ * this and was right to.
+ *
+ * The callback MUST be answered exactly once. Dropping it leaves the
+ * page's file input permanently dead — not for that attempt, for the rest
+ * of the session — so a superseded chooser is cancelled here, and
+ * [onActivityResult] answers every outcome including a cancel.
+ */
+ override fun onShowFileChooser(
+ view: WebView, callback: ValueCallback<Array<Uri>>,
+ params: FileChooserParams
+ ): Boolean {
+ pendingFileChooser?.onReceiveValue(null)
+ pendingFileChooser = callback
+ return try {
+ startActivityForResult(params.createIntent(), REQ_FILE_CHOOSER)
+ true
+ } catch (e: Exception) {
+ Log.w(TAG, "no file chooser available", e)
+ pendingFileChooser = null
+ callback.onReceiveValue(null)
+ false
+ }
+ }
+ }
+
+ private var pendingFileChooser: ValueCallback<Array<Uri>>? = null
+
/**
* Hand the real insets to the page as CSS custom properties.
*
@@ -466,6 +592,18 @@ class EditorActivity : Activity() {
}
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
+ if (requestCode == REQ_FILE_CHOOSER) {
+ val cb = pendingFileChooser
+ pendingFileChooser = null
+ // Answered on EVERY path, cancel included: an unanswered callback
+ // leaves the page's file input dead for the rest of the session.
+ cb?.onReceiveValue(
+ if (resultCode == RESULT_OK)
+ WebChromeClient.FileChooserParams.parseResult(resultCode, data)
+ else null
+ )
+ return
+ }
if (requestCode != REQ_EXPORT) return super.onActivityResult(requestCode, resultCode, data)
val p = pendingExport
pendingExport = null
@@ -597,6 +735,11 @@ class EditorActivity : Activity() {
}
override fun onDestroy() {
+ // Never strand a file-chooser callback: the WebView may outlive this
+ // activity briefly, and an unanswered one is a leak with a visible
+ // symptom.
+ pendingFileChooser?.onReceiveValue(null)
+ pendingFileChooser = null
// A WebView outlives its activity if anything still references it, and
// it holds the whole document. Detach and destroy explicitly.
if (this::web.isInitialized) {
diff --git a/tray/android/app/src/main/res/drawable/ic_launcher_foreground.xml b/tray/android/app/src/main/res/drawable/ic_launcher_foreground.xml
index 63aa5a3a..5b158c52 100644
--- a/tray/android/app/src/main/res/drawable/ic_launcher_foreground.xml
+++ b/tray/android/app/src/main/res/drawable/ic_launcher_foreground.xml
@@ -1,21 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
- The bento/tray mark, from tray/assets/tray-icon.svg.
+ GENERATED from tray/assets/tray-icon.svg by tray/assets/make-icons.mjs.
+ Do not edit: run `node tray/assets/make-icons.mjs` instead.
- The navy frame is the BACKGROUND layer and the cream tray is the foreground.
- That split is what an adaptive icon wants — the system parallaxes the two
- layers against each other, and a frame drawn into the foreground would slide
- away from its own edge.
-
- The tray is 56 wide on the 108 canvas, not the full 72 safe zone. At 72 it
- exactly filled the visible area, so every launcher mask cut its corners off and
- the navy frame — the thing that makes the mark read as bento — was never drawn
- at all. At 56 the frame survives a circle mask, which is the tightest one in
- use, and the tray still sits inside the 66dp guaranteed-visible circle apart
- from its own rounded corners.
-
- Rounded rects are paths because Android vector drawables have no <rect>.
- Regenerate rather than editing the numbers — the snippet is in tray/README.md.
+ The navy frame is the BACKGROUND layer (@color/tray_navy) and the cream tray is
+ the foreground. That split is what an adaptive icon wants: the system
+ parallaxes the two against each other, and a frame drawn into the foreground
+ would slide away from its own edge.
-->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="108dp"
diff --git a/tray/android/app/src/main/res/drawable/ic_launcher_monochrome.xml b/tray/android/app/src/main/res/drawable/ic_launcher_monochrome.xml
index f2708d72..430998db 100644
--- a/tray/android/app/src/main/res/drawable/ic_launcher_monochrome.xml
+++ b/tray/android/app/src/main/res/drawable/ic_launcher_monochrome.xml
@@ -1,11 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
- The themed-icon layer (Android 13+): one shape, tinted by the system to match
- the user's wallpaper.
+ GENERATED from tray/assets/tray-icon.svg by tray/assets/make-icons.mjs.
+ Do not edit: run `node tray/assets/make-icons.mjs` instead.
- Colour cannot carry the mark here, so geometry has to. The three compartments
- become HOLES in the tray via evenOdd fill — the same rhythm as the full-colour
- icon (left tall, right split in two), legible as a silhouette.
+ The themed-icon layer (Android 13+). Colour cannot carry the mark when the
+ system tints it, so the compartments are knocked out of the tray with evenOdd
+ fill — the same rhythm as the full-colour icon, legible as a silhouette.
-->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="108dp"
diff --git a/tray/assets/make-icons.mjs b/tray/assets/make-icons.mjs
new file mode 100644
index 00000000..7d1f85de
--- /dev/null
+++ b/tray/assets/make-icons.mjs
@@ -0,0 +1,148 @@
+#!/usr/bin/env node
+// SPDX-License-Identifier: MIT
+// Copyright (c) 2026 The Bento authors
+//
+// One mark, two platforms. `tray-icon.svg` is the SOURCE; this generates the
+// Android launcher vectors from it so the geometry cannot drift.
+//
+// node tray/assets/make-icons.mjs # write the Android drawables
+// node tray/assets/make-icons.mjs --check # fail if they are out of date (CI)
+//
+// iOS consumes the same SVG directly, as a 1024x1024 PNG export — see the
+// comment at the top of tray-icon.svg for the export command. It is not
+// generated here because it needs a browser to rasterise, and this script has no
+// dependencies on purpose.
+//
+// WHY GENERATE AT ALL: Android vector drawables have no <rect>, so every rounded
+// rectangle in the mark has to be re-expressed as path data. Written by hand
+// that is four opaque `M…A…V…Z` strings that nobody will ever diff against the
+// SVG — so a change to the mark would land on iOS and silently miss Android.
+
+import { readFileSync, writeFileSync } from 'node:fs'
+import { dirname, join } from 'node:path'
+import { fileURLToPath } from 'node:url'
+
+const here = dirname(fileURLToPath(import.meta.url))
+const ANDROID_RES = join(here, '../android/app/src/main/res/drawable')
+
+// The adaptive-icon canvas is 108 units with a 72-unit safe zone. The cream tray
+// is drawn at 56, NOT 72: at 72 it exactly filled the visible area, so every
+// launcher mask cut its corners off and the navy frame — the thing that makes
+// the mark read as Bento — was never drawn at all. 56 leaves the frame visible
+// under a circle mask, which is the tightest one in use.
+const CANVAS = 108
+const TRAY = 56
+
+const f = (n) => +n.toFixed(2)
+const roundRect = (x, y, w, h, r) =>
+ `M${f(x + r)},${f(y)} H${f(x + w - r)} A${f(r)},${f(r)} 0 0 1 ${f(x + w)},${f(y + r)} ` +
+ `V${f(y + h - r)} A${f(r)},${f(r)} 0 0 1 ${f(x + w - r)},${f(y + h)} ` +
+ `H${f(x + r)} A${f(r)},${f(r)} 0 0 1 ${f(x)},${f(y + h - r)} ` +
+ `V${f(y + r)} A${f(r)},${f(r)} 0 0 1 ${f(x + r)},${f(y)} Z`
+
+/** Pull the <rect>s out of the source SVG, in document order. */
+function readMark() {
+ const svg = readFileSync(join(here, 'tray-icon.svg'), 'utf8')
+ const rects = [...svg.matchAll(/<rect\b([^>]*)\/>/g)].map((m) => {
+ const attr = (name) => {
+ const hit = m[1].match(new RegExp(`\\b${name}="([^"]*)"`))
+ return hit ? hit[1] : null
+ }
+ return {
+ x: parseFloat(attr('x') ?? '0'), y: parseFloat(attr('y') ?? '0'),
+ w: parseFloat(attr('width')), h: parseFloat(attr('height')),
+ r: parseFloat(attr('rx') ?? '0'), fill: attr('fill'),
+ }
+ })
+ // Expected shape: a full-bleed navy ground, the cream tray, then three
+ // compartments. Asserted rather than assumed — if the mark is redrawn with a
+ // different structure this must be revisited, not silently mis-generated.
+ if (rects.length !== 5) {
+ throw new Error(`tray-icon.svg: expected 5 rects (ground, tray, 3 compartments), found ${rects.length}`)
+ }
+ const [ground, tray, ...cells] = rects
+ if (ground.w !== 32 || ground.h !== 32) {
+ throw new Error('tray-icon.svg: first rect should be the full-bleed 32x32 ground')
+ }
+ return { ground, tray, cells }
+}
+
+function build() {
+ const { ground, tray, cells } = readMark()
+ // Map the SVG's 32-unit grid so the tray spans TRAY units, centred.
+ const origin = (CANVAS - TRAY) / 2
+ const scale = TRAY / tray.w
+ const map = (v, start) => origin + (v - start) * scale
+
+ const shapes = [
+ { fill: tray.fill, d: roundRect(origin, origin, TRAY, TRAY, tray.r * scale) },
+ ...cells.map((c) => ({
+ fill: c.fill,
+ d: roundRect(map(c.x, tray.x), map(c.y, tray.y), c.w * scale, c.h * scale, c.r * scale),
+ })),
+ ]
+
+ const header = (extra) => `<?xml version="1.0" encoding="utf-8"?>
+<!--
+ GENERATED from tray/assets/tray-icon.svg by tray/assets/make-icons.mjs.
+ Do not edit: run \`node tray/assets/make-icons.mjs\` instead.
+${extra}-->
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+ android:width="${CANVAS}dp"
+ android:height="${CANVAS}dp"
+ android:viewportWidth="${CANVAS}"
+ android:viewportHeight="${CANVAS}">`
+
+ const foreground = header(
+`
+ The navy frame is the BACKGROUND layer (@color/tray_navy) and the cream tray is
+ the foreground. That split is what an adaptive icon wants: the system
+ parallaxes the two against each other, and a frame drawn into the foreground
+ would slide away from its own edge.
+`) + '\n' +
+ shapes.map((s) => ` <path\n android:fillColor="${s.fill}"\n android:pathData="${s.d}" />`).join('\n') +
+ '\n</vector>\n'
+
+ // Themed icons are tinted to one colour by the system, so geometry has to
+ // carry the mark alone: the compartments become HOLES in the tray via evenOdd.
+ const monochrome = header(
+`
+ The themed-icon layer (Android 13+). Colour cannot carry the mark when the
+ system tints it, so the compartments are knocked out of the tray with evenOdd
+ fill — the same rhythm as the full-colour icon, legible as a silhouette.
+`) + `
+ <path
+ android:fillColor="#FFFFFF"
+ android:fillType="evenOdd"
+ android:pathData="${shapes.map((s) => s.d).join(' ')}" />
+</vector>
+`
+
+ return {
+ [join(ANDROID_RES, 'ic_launcher_foreground.xml')]: foreground,
+ [join(ANDROID_RES, 'ic_launcher_monochrome.xml')]: monochrome,
+ }
+}
+
+const files = build()
+const check = process.argv.includes('--check')
+let stale = 0
+
+for (const [path, content] of Object.entries(files)) {
+ const current = (() => { try { return readFileSync(path, 'utf8') } catch { return null } })()
+ if (current === content) continue
+ stale++
+ if (check) {
+ console.error(`stale: ${path.replace(/.*\/tray\//, 'tray/')}`)
+ } else {
+ writeFileSync(path, content)
+ console.log(`wrote: ${path.replace(/.*\/tray\//, 'tray/')}`)
+ }
+}
+
+if (check && stale) {
+ console.error('\nAndroid launcher drawables are out of date with tray-icon.svg.')
+ console.error('Run: node tray/assets/make-icons.mjs')
+ process.exit(1)
+}
+if (!stale) console.log('icons up to date')
diff --git a/tray/ios/EditorViewController.swift b/tray/ios/EditorViewController.swift
index 40646a99..e8ee0ed0 100644
--- a/tray/ios/EditorViewController.swift
+++ b/tray/ios/EditorViewController.swift
@@ -35,7 +35,7 @@ import CryptoKit
/// the same release as everyone else on the same day — no App Store
/// submission per release, no drift. What the app ships is file access.
final class EditorViewController: UIViewController, WKScriptMessageHandler, WKURLSchemeHandler,
- WKNavigationDelegate, WKDownloadDelegate {
+ WKNavigationDelegate, WKDownloadDelegate, WKUIDelegate {
private let document: BentoDocument
private var webView: WKWebView!
@@ -265,6 +265,9 @@ final class EditorViewController: UIViewController, WKScriptMessageHandler, WKUR
// frame is driven by viewDidLayoutSubviews, not autoresizing
webView.allowsBackForwardNavigationGestures = false
webView.navigationDelegate = self
+ // Without this, alert() does nothing and confirm() returns false — see
+ // the WKUIDelegate section below.
+ webView.uiDelegate = self
// Full bleed. WKWebView does NOT hand safe-area insets to CSS here —
// measured both ways: with `.never` the page filled the screen and
// env(safe-area-inset-*) read 0px on all four sides; with the default it
@@ -380,6 +383,57 @@ final class EditorViewController: UIViewController, WKScriptMessageHandler, WKUR
present(a, animated: true)
}
+ // MARK: - page dialogs
+ //
+ // WKWebView does not show `alert()`, `confirm()` or `prompt()` on its own.
+ // Without a WKUIDelegate it does not merely skip them — it answers wrongly
+ // and says nothing: alert() is a no-op, and **confirm() returns false**.
+ //
+ // That is not cosmetic. Every one of the runtime's seven uses is shaped
+ // `if (!confirm(…)) return`, so the feature behind each one silently did
+ // nothing when tapped: delete this slide, remove a collaborator, reset
+ // access, replace all slides, embed an oversized file. No error, nothing in
+ // the log, and the same on Android for the same reason — fixed there in the
+ // same change (`TrayChromeClient`).
+ //
+ // The panels are presented from `self` and the completion handler is called
+ // on EVERY path including dismissal, because a WebKit dialog callback that
+ // is never invoked deadlocks the page.
+
+ func webView(_ webView: WKWebView, runJavaScriptAlertPanelWithMessage message: String,
+ initiatedByFrame frame: WKFrameInfo,
+ completionHandler: @escaping () -> Void) {
+ let a = UIAlertController(title: nil, message: message, preferredStyle: .alert)
+ a.addAction(UIAlertAction(title: NSLocalizedString("OK", comment: ""),
+ style: .default) { _ in completionHandler() })
+ present(a, animated: true)
+ }
+
+ func webView(_ webView: WKWebView, runJavaScriptConfirmPanelWithMessage message: String,
+ initiatedByFrame frame: WKFrameInfo,
+ completionHandler: @escaping (Bool) -> Void) {
+ let a = UIAlertController(title: nil, message: message, preferredStyle: .alert)
+ a.addAction(UIAlertAction(title: NSLocalizedString("Cancel", comment: ""),
+ style: .cancel) { _ in completionHandler(false) })
+ a.addAction(UIAlertAction(title: NSLocalizedString("OK", comment: ""),
+ style: .default) { _ in completionHandler(true) })
+ present(a, animated: true)
+ }
+
+ func webView(_ webView: WKWebView, runJavaScriptTextInputPanelWithPrompt prompt: String,
+ defaultText: String?, initiatedByFrame frame: WKFrameInfo,
+ completionHandler: @escaping (String?) -> Void) {
+ let a = UIAlertController(title: nil, message: prompt, preferredStyle: .alert)
+ a.addTextField { $0.text = defaultText }
+ a.addAction(UIAlertAction(title: NSLocalizedString("Cancel", comment: ""),
+ style: .cancel) { _ in completionHandler(nil) })
+ a.addAction(UIAlertAction(title: NSLocalizedString("OK", comment: ""),
+ style: .default) { [weak a] _ in
+ completionHandler(a?.textFields?.first?.text)
+ })
+ present(a, animated: true)
+ }
+
// MARK: - the save bridge
func userContentController(_ c: WKUserContentController, didReceive message: WKScriptMessage) {