2 Copyright (C) 2024 Rubén Beltrán del Río
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.
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.
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.
19 struct CapturaSettings {
20 static var frameRate: Int {
22 if UserDefaults.standard.object(forKey: "frameRate") == nil {
25 return min(10, max(4, UserDefaults.standard.integer(forKey: "frameRate")))
29 UserDefaults.standard.setValue(newValue, forKey: "frameRate")
33 static var outputFormats: OutputFormatSetting {
35 OutputFormatSetting(rawValue: UserDefaults.standard.integer(forKey: "outputFormats")) ?? .all
38 UserDefaults.standard.setValue(newValue.rawValue, forKey: "outputFormats")
42 static var shouldSaveMp4: Bool {
43 outputFormats.shouldSaveMp4() || (shouldUseBackend && shouldUploadMp4)
46 static var shouldSaveGif: Bool {
47 outputFormats.shouldSaveGif() || (shouldUseBackend && shouldUploadGif)
50 static var shouldUploadGif: Bool {
51 backendFormat.shouldSaveGif()
54 static var shouldUploadMp4: Bool {
55 backendFormat.shouldSaveMp4()
58 static var shouldUseBackend: Bool {
62 static var backend: URL? {
64 if let url = UserDefaults.standard.string(forKey: "backendUrl") {
65 return URL(string: url)
70 UserDefaults.standard.setValue(newValue?.absoluteString, forKey: "backendUrl")
74 static var backendFormat: OutputFormatSetting {
76 OutputFormatSetting(rawValue: UserDefaults.standard.integer(forKey: "backendFormat")) ?? .gifOnly
79 UserDefaults.standard.setValue(newValue.rawValue, forKey: "backendFormat")
83 static var shouldKeepLocalFiles: Bool {
85 if UserDefaults.standard.object(forKey: "keepFiles") == nil {
88 return UserDefaults.standard.bool(forKey: "keepFiles")
92 UserDefaults.standard.set(newValue, forKey: "keepFiles")
96 static var shouldAllowURLAutomation: Bool {
98 UserDefaults.standard.bool(forKey: "allowURLAutomation")
101 UserDefaults.standard.setValue(newValue, forKey: "allowURLAutomation")
105 static func apply(_ config: ConfigureAction) {
106 if let fps = config.fps {
109 if let outputs = config.outputs {
110 outputFormats = outputs
112 if let newBackend = config.backend {
115 if let backendOutput = config.backendOutput {
116 backendFormat = backendOutput
118 if let keepLocalFiles = config.keepLocalFiles {
119 shouldKeepLocalFiles = keepLocalFiles