]>
Commit | Line | Data |
---|---|---|
5802c153 RBR |
1 | /* |
2 | Copyright (C) 2024 Rubén Beltrán del Río | |
3 | ||
4 | This program is free software: you can redistribute it and/or modify | |
5 | it under the terms of the GNU General Public License as published by | |
6 | the Free Software Foundation, either version 3 of the License, or | |
7 | (at your option) any later version. | |
8 | ||
9 | This program is distributed in the hope that it will be useful, | |
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | GNU General Public License for more details. | |
13 | ||
14 | You should have received a copy of the GNU General Public License | |
15 | along with this program. If not, see https://captura.tranquil.systems. | |
16 | */ | |
a4e80427 RBR |
17 | import SwiftUI |
18 | ||
19 | struct AdvancedSettings: View { | |
505c1e62 | 20 | |
e42019cd RBR |
21 | @AppStorage("backendUrl") var backendUrl: String = "" |
22 | @AppStorage("backendFormat") var backendFormat: OutputFormatSetting = .gifOnly | |
23 | @AppStorage("keepFiles") var keepFiles = true | |
24 | @AppStorage("allowURLAutomation") var allowURLAutomation = false | |
ba17de89 | 25 | @State var showConfirmation = false |
505c1e62 RBR |
26 | |
27 | private var anyState: String { | |
28 | "\(backendUrl), \(backendFormat), \(keepFiles), \(allowURLAutomation)" | |
29 | } | |
30 | ||
c9b9e1d6 RBR |
31 | var parsedBackendUrl: URL? { |
32 | URL(string: backendUrl) | |
33 | } | |
505c1e62 | 34 | |
a4e80427 RBR |
35 | var body: some View { |
36 | Form { | |
505c1e62 | 37 | VStack(alignment: .center) { |
ba17de89 | 38 | Section { |
505c1e62 | 39 | VStack(alignment: .center) { |
ba17de89 RBR |
40 | LabeledContent("Backend URL") { |
41 | TextField("", text: $backendUrl).font(.body) | |
42 | }.font(.headline) | |
505c1e62 RBR |
43 | .help( |
44 | "The Backend URL to use. If this is empty, no backend will be used and the options below won't have an effect." | |
45 | ) | |
377442f2 | 46 | Picker(selection: $backendFormat, label: Text("Backend Format").font(.headline)) { |
ba17de89 RBR |
47 | Text("GIF") |
48 | .tag(OutputFormatSetting.gifOnly) | |
49 | .padding(.horizontal, 4.0) | |
50 | .padding(.vertical, 2.0) | |
51 | Text("MP4") | |
52 | .tag(OutputFormatSetting.mp4Only) | |
53 | .padding(.horizontal, 4.0) | |
54 | .padding(.vertical, 2.0) | |
55 | } | |
56 | .pickerStyle(.radioGroup) | |
57 | .disabled(parsedBackendUrl == nil) | |
505c1e62 RBR |
58 | .help( |
59 | "The format picked here will be generated regardless of what option you pick in the output settings. It doesn't prevent files from being rendered." | |
60 | ) | |
ba17de89 RBR |
61 | Toggle("Keep Local Files", isOn: $keepFiles) |
62 | .font(.headline) | |
63 | .disabled(parsedBackendUrl == nil) | |
64 | .padding(.vertical, 8.0) | |
505c1e62 RBR |
65 | .help( |
66 | "If this is off, locally generated recordings will be deleted immediately after a successful upload." | |
67 | ) | |
ba17de89 | 68 | HStack { |
505c1e62 RBR |
69 | Text( |
70 | "These settings can break things! Please make sure you understand how to use them before enabling." | |
71 | ) | |
72 | .lineLimit(3...10) | |
ba17de89 RBR |
73 | Link(destination: URL(string: "https://captura.tranquil.systems")!) { |
74 | Image(systemName: "info.circle") | |
75 | }.buttonStyle(.borderless) | |
76 | } | |
77 | } | |
c9b9e1d6 | 78 | } |
ba17de89 RBR |
79 | Divider().padding(.vertical, 8.0) |
80 | Section { | |
81 | Toggle("Allow URL Based Automation", isOn: $allowURLAutomation) | |
82 | .font(.headline) | |
83 | .padding(.vertical, 8.0) | |
505c1e62 RBR |
84 | .help( |
85 | "If this is on, the app can be controlled remotely using the captura: URL scheme." | |
86 | ) | |
87 | .confirmationDialog( | |
88 | "This may be dangerous and can allow websites to remotely record your computer.", | |
89 | isPresented: $showConfirmation, | |
90 | actions: { | |
91 | Button("I Understand The Risk", role: .destructive) { | |
92 | showConfirmation = false | |
93 | } | |
94 | Button("Cancel", role: .cancel) { | |
95 | showConfirmation = false | |
96 | allowURLAutomation = false | |
97 | } | |
ba17de89 | 98 | } |
505c1e62 RBR |
99 | ) |
100 | .onChange( | |
101 | of: allowURLAutomation, | |
102 | perform: { newValue in | |
103 | if newValue { | |
104 | showConfirmation = true | |
105 | } | |
106 | }) | |
a4e80427 | 107 | } |
c9b9e1d6 | 108 | Spacer() |
a4e80427 RBR |
109 | } |
110 | } | |
377442f2 RBR |
111 | .onChange(of: anyState) { _ in |
112 | NotificationCenter.default.post(name: .reloadConfiguration, object: nil, userInfo: nil) | |
113 | } | |
a4e80427 RBR |
114 | } |
115 | } | |
116 | ||
117 | #Preview { | |
118 | OutputSettings() | |
119 | } |