4 protocol ConfigureActionProtocol {
5 var action: String { get }
7 var outputs: OutputFormatSetting? { get }
8 var backend: URL? { get }
9 var backendOutput: OutputFormatSetting? { get }
10 var keepLocalFiles: Bool? { get }
13 protocol RecordActionProtocol {
14 var action: String { get }
18 var width: Int? { get }
19 var height: Int? { get }
20 var preventResize: Bool? { get }
21 var preventMove: Bool? { get }
23 var backend: URL? { get }
24 var outputs: OutputFormatSetting? { get }
25 var backendOutput: OutputFormatSetting? { get }
26 var keepLocalFiles: Bool? { get }
27 var autoStart: Bool? { get }
28 var skipBackend: Bool { get }
29 var maxLength: Int? { get }
32 // The concrete implementations
33 struct ConfigureAction: ConfigureActionProtocol {
36 var outputs: OutputFormatSetting?
38 var backendOutput: OutputFormatSetting?
39 var keepLocalFiles: Bool?
42 struct RecordAction: RecordActionProtocol {
48 var preventResize: Bool?
49 var preventMove: Bool?
51 var outputs: OutputFormatSetting?
53 var backendOutput: OutputFormatSetting?
54 var keepLocalFiles: Bool?
61 case record(RecordAction)
62 case configure(ConfigureAction)
65 struct CapturaURLDecoder {
67 static func decodeParams(url: URL) -> CapturaAction? {
68 guard let components = URLComponents(url: url, resolvingAgainstBaseURL: false),
69 let params = components.queryItems else {
73 var paramsDict = [String: Any]()
75 params.forEach { item in
76 paramsDict[item.name] = item.value
79 guard let action = paramsDict["action"] as? String else {
85 var fps = Int(paramsDict["fps"] as? String ?? "")
86 let backend = URL(string: paramsDict["backend"] as? String ?? "")
87 let keepLocalFiles = Bool(paramsDict["keep_local_files"] as? String ?? "")
88 let outputs = OutputFormatSetting(paramsDict["outputs"] as? String ?? "")
89 var backendOutput = OutputFormatSetting(paramsDict["backend_output"] as? String ?? "")
92 fps = min(10, max(4, fps!))
95 if backendOutput == .all {
96 backendOutput = .gifOnly
99 return .configure(ConfigureAction(
104 backendOutput: backendOutput,
105 keepLocalFiles: keepLocalFiles
109 let x = Int(paramsDict["x"] as? String ?? "")
110 let y = Int(paramsDict["y"] as? String ?? "")
111 let width = Int(paramsDict["width"] as? String ?? "")
112 let height = Int(paramsDict["height"] as? String ?? "")
113 let preventResize = Bool(paramsDict["prevent_resize"] as? String ?? "")
114 let preventMove = Bool(paramsDict["prevent_move"] as? String ?? "")
115 var fps = Int(paramsDict["fps"] as? String ?? "")
116 let backend = URL(string: paramsDict["backend"] as? String ?? "")
117 let keepLocalFiles = Bool(paramsDict["keep_local_files"] as? String ?? "")
118 let outputs = OutputFormatSetting(paramsDict["outputs"] as? String ?? "")
119 var backendOutput = OutputFormatSetting(paramsDict["backend_output"] as? String ?? "")
120 let autoStart = Bool(paramsDict["auto_start"] as? String ?? "")
121 var maxLength = Int(paramsDict["max_length"] as? String ?? "")
124 fps = min(10, max(4, fps!))
127 if maxLength != nil {
128 maxLength = min(300, max(1, fps!))
131 if backendOutput == .all {
132 backendOutput = .gifOnly
135 var skipBackend = false
136 if let backendString = paramsDict["backend"] as? String {
137 if backendString == "" {
142 return .record(RecordAction(
148 preventResize: preventResize,
149 preventMove: preventMove,
153 backendOutput: backendOutput,
154 keepLocalFiles: keepLocalFiles,
155 autoStart: autoStart,
156 skipBackend: skipBackend,