Skip to content

armgit / bento

Public Imported from GitHub
0

Bento, the office suite that fits in a file

home/ios: build for Mac Catalyst; on the Mac, open a double-clicked file in place (#751)

nyblnet088be31c3352
diff --git a/docs/DECISIONS.md b/docs/DECISIONS.md
index e4c5326d..4acbf236 100644
--- a/docs/DECISIONS.md
+++ b/docs/DECISIONS.md
@@ -14,6 +14,39 @@ Decision. Why. Pointers.
---
+## 2026-10-18 — The Mac app is the iOS app, built for Mac Catalyst; a Mac double-click edits in place
+
+**Decision (maintainer, 2026-10-18).** Native desktop apps are the primary desktop
+host, and macOS comes from building the existing `home/ios` app for **Mac
+Catalyst**, not from a SwiftUI rewrite or a separate AppKit target. It ships with
+**Developer ID first** (notarised, outside the store); the Mac App Store comes
+later. A `.bento.html` double-click reaches the app through a per-file "open with"
+binding on documents it saves, plus an "Edit in bento/home" hand-off from the
+browser. A `.bento` extension is ruled out: a Bento file stays an HTML file that
+opens anywhere.
+
+**Why Catalyst.** The app builds for Catalyst with no source changes, so every
+host fix lands on the Mac for free.
+
+**Why a type can't do it.** macOS types a file by its last extension, so
+`x.bento.html` is always `public.html`. Measured: a declared, registered
+`bento.html` type with the app as Owner still left a double-click going to the
+browser.
+
+**What changes in code now.** On the Mac, a file the system hands over is opened
+**where it is**. iOS's `revealDocument(importIfNeeded:)` is right on a phone and
+wrong on a Mac: an unsandboxed Mac app's Documents is the person's real
+`~/Documents`, so the import wrote a copy there, and every save went to the copy.
+On the Mac, a double-click means "edit this file".
+
+The Mac bundle id stays `page.bento.home`: one app on every Apple platform.
+
+**Still open.** The browser hand-off's URL scheme needs a security ruling. Signing,
+notarisation, the keychain, passkeys and associated domains all wait on the paid
+Apple team. The scoping is in the private design notes.
+
+---
+
## 2026-09-10 — bento/spaces footnotes: the reference is a TEXT TOKEN, and the number is derived
**Decision.** A footnote in `bento/spaces` is `doc.footnotes` (a document-level
diff --git a/home/README.md b/home/README.md
index e16792d3..722c0e6e 100644
--- a/home/README.md
+++ b/home/README.md
@@ -326,6 +326,18 @@ that carries it is generated and gitignored, so nothing personal is committed.
Leave it unset and `DEVELOPMENT_TEAM` is simply absent — simulator builds are
unaffected.
+**The Mac app is this app**, built for Mac Catalyst. Without a team, build it
+ad-hoc, for this Mac only:
+
+```
+xcodebuild -project BentoTray.xcodeproj -scheme BentoTray \
+ -destination 'platform=macOS,variant=Mac Catalyst' CODE_SIGN_IDENTITY=- build
+```
+
+Distributing it means Developer ID signing and notarisation, which need the team.
+On the Mac, a file handed over by a double-click or Open With is edited **where it
+is**; it is never imported (see `openIncoming`).
+
Find it in **Xcode ▸ Settings ▸ Accounts**, or developer.apple.com ▸ Membership.
A free Apple ID signs for your own devices on a **7-day** profile that must then
be re-signed; TestFlight and the App Store need the paid programme.
diff --git a/home/ios/DocumentBrowserViewController.swift b/home/ios/DocumentBrowserViewController.swift
index 47e309ee..167e0dbb 100644
--- a/home/ios/DocumentBrowserViewController.swift
+++ b/home/ios/DocumentBrowserViewController.swift
@@ -193,7 +193,20 @@ final class DocumentBrowserViewController: UIDocumentBrowserViewController,
/// AirDrop, or tapping a file in Files. `revealDocument` imports it into the
/// browser's storage when it lives somewhere we cannot keep hold of, and
/// surfaces it in the UI so the user can find it again afterwards.
+ ///
+ /// NOT on the Mac. There the system hands us a file because someone
+ /// double-clicked it, or chose Open With, and that means "edit this file",
+ /// never "keep a copy of it". Importing there was worse than redundant: an
+ /// unsandboxed Mac app's Documents directory is the person's real
+ /// ~/Documents, so the import silently wrote a COPY there, the editor saved
+ /// to the copy, and the file they had opened never changed (measured on a
+ /// Catalyst build, 2026-10-18). A sandboxed build would copy into its
+ /// container instead, which is the same failure somewhere less visible.
func openIncoming(_ url: URL) {
+ #if targetEnvironment(macCatalyst)
+ openEditor(url)
+ return
+ #else
revealDocument(at: url, importIfNeeded: true) { [weak self] revealed, error in
guard let self else { return }
// Falling back to the original URL matters: reveal fails for a file
@@ -202,6 +215,7 @@ final class DocumentBrowserViewController: UIDocumentBrowserViewController,
self.openEditor(revealed ?? url)
if let error { NSLog("reveal failed, opened in place: %@", String(describing: error)) }
}
+ #endif
}
private func openEditor(_ url: URL) {
diff --git a/home/ios/project.yml b/home/ios/project.yml
index 32286191..1b31f0b4 100644
--- a/home/ios/project.yml
+++ b/home/ios/project.yml
@@ -30,7 +30,14 @@ targets:
base:
INFOPLIST_FILE: Info.plist
PRODUCT_BUNDLE_IDENTIFIER: page.bento.home
- TARGETED_DEVICE_FAMILY: "1,2" # iPhone and iPad
+ TARGETED_DEVICE_FAMILY: "1,2,6" # iPhone, iPad, and the Mac via Catalyst
+ # The Mac app is this app, built for Mac Catalyst (ruled 2026-10-18).
+ # Locally, with no team, build it ad-hoc:
+ # xcodebuild -scheme BentoTray -destination 'platform=macOS,variant=Mac Catalyst' CODE_SIGN_IDENTITY=-
+ # The Mac bundle id stays page.bento.home rather than Xcode's derived
+ # "maccatalyst." variant, so it is one app on every Apple platform.
+ SUPPORTS_MACCATALYST: YES
+ DERIVE_MACCATALYST_PRODUCT_BUNDLE_IDENTIFIER: NO
SWIFT_VERSION: "5.0"
# Signing. The SIMULATOR needs none of this — it signs ad-hoc, which is
# why every build so far has just worked. A real device needs a team.
diff --git a/scripts/test-home-bridge.ts b/scripts/test-home-bridge.ts
index 439ee190..59be4180 100644
--- a/scripts/test-home-bridge.ts
+++ b/scripts/test-home-bridge.ts
@@ -154,6 +154,26 @@ ok(exportCopy.includes('hasPrefix(') && exportCopy.includes('safeFileName(name)'
'android: a main-frame page start forgets remembered Save-As copies')
}
+// The Mac (Catalyst) opens a system-handed file IN PLACE. revealDocument's import
+// is right on iOS and wrong on the Mac: an unsandboxed Mac app's Documents is the
+// person's real ~/Documents, so the import wrote a copy there and every save went
+// to the copy while the file they double-clicked never changed (measured,
+// 2026-10-18). The Catalyst branch must open the URL it was given, and must do so
+// BEFORE any import can run.
+{
+ const browser = readFileSync(join(dirname(SRC), 'DocumentBrowserViewController.swift'), 'utf8')
+ const incoming = slice(browser, 'func openIncoming(')
+ const mac = incoming.indexOf('#if targetEnvironment(macCatalyst)')
+ const reveal = incoming.indexOf('revealDocument(')
+ ok(mac >= 0 && /openEditor\(url\)\s*\n\s*return/.test(incoming.slice(mac, reveal > mac ? reveal : undefined)),
+ 'on the Mac, openIncoming opens the given file and returns')
+ ok(mac >= 0 && reveal > mac,
+ "the Mac branch comes before revealDocument's import, so the Mac can never import a copy")
+ const yml = readFileSync(join(dirname(SRC), 'project.yml'), 'utf8')
+ ok(/SUPPORTS_MACCATALYST:\s*YES/.test(yml) && /DERIVE_MACCATALYST_PRODUCT_BUNDLE_IDENTIFIER:\s*NO/.test(yml),
+ 'the app builds for Mac Catalyst, as page.bento.home on every Apple platform')
+}
+
if (spawnSync('swiftc', ['--version']).status !== 0) {
console.log(' skip no Swift toolchain on this machine — behaviour checks not run')
console.log(`\n${checks - failures}/${checks} checks passed`)