Commit eee69add63

eee69add637e6a92d9a22e27f1bfc83d40ef6baf

parent: 393d4d261f

Verified · cmc

cmc <hello@cleberg.net> · 2026-11-25 22:15 UTC

Share extension: keep the sheet open when saving fails

Capture and Attach no longer ignore a failed write: the sheet stays
open with the reason and "Open orgstar once, then try again." instead
of closing as if the item were saved.

Ref #222

Layout: unified · split

Changed files (4)
Sources/OrgstarShare/ShareViewController.swift +20 −7 · view
@@ -17,11 +17,12 @@ final class ShareViewController: UIViewController {
1717 Task { @MainActor in
1818 let shared = await Shared.load(items)
1919 let inbox = CaptureInbox()
20 // A failed write throws, and the sheet stays open with the error.
2021 let form = ShareForm(shared: shared, templates: inbox?.templates() ?? [], available: inbox != nil) { link in
21 if let link { try? inbox?.add(link) }
22 if let link { try inbox?.add(link) }
2223 context?.completeRequest(returningItems: nil)
2324 } attach: { files in
24 try? AttachmentInbox()?.add(files)
25 try AttachmentInbox()?.add(files)
2526 context?.completeRequest(returningItems: nil)
2627 }
2728 let host = UIHostingController(rootView: form)
@@ -96,9 +97,10 @@ struct ShareForm: View {
9697 let shared: Shared
9798 let templates: [CaptureInbox.Template]
9899 let available: Bool
99 let finish: (String?) -> Void
100 let finish: (String?) throws -> Void
100101 /// Leaves the files for the app to attach.
101 let attach: ([URL]) -> Void
102 let attach: ([URL]) throws -> Void
103 @State private var failure: String?
102104 @State private var title = ""
103105 @State private var note = ""
104106 @State private var template: String?
@@ -109,6 +111,9 @@ struct ShareForm: View {
109111 if !available {
110112 Text("orgstar's shared folder isn't available.").foregroundStyle(.red)
111113 }
114 if let failure {
115 Text(failure).foregroundStyle(.red)
116 }
112117 if !shared.files.isEmpty {
113118 Section {
114119 ForEach(shared.files, id: \.self) { Text($0.lastPathComponent) }
@@ -124,15 +129,15 @@ struct ShareForm: View {
124129 .navigationTitle("orgstar")
125130 .navigationBarTitleDisplayMode(.inline)
126131 .toolbar {
127 ToolbarItem(placement: .cancellationAction) { Button("Cancel") { finish(nil) } }
132 ToolbarItem(placement: .cancellationAction) { Button("Cancel") { save { try finish(nil) } } }
128133 ToolbarItem(placement: .confirmationAction) {
129134 if shared.files.isEmpty {
130135 Button("Capture") {
131 finish(OrgProtocol.captureURL(template: template, url: shared.url?.absoluteString, title: title, body: note))
136 save { try finish(OrgProtocol.captureURL(template: template, url: shared.url?.absoluteString, title: title, body: note)) }
132137 }
133138 .disabled(!available)
134139 } else {
135 Button("Attach") { attach(shared.files) }.disabled(!available)
140 Button("Attach") { save { try attach(shared.files) } }.disabled(!available)
136141 }
137142 }
138143 }
@@ -144,6 +149,14 @@ struct ShareForm: View {
144149 }
145150 }
146151
152 private func save(_ write: () throws -> Void) {
153 do {
154 try write()
155 } catch {
156 failure = String(localized: "Couldn't save this for orgstar: \(error.localizedDescription) Open orgstar once, then try again.")
157 }
158 }
159
147160 @ViewBuilder
148161 private var captureSections: some View {
149162 if !templates.isEmpty {
docs/manual/guide/08-capture.org +1 −1 · view
@@ -353,7 +353,7 @@ In another app, share a web page or text and choose orgstar. The share form has:
353353- for a link, its title (editable) and address;
354354- a Text field, filled with shared text.
355355
356Capture saves the item in the app group's capture inbox. The next time you open orgstar, it opens the capture sheet with the item as an org-protocol capture: the link becomes =%a= and =%:link=, the title =%:description=, and the text =%i=. Several waiting items open one after another, oldest first. An item stays in the inbox until its sheet is saved or cancelled, so items still waiting when orgstar is ended open the next time. If the extension says orgstar's shared folder isn't available, the app group is missing from the build and nothing can be saved.
356Capture saves the item in the app group's capture inbox. The next time you open orgstar, it opens the capture sheet with the item as an org-protocol capture: the link becomes =%a= and =%:link=, the title =%:description=, and the text =%i=. Several waiting items open one after another, oldest first. An item stays in the inbox until its sheet is saved or cancelled, so items still waiting when orgstar is ended open the next time. If the extension says orgstar's shared folder isn't available, the app group is missing from the build and nothing can be saved. If saving the item fails, the form stays open with the reason and "Open orgstar once, then try again.", so the item isn't lost.
357357
358358The share form lists no templates until orgstar has run once with your configuration folder; the capture sheet then starts on the first template.
359359
docs/manual/guide/14-ios.org +1 −1 · view
@@ -290,7 +290,7 @@ orgstar appears in the share sheet of other apps for a web link or text.
2902902. Choose a template, edit the link's title, and add text.
2912913. Tap Capture.
292292
293The share extension doesn't file the entry itself. It leaves it for the app, which opens its capture sheet with the link and text the next time it becomes active. Several shared items open one after another. If the extension shows "orgstar's shared folder isn't available", the app and its extension can't share data, and Capture is disabled.
293The share extension doesn't file the entry itself. It leaves it for the app, which opens its capture sheet with the link and text the next time it becomes active. Several shared items open one after another. If the extension shows "orgstar's shared folder isn't available", the app and its extension can't share data, and Capture is disabled. If saving the shared item fails, the extension stays open with the reason, so you can try again.
294294
295295** From Shortcuts
296296
l10n/Localizable.xcstrings +34 · view
@@ -9791,6 +9791,40 @@
97919791 }
97929792 }
97939793 },
9794 "Couldn't save this for orgstar: %@ Open orgstar once, then try again.": {
9795 "localizations": {
9796 "de": {
9797 "stringUnit": {
9798 "state": "translated",
9799 "value": "Konnte das nicht für orgstar sichern: %@ Öffne orgstar einmal und versuche es dann erneut."
9800 }
9801 },
9802 "es": {
9803 "stringUnit": {
9804 "state": "translated",
9805 "value": "No se pudo guardar para orgstar: %@ Abre orgstar una vez y vuelve a intentarlo."
9806 }
9807 },
9808 "fr": {
9809 "stringUnit": {
9810 "state": "translated",
9811 "value": "Impossible d'enregistrer ceci pour orgstar : %@ Ouvrez orgstar une fois, puis réessayez."
9812 }
9813 },
9814 "ja": {
9815 "stringUnit": {
9816 "state": "translated",
9817 "value": "orgstar用に保存できませんでした: %@ orgstarを一度開いてから、もう一度お試しください。"
9818 }
9819 },
9820 "pt-BR": {
9821 "stringUnit": {
9822 "state": "translated",
9823 "value": "Não foi possível salvar para o orgstar: %@ Abra o orgstar uma vez e tente novamente."
9824 }
9825 }
9826 }
9827 },
97949828 "Countdown timer": {
97959829 "localizations": {
97969830 "de": {
Keyboard shortcuts

Global

⌘K
Command palette & jump
/
Focus search
?
Show this help
g d
Dashboard
g e
Explore repositories
g n
Notifications

Repository & editor

t
Find file in repository
y
Copy immutable SHA permalink
g c
Code tab
g i
Issues tab
g m
Merge requests tab
g b
Builds tab
⌘↵
Submit active form