Sources/OrgApp/XCallbackSettings.swift
59 lines · 2545 bytes
1import SwiftUI
2
3/// The apps allowed to capture, clock and read through x-callback-url links, each with
4/// Forget, for a settings form.
5public struct XCallbackSettings: View {
6 @Bindable var approvals: XCallbackApprovals
7
8 public init(approvals: XCallbackApprovals = .shared) {
9 self.approvals = approvals
10 }
11
12 public var body: some View {
13 Section {
14 if approvals.sources.isEmpty {
15 Text("None").foregroundStyle(.secondary)
16 }
17 ForEach(approvals.sources) { source in
18 HStack {
19 VStack(alignment: .leading, spacing: 2) {
20 Text(XCallbackApprovals.name(source))
21 Text(XCallbackApprovals.destination(source)).font(.caption).foregroundStyle(.secondary)
22 }
23 Spacer()
24 Button("Forget") { approvals.forget(source) }.buttonStyle(.borderless)
25 }
26 }
27 } header: {
28 Text("Apps Allowed to Use Links")
29 } footer: {
30 Text("Apps that may capture, clock in and out, and read your agenda and clock through orgstar:// x-callback-url links without asking.")
31 .font(.caption)
32 .foregroundStyle(.secondary)
33 .fixedSize(horizontal: false, vertical: true)
34 }
35 }
36}
37
38extension XCallbackApprovals {
39 /// The name the app gave, or a stand-in when it gave none.
40 public static func name(_ source: Source) -> String {
41 source.name.isEmpty ? String(localized: "An app that doesn't give its name") : source.name
42 }
43
44 /// Where results go: `Results go to shortcuts:`.
45 public static func destination(_ source: Source) -> String {
46 source.schemes.isEmpty
47 ? String(localized: "No results are sent back")
48 : String(localized: "Results go to \(source.schemes.map { $0 + ":" }.joined(separator: ", "))")
49 }
50
51 /// The question asked before an app's first link that writes to files or reads them.
52 public static func question(_ source: Source) -> String {
53 source.name.isEmpty ? String(localized: "Allow links from an app that doesn't give its name?") : String(localized: "Allow “\(source.name)” to use orgstar?")
54 }
55
56 public static func explanation(_ source: Source) -> String {
57 String(localized: "Its links will be able to capture, clock in and out, and read your agenda and clock without asking again. \(destination(source)). You can forget it in Settings.")
58 }
59}