]> git.r.bdr.sh - rbdr/captura/blob - Captura/Presentation/Settings/AdvancedSettings.swift
cf5794e53e753b188172c983510b07a904397aa8
[rbdr/captura] / Captura / Presentation / Settings / AdvancedSettings.swift
1 import SwiftUI
2
3 struct AdvancedSettings: View {
4
5 @AppStorage("backendUrl") var backendUrl: String = ""
6 @AppStorage("backendFormat") var backendFormat: OutputFormatSetting = .gifOnly
7 @AppStorage("keepFiles") var keepFiles = true
8 @AppStorage("allowURLAutomation") var allowURLAutomation = false
9 @State var showConfirmation = false
10
11 private var anyState: String { "\(backendUrl), \(backendFormat), \(keepFiles), \(allowURLAutomation)" }
12
13 var parsedBackendUrl: URL? {
14 URL(string: backendUrl)
15 }
16
17 var body: some View {
18 Form {
19 VStack (alignment: .center) {
20 Section {
21 VStack (alignment: .center) {
22 LabeledContent("Backend URL") {
23 TextField("", text: $backendUrl).font(.body)
24 }.font(.headline)
25 .help("The Backend URL to use. If this is empty, no backend will be used and the options below won't have an effect.")
26 Picker(selection: $backendFormat, label: Text("Backend Format").font(.headline)) {
27 Text("GIF")
28 .tag(OutputFormatSetting.gifOnly)
29 .padding(.horizontal, 4.0)
30 .padding(.vertical, 2.0)
31 Text("MP4")
32 .tag(OutputFormatSetting.mp4Only)
33 .padding(.horizontal, 4.0)
34 .padding(.vertical, 2.0)
35 }
36 .pickerStyle(.radioGroup)
37 .disabled(parsedBackendUrl == nil)
38 .help("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.")
39 Toggle("Keep Local Files", isOn: $keepFiles)
40 .font(.headline)
41 .disabled(parsedBackendUrl == nil)
42 .padding(.vertical, 8.0)
43 .help("If this is off, locally generated recordings will be deleted immediately after a successful upload.")
44 HStack {
45 Text("These settings can break things! Please make sure you understand how to use them before enabling.")
46 .lineLimit(3...10)
47 Link(destination: URL(string: "https://captura.tranquil.systems")!) {
48 Image(systemName: "info.circle")
49 }.buttonStyle(.borderless)
50 }
51 }
52 }
53 Divider().padding(.vertical, 8.0)
54 Section {
55 Toggle("Allow URL Based Automation", isOn: $allowURLAutomation)
56 .font(.headline)
57 .padding(.vertical, 8.0)
58 .help("If this is on, the app can be controlled remotely using the captura: URL scheme.")
59 .confirmationDialog("This may be dangerous and can allow websites to remotely record your computer.", isPresented: $showConfirmation, actions: {
60 Button("I Understand The Risk", role: .destructive) {
61 showConfirmation = false
62 }
63 Button("Cancel", role: .cancel) {
64 showConfirmation = false
65 allowURLAutomation = false
66 }
67 })
68 .onChange(of: allowURLAutomation, perform: { newValue in
69 if newValue {
70 showConfirmation = true
71 }
72 })
73 }
74 Spacer()
75 }
76 }
77 .onChange(of: anyState) { _ in
78 NotificationCenter.default.post(name: .reloadConfiguration, object: nil, userInfo: nil)
79 }
80 }
81 }
82
83 #Preview {
84 OutputSettings()
85 }