]> git.r.bdr.sh - rbdr/captura/commitdiff
Adds configure support for URLs
authorRuben Beltran del Rio <redacted>
Wed, 2 Aug 2023 20:23:48 +0000 (22:23 +0200)
committerRuben Beltran del Rio <redacted>
Wed, 2 Aug 2023 20:23:48 +0000 (22:23 +0200)
Captura.xcodeproj/project.pbxproj
Captura.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved [deleted file]
Captura/CapturaApp.swift
Captura/Core Extensions/Notification+AppEvents.swift
Captura/Data/CapturaSettings.swift
Captura/Presentation/Settings/AdvancedSettings.swift
Captura/Presentation/Settings/OutputSettings.swift
Captura/Scripting/Captura.sdef
Captura/Scripting/ConfigureCommand.swift [new file with mode: 0644]

index 35a5e104261396746ce5ad012111f0e1924954fd..4a11599ce3aba0ad8917f691472a32327f07edd4 100644 (file)
@@ -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 = "<group>"; };
                B5F915712A6EF80E007ECE8E /* CapturaUITestsLaunchTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CapturaUITestsLaunchTests.swift; sourceTree = "<group>"; };
+               B5F95FAE2A7AE7F0005EFFDA /* ConfigureCommand.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ConfigureCommand.swift; sourceTree = "<group>"; };
 /* End PBXFileReference section */
 
 /* Begin PBXFrameworksBuildPhase section */
                        isa = PBXFrameworksBuildPhase;
                        buildActionMask = 2147483647;
                        files = (
-                               B5278B4B2A7995AA009F6462 /* CloudStorage in Frameworks */,
                        );
                        runOnlyForDeploymentPostprocessing = 0;
                };
                        children = (
                                B5278B482A781B78009F6462 /* Captura.sdef */,
                                B55403E92A79A434004BCBAB /* ScriptedPreferences.swift */,
+                               B5F95FAE2A7AE7F0005EFFDA /* ConfigureCommand.swift */,
                                B55403EC2A7A388B004BCBAB /* RecordCommand.swift */,
                        );
                        path = Scripting;
                        );
                        name = Captura;
                        packageProductDependencies = (
-                               B5278B4A2A7995AA009F6462 /* CloudStorage */,
                        );
                        productName = Captura;
                        productReference = B5F9154E2A6EF80D007ECE8E /* Captura.app */;
                        );
                        mainGroup = B5F915452A6EF80D007ECE8E;
                        packageReferences = (
-                               B5278B492A7995AA009F6462 /* XCRemoteSwiftPackageReference "CloudStorage" */,
                        );
                        productRefGroup = B5F9154F2A6EF80D007ECE8E /* Products */;
                        projectDirPath = "";
                                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 */,
                };
 /* 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 (file)
index c5bc2ce..0000000
+++ /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
-}
index d954b9f800e969554ae4bcc478e270f11759c4fb..2136d72f9be0ed6d699d6b9629cf3f6814e57697 100644 (file)
@@ -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()
   }
index 82b46e11bcfb2b2cee23276cd9a3139ca81bc718..be06a2f3676165f7a2f6df16e7b7ea26b6862278 100644 (file)
@@ -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")
 }
index 2d0e70b63bfe80babfecbcbd67fba88a938eba72..578d17c2a4b498f7e8a231d4e785f22be280678c 100644 (file)
@@ -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")
     }
   }
   
index 66314b481582ced4359fa2a2e8b2bc1f39c92a91..cf5794e53e753b188172c983510b07a904397aa8 100644 (file)
@@ -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)" }
index cce34ead395f64153bd52c3a7f587745310ab140..c59afd75c72e26b30e41612258220555cec76aae 100644 (file)
@@ -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)" }
   
index ca49d17015d1b4d3f0a79b8865be8fa3b7c0a252..0ad7f55e5093036e2abb9ff32f7340f4a1d35a6c 100644 (file)
@@ -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." />
           <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 (file)
index 0000000..4e42326
--- /dev/null
@@ -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
+    }
+}