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 }
30 // The concrete implementations
31 struct ConfigureAction: ConfigureActionProtocol {
34 var outputs: OutputFormatSetting?
36 var backendOutput: OutputFormatSetting?
37 var keepLocalFiles: Bool?
40 struct RecordAction: RecordActionProtocol {
46 var preventResize: Bool?
47 var preventMove: Bool?
49 var outputs: OutputFormatSetting?
51 var backendOutput: OutputFormatSetting?
52 var keepLocalFiles: Bool?
57 case record(RecordAction)
58 case configure(ConfigureAction)
61 struct CapturaURLDecoder {
63 static func decodeParams(url: URL) -> CapturaAction? {
64 guard let components = URLComponents(url: url, resolvingAgainstBaseURL: false),
65 let params = components.queryItems else {
69 var paramsDict = [String: Any]()
71 params.forEach { item in
72 paramsDict[item.name] = item.value
75 guard let action = paramsDict["action"] as? String else {
81 var fps = Int(paramsDict["fps"] as? String ?? "")
82 let backend = URL(string: paramsDict["backend"] as? String ?? "")
83 let keepLocalFiles = Bool(paramsDict["keep_local_files"] as? String ?? "")
84 let outputs = OutputFormatSetting(paramsDict["outputs"] as? String ?? "")
85 var backendOutput = OutputFormatSetting(paramsDict["backend_output"] as? String ?? "")
88 fps = min(10, max(4, fps!))
91 if backendOutput == .all {
92 backendOutput = .gifOnly
95 return .configure(ConfigureAction(
100 backendOutput: backendOutput,
101 keepLocalFiles: keepLocalFiles
105 let x = Int(paramsDict["x"] as? String ?? "")
106 let y = Int(paramsDict["y"] as? String ?? "")
107 let width = Int(paramsDict["width"] as? String ?? "")
108 let height = Int(paramsDict["height"] as? String ?? "")
109 let preventResize = Bool(paramsDict["prevent_resize"] as? String ?? "")
110 let preventMove = Bool(paramsDict["prevent_move"] as? String ?? "")
111 var fps = Int(paramsDict["fps"] as? String ?? "")
112 let backend = URL(string: paramsDict["backend"] as? String ?? "")
113 let keepLocalFiles = Bool(paramsDict["keep_local_files"] as? String ?? "")
114 let outputs = OutputFormatSetting(paramsDict["outputs"] as? String ?? "")
115 var backendOutput = OutputFormatSetting(paramsDict["backend_output"] as? String ?? "")
118 fps = min(10, max(4, fps!))
121 if backendOutput == .all {
122 backendOutput = .gifOnly
125 return .record(RecordAction(
131 preventResize: preventResize,
132 preventMove: preventMove,
136 backendOutput: backendOutput,
137 keepLocalFiles: keepLocalFiles