Commit eee69add63
Verified · cmc
Changed files (4)
Sources/OrgstarShare/ShareViewController.swift +20 −7 · view
| @@ -17,11 +17,12 @@ final class ShareViewController: UIViewController { | ||
| 17 | 17 | Task { @MainActor in |
| 18 | 18 | let shared = await Shared.load(items) |
| 19 | 19 | let inbox = CaptureInbox() |
| 20 | // A failed write throws, and the sheet stays open with the error. | |
| 20 | 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 | 23 | context?.completeRequest(returningItems: nil) |
| 23 | 24 | } attach: { files in |
| 24 | try? AttachmentInbox()?.add(files) | |
| 25 | try AttachmentInbox()?.add(files) | |
| 25 | 26 | context?.completeRequest(returningItems: nil) |
| 26 | 27 | } |
| 27 | 28 | let host = UIHostingController(rootView: form) |
| @@ -96,9 +97,10 @@ struct ShareForm: View { | ||
| 96 | 97 | let shared: Shared |
| 97 | 98 | let templates: [CaptureInbox.Template] |
| 98 | 99 | let available: Bool |
| 99 | let finish: (String?) -> Void | |
| 100 | let finish: (String?) throws -> Void | |
| 100 | 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 | 104 | @State private var title = "" |
| 103 | 105 | @State private var note = "" |
| 104 | 106 | @State private var template: String? |
| @@ -109,6 +111,9 @@ struct ShareForm: View { | ||
| 109 | 111 | if !available { |
| 110 | 112 | Text("orgstar's shared folder isn't available.").foregroundStyle(.red) |
| 111 | 113 | } |
| 114 | if let failure { | |
| 115 | Text(failure).foregroundStyle(.red) | |
| 116 | } | |
| 112 | 117 | if !shared.files.isEmpty { |
| 113 | 118 | Section { |
| 114 | 119 | ForEach(shared.files, id: \.self) { Text($0.lastPathComponent) } |
| @@ -124,15 +129,15 @@ struct ShareForm: View { | ||
| 124 | 129 | .navigationTitle("orgstar") |
| 125 | 130 | .navigationBarTitleDisplayMode(.inline) |
| 126 | 131 | .toolbar { |
| 127 | ToolbarItem(placement: .cancellationAction) { Button("Cancel") { finish(nil) } } | |
| 132 | ToolbarItem(placement: .cancellationAction) { Button("Cancel") { save { try finish(nil) } } } | |
| 128 | 133 | ToolbarItem(placement: .confirmationAction) { |
| 129 | 134 | if shared.files.isEmpty { |
| 130 | 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 | 138 | .disabled(!available) |
| 134 | 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 | 160 | @ViewBuilder |
| 148 | 161 | private var captureSections: some View { |
| 149 | 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 | 353 | - for a link, its title (editable) and address; |
| 354 | 354 | - a Text field, filled with shared text. |
| 355 | 355 | |
| 356 | Capture 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. | |
| 356 | Capture 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 | |
| 358 | 358 | The 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. | ||
| 290 | 290 | 2. Choose a template, edit the link's title, and add text. |
| 291 | 291 | 3. Tap Capture. |
| 292 | 292 | |
| 293 | The 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. | |
| 293 | The 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 | 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 | 9828 | "Countdown timer": { |
| 9795 | 9829 | "localizations": { |
| 9796 | 9830 | "de": { |