Skip to content

armgit / bento

Public Imported from GitHub
0

Bento, the office suite that fits in a file

tray/ios: a way back out of a document, and the teardown that goes with it

nyblnetfae1f06c49ae
diff --git a/tray/README.md b/tray/README.md
index 0e93e825..ded3f760 100644
--- a/tray/README.md
+++ b/tray/README.md
@@ -147,6 +147,27 @@ actual device or simulator. Runtime behaviour — the scheme handler serving
bytes, security-scoped access, the save round trip reaching disk — is still
unproven.
+### Getting back out
+
+The editor is presented inside a `UINavigationController` with a **Documents**
+button and the file's name. That bar is not decoration: presented full screen
+with no chrome, a document was a ONE-WAY TRIP — full-screen modals have no
+interactive dismiss, so force-quitting the app was the only exit.
+
+The host has to supply this itself. It cannot ask the page for a close button
+without assuming what the page is, which is the one thing this app does not do.
+
+Leaving also does the teardown that had no home before: `UIDocument.close()`
+(flushes and relinquishes file coordination — the document previously stayed
+open for the life of the app) and the security-scoped release, which ran only
+on the failure path and leaked once per document opened. The scope is dropped
+only after close completes; dropping it earlier can fail the final write for a
+file outside the container.
+
+Known limitation: the nav bar stays visible during a slideshow. The host cannot
+tell when an arbitrary page has gone presentation-mode, and iPhone Safari has no
+real fullscreen, so Bento falls back to filling its view.
+
### Platform notes worth keeping
`didImportDocumentAt` is **never called for the creation flow** on iOS 26. The
diff --git a/tray/ios/DocumentBrowserViewController.swift b/tray/ios/DocumentBrowserViewController.swift
index 856d2b23..c3ec5b69 100644
--- a/tray/ios/DocumentBrowserViewController.swift
+++ b/tray/ios/DocumentBrowserViewController.swift
@@ -94,8 +94,22 @@ final class DocumentBrowserViewController: UIDocumentBrowserViewController,
return
}
let editor = EditorViewController(document: doc)
- editor.modalPresentationStyle = .fullScreen
- self.present(editor, animated: true)
+ // Two extensions: "Q3-board.bento.html" -> "Q3-board".
+ editor.title = url.deletingPathExtension().deletingPathExtension().lastPathComponent
+ let nav = UINavigationController(rootViewController: editor)
+ nav.modalPresentationStyle = .fullScreen
+ editor.onDone = { [weak self, weak nav] in
+ // close() flushes and relinquishes file coordination; without it
+ // the document stayed open for the life of the app. The scope is
+ // released only after the close completes — dropping it earlier
+ // can fail the final write for a file outside our container.
+ doc.close { _ in
+ if scoped { url.stopAccessingSecurityScopedResource() }
+ }
+ nav?.dismiss(animated: true)
+ _ = self
+ }
+ self.present(nav, animated: true)
}
}
}
diff --git a/tray/ios/EditorViewController.swift b/tray/ios/EditorViewController.swift
index cd3d1d58..cd79a09d 100644
--- a/tray/ios/EditorViewController.swift
+++ b/tray/ios/EditorViewController.swift
@@ -55,10 +55,17 @@ final class EditorViewController: UIViewController, WKScriptMessageHandler, WKUR
return digest.compactMap { String(format: "%02x", $0) }.joined().prefix(24).description
}()
+ /// Called when the user leaves the document. The browser owns teardown —
+ /// closing the UIDocument and releasing the security scope — because it
+ /// owns both of those.
+ var onDone: (() -> Void)?
+
init(document: BentoDocument) {
self.document = document
super.init(nibName: nil, bundle: nil)
}
+
+ @objc private func doneTapped() { onDone?() }
required init?(coder: NSCoder) { fatalError("not used") }
override func viewDidLoad() {
@@ -81,6 +88,15 @@ final class EditorViewController: UIViewController, WKScriptMessageHandler, WKUR
webView.allowsBackForwardNavigationGestures = false
view.addSubview(webView)
webView.load(URLRequest(url: URL(string: "bento-tray://\(originHost)/index.html")!))
+
+ // A way BACK. Presented full screen with no chrome, a document was a
+ // one-way trip: full-screen modals have no interactive dismiss, so the
+ // only exit was force-quitting the app. The host has to supply this
+ // itself — it cannot ask the page for a close button without assuming
+ // what the page is.
+ navigationItem.leftBarButtonItem = UIBarButtonItem(
+ title: NSLocalizedString("Documents", comment: "back to the file browser"),
+ style: .plain, target: self, action: #selector(doneTapped))
}
// MARK: - serving the deck