diff options
| author | Ruben Beltran del Rio <ruben@unlimited.pizza> | 2023-08-02 22:23:48 +0200 |
|---|---|---|
| committer | Ruben Beltran del Rio <ruben@unlimited.pizza> | 2023-08-02 22:23:48 +0200 |
| commit | e42019cd38b59e757f6036b132614a471d4cf6fe (patch) | |
| tree | 2c95f67640d01a63ef9696ec23d429b866d87293 /Captura | |
| parent | 153f3309127a4f9d898310224a467d11eef0f2ff (diff) | |
Adds configure support for URLs
Diffstat (limited to 'Captura')
| -rw-r--r-- | Captura/CapturaApp.swift | 18 | ||||
| -rw-r--r-- | Captura/Core Extensions/Notification+AppEvents.swift | 1 | ||||
| -rw-r--r-- | Captura/Data/CapturaSettings.swift | 28 | ||||
| -rw-r--r-- | Captura/Presentation/Settings/AdvancedSettings.swift | 9 | ||||
| -rw-r--r-- | Captura/Presentation/Settings/OutputSettings.swift | 5 | ||||
| -rw-r--r-- | Captura/Scripting/Captura.sdef | 14 | ||||
| -rw-r--r-- | Captura/Scripting/ConfigureCommand.swift | 33 |
7 files changed, 78 insertions, 30 deletions
diff --git a/Captura/CapturaApp.swift b/Captura/CapturaApp.swift index d954b9f..2136d72 100644 --- a/Captura/CapturaApp.swift +++ b/Captura/CapturaApp.swift @@ -108,7 +108,9 @@ struct CapturaApp: App { if let action = CapturaURLDecoder.decodeParams(url: url) { switch action { case let .configure(config): - CapturaSettings.apply(config) + NotificationCenter.default.post(name: .setConfiguration, object: nil, userInfo: [ + "config": config + ]) case let .record(config): NotificationCenter.default.post(name: .setCaptureSessionConfiguration, object: nil, userInfo: [ "config": config @@ -200,8 +202,16 @@ struct CapturaApp: App { if let frame = notification.userInfo?["frame"] { receivedFrame(frame as! CVImageBuffer) } + case .setConfiguration: + DispatchQueue.main.async { + if let userInfo = notification.userInfo { + if let config = userInfo["config"] as? ConfigureAction { + self.setConfiguration(config) + } + } + } case .reloadConfiguration: - reloadConfiguration() + reloadConfiguration() case .setCaptureSessionConfiguration: if let userInfo = notification.userInfo { if let config = userInfo["config"] as? RecordAction { @@ -336,6 +346,10 @@ struct CapturaApp: App { } } + func setConfiguration(_ config: ConfigureAction) { + CapturaSettings.apply(config) + } + func reloadConfiguration() { self.captureSessionConfiguration = CaptureSessionConfiguration() } diff --git a/Captura/Core Extensions/Notification+AppEvents.swift b/Captura/Core Extensions/Notification+AppEvents.swift index 82b46e1..be06a2f 100644 --- a/Captura/Core Extensions/Notification+AppEvents.swift +++ b/Captura/Core Extensions/Notification+AppEvents.swift @@ -11,4 +11,5 @@ extension Notification.Name { static let failedtoUpload = Notification.Name("failedToUpload") static let reloadConfiguration = Notification.Name("reloadConfiguration") static let setCaptureSessionConfiguration = Notification.Name("setCaptureSessionConfiguration") + static let setConfiguration = Notification.Name("setConfiguration") } diff --git a/Captura/Data/CapturaSettings.swift b/Captura/Data/CapturaSettings.swift index 2d0e70b..578d17c 100644 --- a/Captura/Data/CapturaSettings.swift +++ b/Captura/Data/CapturaSettings.swift @@ -3,23 +3,23 @@ import Foundation struct CapturaSettings { static var frameRate: Int { get { - if NSUbiquitousKeyValueStore.default.object(forKey: "frameRate") == nil { + if UserDefaults.standard.object(forKey: "frameRate") == nil { return 10 } else { - return min(10, max(4, Int(NSUbiquitousKeyValueStore.default.longLong(forKey: "frameRate")))) + return min(10, max(4, UserDefaults.standard.integer(forKey: "frameRate"))) } } set { - NSUbiquitousKeyValueStore.default.setValue(newValue, forKey: "frameRate") + UserDefaults.standard.setValue(newValue, forKey: "frameRate") } } static var outputFormats: OutputFormatSetting { get { - OutputFormatSetting(rawValue: Int(NSUbiquitousKeyValueStore.default.longLong(forKey: "outputFormats"))) ?? .all + OutputFormatSetting(rawValue: UserDefaults.standard.integer(forKey: "outputFormats")) ?? .all } set { - NSUbiquitousKeyValueStore.default.setValue(newValue.rawValue, forKey: "outputFormats") + UserDefaults.standard.setValue(newValue.rawValue, forKey: "outputFormats") } } @@ -45,44 +45,44 @@ struct CapturaSettings { static var backend: URL? { get { - if let url = NSUbiquitousKeyValueStore.default.string(forKey: "backendUrl") { + if let url = UserDefaults.standard.string(forKey: "backendUrl") { return URL(string: url) } return nil } set { - NSUbiquitousKeyValueStore.default.setValue(newValue?.absoluteString, forKey: "backendUrl") + UserDefaults.standard.setValue(newValue?.absoluteString, forKey: "backendUrl") } } static var backendFormat: OutputFormatSetting { get { - OutputFormatSetting(rawValue: Int(NSUbiquitousKeyValueStore.default.longLong(forKey: "backendFormat"))) ?? .gifOnly + OutputFormatSetting(rawValue: UserDefaults.standard.integer(forKey: "backendFormat")) ?? .gifOnly } set { - NSUbiquitousKeyValueStore.default.setValue(newValue.rawValue, forKey: "backendFormat") + UserDefaults.standard.setValue(newValue.rawValue, forKey: "backendFormat") } } static var shouldKeepLocalFiles: Bool { get { - if NSUbiquitousKeyValueStore.default.object(forKey: "keepFiles") == nil { + if UserDefaults.standard.object(forKey: "keepFiles") == nil { return true } else { - return NSUbiquitousKeyValueStore.default.bool(forKey: "keepFiles") + return UserDefaults.standard.bool(forKey: "keepFiles") } } set { - NSUbiquitousKeyValueStore.default.set(newValue, forKey: "keepFiles") + UserDefaults.standard.set(newValue, forKey: "keepFiles") } } static var shouldAllowURLAutomation: Bool { get { - NSUbiquitousKeyValueStore.default.bool(forKey: "allowURLAutomation") + UserDefaults.standard.bool(forKey: "allowURLAutomation") } set { - NSUbiquitousKeyValueStore.default.setValue(newValue, forKey: "allowURLAutomation") + UserDefaults.standard.setValue(newValue, forKey: "allowURLAutomation") } } diff --git a/Captura/Presentation/Settings/AdvancedSettings.swift b/Captura/Presentation/Settings/AdvancedSettings.swift index 66314b4..cf5794e 100644 --- a/Captura/Presentation/Settings/AdvancedSettings.swift +++ b/Captura/Presentation/Settings/AdvancedSettings.swift @@ -1,12 +1,11 @@ import SwiftUI -import CloudStorage struct AdvancedSettings: View { - @CloudStorage("backendUrl") var backendUrl: String = "" - @CloudStorage("backendFormat") var backendFormat: OutputFormatSetting = .gifOnly - @CloudStorage("keepFiles") var keepFiles = true - @CloudStorage("allowURLAutomation") var allowURLAutomation = false + @AppStorage("backendUrl") var backendUrl: String = "" + @AppStorage("backendFormat") var backendFormat: OutputFormatSetting = .gifOnly + @AppStorage("keepFiles") var keepFiles = true + @AppStorage("allowURLAutomation") var allowURLAutomation = false @State var showConfirmation = false private var anyState: String { "\(backendUrl), \(backendFormat), \(keepFiles), \(allowURLAutomation)" } diff --git a/Captura/Presentation/Settings/OutputSettings.swift b/Captura/Presentation/Settings/OutputSettings.swift index cce34ea..c59afd7 100644 --- a/Captura/Presentation/Settings/OutputSettings.swift +++ b/Captura/Presentation/Settings/OutputSettings.swift @@ -1,10 +1,9 @@ import SwiftUI -import CloudStorage struct OutputSettings: View { - @CloudStorage("outputFormats") var outputFormats: OutputFormatSetting = .all - @CloudStorage("frameRate") var frameRate = 10.0 + @AppStorage("outputFormats") var outputFormats: OutputFormatSetting = .all + @AppStorage("frameRate") var frameRate = 10.0 private var anyState: String { "\(outputFormats), \(frameRate)" } diff --git a/Captura/Scripting/Captura.sdef b/Captura/Scripting/Captura.sdef index ca49d17..0ad7f55 100644 --- a/Captura/Scripting/Captura.sdef +++ b/Captura/Scripting/Captura.sdef @@ -8,18 +8,14 @@ <suite name="Captura Suite" code="CAPT" description="Controls Captura"> <class name="application" code="capp" description="The application's top-level scripting object."> <cocoa class="CapturaApp"/> - <property name="preferences" code="pPrp" type="preferences" access="r"> - <cocoa key="scriptedPreferences"/> - </property> </class> - <class name="preferences" code="Cprf" description="The application preferences"> - <cocoa class="ScriptedPreferences"/> + <record-type code="CCRc" name="configuration"> <property name="fps" code="pPfp" type="integer" description="Sets the FPS of the recording" access="rw" /> <property name="outputs" code="pPou" type="text" description="Which outputs get generated locally" access="rw" /> <property name="backend" code="pPbk" type="text" description="Updates the backend URL that will be used" access="rw" /> <property name="backend_output" code="pPbo" type="text" description="Which output should be sent to the backend" access="rw" /> <property name="keep_local_files" code="pPlf" type="boolean" description="Whether to keep local files after a successful backend upload." access="rw"/> - </class> + </record-type> <record-type code="CCRr" name="recording_configuration"> <property name="x" code="CCrx" type="integer" description="Sets the starting horizontal position of the recording frame from the left of the screen. Defaults to the center of the screen." /> <property name="y" code="CCry" type="integer" description="Sets the starting vertical position of the recording frame from the bottom of the screen. Defaults to the center of the screen." /> @@ -41,5 +37,11 @@ <type type="recording_configuration" /> </direct-parameter> </command> + <command name="configure" code="CCCMConf"> + <cocoa class="ConfigureCommand" /> + <direct-parameter description="The settings to be updated"> + <type type="configuration" /> + </direct-parameter> + </command> </suite> </dictionary> diff --git a/Captura/Scripting/ConfigureCommand.swift b/Captura/Scripting/ConfigureCommand.swift new file mode 100644 index 0000000..4e42326 --- /dev/null +++ b/Captura/Scripting/ConfigureCommand.swift @@ -0,0 +1,33 @@ +import Foundation + +@objc(ConfigureCommand) +class ConfigureCommand: NSScriptCommand { + override func performDefaultImplementation() -> Any? { + + let args = self.directParameter as? [String: Any] ?? [:] + + // Here you can extract the parameters from the args dictionary and configure your settings + let fps = args["fps"] as? Int + let outputs = OutputFormatSetting(args["outputs"] as? String ?? "") + let backend = URL(string: args["backend"] as? String ?? "") + let backendOutput = OutputFormatSetting(args["backend_output"] as? String ?? "") + let keepLocalFiles = args["keep_local_files"] as? Bool + + let config = ConfigureAction( + action: "configure", + fps: fps, + outputs: outputs, + backend: backend, + backendOutput: backendOutput, + keepLocalFiles: keepLocalFiles + ) + + NotificationCenter.default.post(name: .setConfiguration, object: nil, userInfo: [ + "config": config + ]) + NotificationCenter.default.post(name: .reloadConfiguration, object: nil, userInfo: nil) + + // Return a result if needed + return nil + } +} |