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 protocol ConfigureActionProtocol {
20 var action: String { get }
22 var outputs: OutputFormatSetting? { get }
23 var backend: URL? { get }
24 var backendOutput: OutputFormatSetting? { get }
25 var keepLocalFiles: Bool? { get }
28 protocol RecordActionProtocol {
29 var action: String { get }
33 var width: Int? { get }
34 var height: Int? { get }
35 var preventResize: Bool? { get }
36 var preventMove: Bool? { get }
38 var backend: URL? { get }
39 var outputs: OutputFormatSetting? { get }
40 var backendOutput: OutputFormatSetting? { get }
41 var keepLocalFiles: Bool? { get }
42 var autoStart: Bool? { get }
43 var skipBackend: Bool { get }
44 var maxLength: Int? { get }
47 // The concrete implementations
48 struct ConfigureAction: ConfigureActionProtocol {
51 var outputs: OutputFormatSetting?
53 var backendOutput: OutputFormatSetting?
54 var keepLocalFiles: Bool?
57 struct RecordAction: RecordActionProtocol {
63 var preventResize: Bool?
64 var preventMove: Bool?
66 var outputs: OutputFormatSetting?
68 var backendOutput: OutputFormatSetting?
69 var keepLocalFiles: Bool?
76 case record(RecordAction)
77 case configure(ConfigureAction)
80 struct CapturaURLDecoder {
82 static func decodeParams(url: URL) -> CapturaAction? {
83 guard let components = URLComponents(url: url, resolvingAgainstBaseURL: false),
84 let params = components.queryItems
89 var paramsDict = [String: Any]()
91 params.forEach { item in
92 paramsDict[item.name] = item.value
95 guard let action = paramsDict["action"] as? String else {
101 var fps = Int(paramsDict["fps"] as? String ?? "")
102 let backend = URL(string: paramsDict["backend"] as? String ?? "")
103 let keepLocalFiles = Bool(paramsDict["keep_local_files"] as? String ?? "")
104 let outputs = OutputFormatSetting(paramsDict["outputs"] as? String ?? "")
105 var backendOutput = OutputFormatSetting(paramsDict["backend_output"] as? String ?? "")
108 fps = min(10, max(4, fps!))
111 if backendOutput == .all {
112 backendOutput = .gifOnly
121 backendOutput: backendOutput,
122 keepLocalFiles: keepLocalFiles
126 let x = Int(paramsDict["x"] as? String ?? "")
127 let y = Int(paramsDict["y"] as? String ?? "")
128 let width = Int(paramsDict["width"] as? String ?? "")
129 let height = Int(paramsDict["height"] as? String ?? "")
130 let preventResize = Bool(paramsDict["prevent_resize"] as? String ?? "")
131 let preventMove = Bool(paramsDict["prevent_move"] as? String ?? "")
132 var fps = Int(paramsDict["fps"] as? String ?? "")
133 let backend = URL(string: paramsDict["backend"] as? String ?? "")
134 let keepLocalFiles = Bool(paramsDict["keep_local_files"] as? String ?? "")
135 let outputs = OutputFormatSetting(paramsDict["outputs"] as? String ?? "")
136 var backendOutput = OutputFormatSetting(paramsDict["backend_output"] as? String ?? "")
137 let autoStart = Bool(paramsDict["auto_start"] as? String ?? "")
138 var maxLength = Int(paramsDict["max_length"] as? String ?? "")
141 fps = min(10, max(4, fps!))
144 if maxLength != nil {
145 maxLength = min(300, max(1, fps!))
148 if backendOutput == .all {
149 backendOutput = .gifOnly
152 var skipBackend = false
153 if let backendString = paramsDict["backend"] as? String {
154 if backendString == "" {
166 preventResize: preventResize,
167 preventMove: preventMove,
171 backendOutput: backendOutput,
172 keepLocalFiles: keepLocalFiles,
173 autoStart: autoStart,
174 skipBackend: skipBackend,