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