Skip to content

armgit / bento

Public Imported from GitHub
0

Bento, the office suite that fits in a file

tray/ios: "+" now opens the editor, and names collisions sensibly

nyblnet50b7a0e9ace3
diff --git a/tray/README.md b/tray/README.md
index 804bcc0c..c0135c8a 100644
--- a/tray/README.md
+++ b/tray/README.md
@@ -124,6 +124,17 @@ actual device or simulator. Runtime behaviour — the scheme handler serving
bytes, security-scoped access, the save round trip reaching disk — is still
unproven.
+### Platform notes worth keeping
+
+`didImportDocumentAt` is **never called for the creation flow** on iOS 26. The
+creation handler fires and the file lands correctly, but the delegate callback
+does not arrive — so an app that opens the editor from that callback silently
+creates files and appears to do nothing. `tray/ios` therefore places new
+documents itself and hands the browser `.none` ("already in its final
+location"), which also puts collision naming under our control: the system
+renames `Untitled.bento.html` to `Untitled.bento 2.html`, reading `.bento.html`
+as a name plus one extension.
+
Still to do:
- App icon, launch screen, signing, an Apple Developer account ($99/yr).
diff --git a/tray/ios/DocumentBrowserViewController.swift b/tray/ios/DocumentBrowserViewController.swift
index 78e04a08..04ed2fca 100644
--- a/tray/ios/DocumentBrowserViewController.swift
+++ b/tray/ios/DocumentBrowserViewController.swift
@@ -15,32 +15,58 @@ final class DocumentBrowserViewController: UIDocumentBrowserViewController,
allowsPickingMultipleItems = false
}
- /// A new deck is seeded from a bundled starter shell. That bundled copy is
- /// the ONLY Bento version the app ships, and it ages harmlessly: a new deck
- /// self-updates through the normal signed channel the first time it checks,
- /// so the seed drifting behind a release does not strand anyone.
+ /// A new document is seeded from the bundled starter shell.
+ ///
+ /// The document is placed OURSELVES and handed back with `.none` ("already
+ /// in its final location") rather than handing the browser a temp file to
+ /// import. Two reasons, both found by testing on iOS 26:
+ ///
+ /// 1. `didImportDocumentAt` IS NEVER CALLED for the creation flow. The
+ /// creation handler fires and the file lands correctly, but the delegate
+ /// callback never arrives — so the editor never opened and "+" appeared
+ /// to do nothing while silently creating files. Placing the file means we
+ /// hold the URL and can open it directly, depending on no callback.
+ /// 2. Naming collisions become ours to control. Letting the system rename
+ /// produced "Untitled.bento 2.html", because it reads `.bento.html` as
+ /// the name "Untitled.bento" plus extension "html" and inserts the
+ /// counter before the last extension only. Ours reads "Untitled 2".
+ ///
+ /// The bundled seed is the only Bento version this app ships and it ages
+ /// harmlessly: a new document self-updates through the normal signed
+ /// channel the first time it checks.
func documentBrowser(_ c: UIDocumentBrowserViewController,
didRequestDocumentCreationWithHandler handler:
@escaping (URL?, UIDocumentBrowserViewController.ImportMode) -> Void) {
- guard let seed = Bundle.main.url(forResource: "starter", withExtension: "bento.html") else {
- handler(nil, .none); return
+ guard let seed = Bundle.main.url(forResource: "starter", withExtension: "bento.html"),
+ let docs = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first
+ else { handler(nil, .none); return }
+
+ var dest = docs.appendingPathComponent("Untitled.bento.html")
+ var n = 2
+ while FileManager.default.fileExists(atPath: dest.path) {
+ dest = docs.appendingPathComponent("Untitled \(n).bento.html")
+ n += 1
}
- let tmp = FileManager.default.temporaryDirectory.appendingPathComponent("Untitled.bento.html")
- try? FileManager.default.removeItem(at: tmp)
- do { try FileManager.default.copyItem(at: seed, to: tmp) } catch { handler(nil, .none); return }
- handler(tmp, .move)
- }
+ do { try FileManager.default.copyItem(at: seed, to: dest) } catch { handler(nil, .none); return }
- func documentBrowser(_ c: UIDocumentBrowserViewController, didPickDocumentsAt urls: [URL]) {
- guard let url = urls.first else { return }
- openEditor(url)
+ handler(dest, .none)
+ // Next runloop: the browser is mid-transition when the handler returns,
+ // and presenting into that animation is how a present() silently fails.
+ DispatchQueue.main.async { [weak self] in self?.openEditor(dest) }
}
+ /// Still implemented for documents imported from ELSEWHERE (dragged in,
+ /// opened from another app) — that path does deliver the callback.
func documentBrowser(_ c: UIDocumentBrowserViewController, didImportDocumentAt sourceURL: URL,
toDestinationURL destinationURL: URL) {
openEditor(destinationURL)
}
+ func documentBrowser(_ c: UIDocumentBrowserViewController, didPickDocumentsAt urls: [URL]) {
+ guard let url = urls.first else { return }
+ openEditor(url)
+ }
+
private func openEditor(_ url: URL) {
// Security-scoped access: a document opened in place lives outside the
// app container, so the URL must be scoped for the whole editing