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 {
17 Task { @MainActor in 17 Task { @MainActor in
18 let shared = await Shared.load(items) 18 let shared = await Shared.load(items)
19 let inbox = CaptureInbox() 19 let inbox = CaptureInbox()
20 // A failed write throws, and the sheet stays open with the error.
20 let form = ShareForm(shared: shared, templates: inbox?.templates() ?? [], available: inbox != nil) { link in 21 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) }
22 context?.completeRequest(returningItems: nil) 23 context?.completeRequest(returningItems: nil)
23 } attach: { files in 24 } attach: { files in
24 try? AttachmentInbox()?.add(files) 25 try AttachmentInbox()?.add(files)
25 context?.completeRequest(returningItems: nil) 26 context?.completeRequest(returningItems: nil)
26 } 27 }
27 let host = UIHostingController(rootView: form) 28 let host = UIHostingController(rootView: form)
@@ -96,9 +97,10 @@ struct ShareForm: View {
96 let shared: Shared 97 let shared: Shared
97 let templates: [CaptureInbox.Template] 98 let templates: [CaptureInbox.Template]
98 let available: Bool 99 let available: Bool
99 let finish: (String?) -> Void 100 let finish: (String?) throws -> Void
100 /// Leaves the files for the app to attach. 101 /// 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?
102 @State private var title = "" 104 @State private var title = ""
103 @State private var note = "" 105 @State private var note = ""
104 @State private var template: String? 106 @State private var template: String?
@@ -109,6 +111,9 @@ struct ShareForm: View {
109 if !available { 111 if !available {
110 Text("orgstar's shared folder isn't available.").foregroundStyle(.red) 112 Text("orgstar's shared folder isn't available.").foregroundStyle(.red)
111 } 113 }
114 if let failure {
115 Text(failure).foregroundStyle(.red)
116 }
112 if !shared.files.isEmpty { 117 if !shared.files.isEmpty {
113 Section { 118 Section {
114 ForEach(shared.files, id: \.self) { Text($0.lastPathComponent) } 119 ForEach(shared.files, id: \.self) { Text($0.lastPathComponent) }
@@ -124,15 +129,15 @@ struct ShareForm: View {
124 .navigationTitle("orgstar") 129 .navigationTitle("orgstar")
125 .navigationBarTitleDisplayMode(.inline) 130 .navigationBarTitleDisplayMode(.inline)
126 .toolbar { 131 .toolbar {
127 ToolbarItem(placement: .cancellationAction) { Button("Cancel") { finish(nil) } } 132 ToolbarItem(placement: .cancellationAction) { Button("Cancel") { save { try finish(nil) } } }
128 ToolbarItem(placement: .confirmationAction) { 133 ToolbarItem(placement: .confirmationAction) {
129 if shared.files.isEmpty { 134 if shared.files.isEmpty {
130 Button("Capture") { 135 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)) }
132 } 137 }
133 .disabled(!available) 138 .disabled(!available)
134 } else { 139 } else {
135 Button("Attach") { attach(shared.files) }.disabled(!available) 140 Button("Attach") { save { try attach(shared.files) } }.disabled(!available)
136 } 141 }
137 } 142 }
138 } 143 }
@@ -144,6 +149,14 @@ struct ShareForm: View {
144 } 149 }
145 } 150 }
146 151
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
147 @ViewBuilder 160 @ViewBuilder
148 private var captureSections: some View { 161 private var captureSections: some View {
149 if !templates.isEmpty { 162 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:
353- for a link, its title (editable) and address; 353- for a link, its title (editable) and address;
354- a Text field, filled with shared text. 354- a Text field, filled with shared text.
355 355
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.
357 357
358The share form lists no templates until orgstar has run once with your configuration folder; the capture sheet then starts on the first template. 358The share form lists no templates until orgstar has run once with your configuration folder; the capture sheet then starts on the first template.
359 359
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.
2902. Choose a template, edit the link's title, and add text. 2902. Choose a template, edit the link's title, and add text.
2913. Tap Capture. 2913. Tap Capture.
292 292
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.
294 294
295** From Shortcuts 295** From Shortcuts
296 296
l10n/Localizable.xcstrings +34 · view
@@ -9791,6 +9791,40 @@
9791 } 9791 }
9792 } 9792 }
9793 }, 9793 },
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 },
9794 "Countdown timer": { 9828 "Countdown timer": {
9795 "localizations": { 9829 "localizations": {
9796 "de": { 9830 "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