From: Ruben Beltran del Rio Date: Wed, 2 Aug 2023 20:23:48 +0000 (+0200) Subject: Adds configure support for URLs X-Git-Tag: 1.0.0~4 X-Git-Url: https://git.r.bdr.sh/rbdr/captura/commitdiff_plain/e42019cd38b59e757f6036b132614a471d4cf6fe?ds=inline;hp=153f3309127a4f9d898310224a467d11eef0f2ff Adds configure support for URLs --- diff --git a/Captura.xcodeproj/project.pbxproj b/Captura.xcodeproj/project.pbxproj index 35a5e10..4a11599 100644 --- a/Captura.xcodeproj/project.pbxproj +++ b/Captura.xcodeproj/project.pbxproj @@ -23,7 +23,6 @@ B5278B422A779CDB009F6462 /* BackendResponse.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5278B412A779CDB009F6462 /* BackendResponse.swift */; }; B5278B452A77D924009F6462 /* CaptureSessionConfiguration.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5278B442A77D924009F6462 /* CaptureSessionConfiguration.swift */; }; B5278B472A77E8D7009F6462 /* CapturaURLDecoder.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5278B462A77E8D7009F6462 /* CapturaURLDecoder.swift */; }; - B5278B4B2A7995AA009F6462 /* CloudStorage in Frameworks */ = {isa = PBXBuildFile; productRef = B5278B4A2A7995AA009F6462 /* CloudStorage */; }; B5278B4E2A799AA3009F6462 /* GetRemoteCaptures.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5278B4D2A799AA3009F6462 /* GetRemoteCaptures.swift */; }; B55403E72A79A08C004BCBAB /* CapturaShortcutsProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = B55403E62A79A08C004BCBAB /* CapturaShortcutsProvider.swift */; }; B55403EA2A79A434004BCBAB /* ScriptedPreferences.swift in Sources */ = {isa = PBXBuildFile; fileRef = B55403E92A79A434004BCBAB /* ScriptedPreferences.swift */; }; @@ -40,6 +39,7 @@ B5F915662A6EF80E007ECE8E /* CapturaTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5F915652A6EF80E007ECE8E /* CapturaTests.swift */; }; B5F915702A6EF80E007ECE8E /* CapturaUITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5F9156F2A6EF80E007ECE8E /* CapturaUITests.swift */; }; B5F915722A6EF80E007ECE8E /* CapturaUITestsLaunchTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5F915712A6EF80E007ECE8E /* CapturaUITestsLaunchTests.swift */; }; + B5F95FAF2A7AE7F1005EFFDA /* ConfigureCommand.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5F95FAE2A7AE7F0005EFFDA /* ConfigureCommand.swift */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -97,6 +97,7 @@ B5F9156B2A6EF80E007ECE8E /* CapturaUITests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = CapturaUITests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; B5F9156F2A6EF80E007ECE8E /* CapturaUITests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CapturaUITests.swift; sourceTree = ""; }; B5F915712A6EF80E007ECE8E /* CapturaUITestsLaunchTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CapturaUITestsLaunchTests.swift; sourceTree = ""; }; + B5F95FAE2A7AE7F0005EFFDA /* ConfigureCommand.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ConfigureCommand.swift; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -104,7 +105,6 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - B5278B4B2A7995AA009F6462 /* CloudStorage in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -220,6 +220,7 @@ children = ( B5278B482A781B78009F6462 /* Captura.sdef */, B55403E92A79A434004BCBAB /* ScriptedPreferences.swift */, + B5F95FAE2A7AE7F0005EFFDA /* ConfigureCommand.swift */, B55403EC2A7A388B004BCBAB /* RecordCommand.swift */, ); path = Scripting; @@ -305,7 +306,6 @@ ); name = Captura; packageProductDependencies = ( - B5278B4A2A7995AA009F6462 /* CloudStorage */, ); productName = Captura; productReference = B5F9154E2A6EF80D007ECE8E /* Captura.app */; @@ -380,7 +380,6 @@ ); mainGroup = B5F915452A6EF80D007ECE8E; packageReferences = ( - B5278B492A7995AA009F6462 /* XCRemoteSwiftPackageReference "CloudStorage" */, ); productRefGroup = B5F9154F2A6EF80D007ECE8E /* Products */; projectDirPath = ""; @@ -438,6 +437,7 @@ B5278B212A71BFC3009F6462 /* OutputFormatSetting.swift in Sources */, B55DDFCE2A6F069D001A5E76 /* RecordingWindow.swift in Sources */, B55403ED2A7A388B004BCBAB /* RecordCommand.swift in Sources */, + B5F95FAF2A7AE7F1005EFFDA /* ConfigureCommand.swift in Sources */, B5278B402A744297009F6462 /* Persistence.swift in Sources */, B55DDFCC2A6F0253001A5E76 /* Notification+AppEvents.swift in Sources */, B5F9155B2A6EF80E007ECE8E /* CapturaRemoteFile+name.swift in Sources */, @@ -778,25 +778,6 @@ }; /* End XCConfigurationList section */ -/* Begin XCRemoteSwiftPackageReference section */ - B5278B492A7995AA009F6462 /* XCRemoteSwiftPackageReference "CloudStorage" */ = { - isa = XCRemoteSwiftPackageReference; - repositoryURL = "https://github.com/nonstrict-hq/CloudStorage"; - requirement = { - kind = upToNextMajorVersion; - minimumVersion = 0.4.0; - }; - }; -/* End XCRemoteSwiftPackageReference section */ - -/* Begin XCSwiftPackageProductDependency section */ - B5278B4A2A7995AA009F6462 /* CloudStorage */ = { - isa = XCSwiftPackageProductDependency; - package = B5278B492A7995AA009F6462 /* XCRemoteSwiftPackageReference "CloudStorage" */; - productName = CloudStorage; - }; -/* End XCSwiftPackageProductDependency section */ - /* Begin XCVersionGroup section */ B5278B3C2A74420F009F6462 /* Captura.xcdatamodeld */ = { isa = XCVersionGroup; diff --git a/Captura.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved b/Captura.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved deleted file mode 100644 index c5bc2ce..0000000 --- a/Captura.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ /dev/null @@ -1,14 +0,0 @@ -{ - "pins" : [ - { - "identity" : "cloudstorage", - "kind" : "remoteSourceControl", - "location" : "https://github.com/nonstrict-hq/CloudStorage", - "state" : { - "revision" : "35700218d35579df091974b6e7765db94c83448b", - "version" : "0.4.0" - } - } - ], - "version" : 2 -} 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 @@ - - - - - + - + @@ -41,5 +37,11 @@ + + + + + + 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 + } +}