]> git.r.bdr.sh - rbdr/captura/blob - Captura/Presentation/Settings/AdvancedSettings.swift
e148f01e63e7c8d7f76bb920c3a25fb6ac616aca
[rbdr/captura] / Captura / Presentation / Settings / AdvancedSettings.swift
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 */
17 import SwiftUI
18
19 struct AdvancedSettings: View {
20
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
25 @State var showConfirmation = false
26
27 private var anyState: String {
28 "\(backendUrl), \(backendFormat), \(keepFiles), \(allowURLAutomation)"
29 }
30
31 var parsedBackendUrl: URL? {
32 URL(string: backendUrl)
33 }
34
35 var body: some View {
36 Form {
37 VStack(alignment: .center) {
38 Section {
39 VStack(alignment: .center) {
40 LabeledContent("Backend URL") {
41 TextField("", text: $backendUrl).font(.body)
42 }.font(.headline)
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 )
46 Picker(selection: $backendFormat, label: Text("Backend Format").font(.headline)) {
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)
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 )
61 Toggle("Keep Local Files", isOn: $keepFiles)
62 .font(.headline)
63 .disabled(parsedBackendUrl == nil)
64 .padding(.vertical, 8.0)
65 .help(
66 "If this is off, locally generated recordings will be deleted immediately after a successful upload."
67 )
68 HStack {
69 Text(
70 "These settings can break things! Please make sure you understand how to use them before enabling."
71 )
72 .lineLimit(3...10)
73 Link(destination: URL(string: "https://captura.tranquil.systems")!) {
74 Image(systemName: "info.circle")
75 }.buttonStyle(.borderless)
76 }
77 }
78 }
79 Divider().padding(.vertical, 8.0)
80 Section {
81 Toggle("Allow URL Based Automation", isOn: $allowURLAutomation)
82 .font(.headline)
83 .padding(.vertical, 8.0)
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 }
98 }
99 )
100 .onChange(
101 of: allowURLAutomation,
102 perform: { newValue in
103 if newValue {
104 showConfirmation = true
105 }
106 })
107 }
108 Spacer()
109 }
110 }
111 .onChange(of: anyState) { _ in
112 NotificationCenter.default.post(name: .reloadConfiguration, object: nil, userInfo: nil)
113 }
114 }
115 }
116
117 #Preview {
118 OutputSettings()
119 }