]> git.r.bdr.sh - rbdr/captura/blobdiff - Captura/Data/CapturaSettings.swift
Allow URL configuration
[rbdr/captura] / Captura / Data / CapturaSettings.swift
index 01ef78c56bf222a1ec2f960e284cff28134094e9..85368ea0695240404ce303ef403f6ccd82bed62e 100644 (file)
@@ -2,11 +2,21 @@ import Foundation
 
 struct CapturaSettings {
   static var frameRate: Int {
-    UserDefaults.standard.integer(forKey: "frameRate")
+    get {
+      UserDefaults.standard.integer(forKey: "frameRate")
+    }
+    set {
+      UserDefaults.standard.setValue(newValue, forKey: "frameRate")
+    }
   }
   
   static var outputFormats: OutputFormatSetting {
-    OutputFormatSetting(rawValue: UserDefaults.standard.integer(forKey: "outputFormats")) ?? .all
+    get {
+      OutputFormatSetting(rawValue: UserDefaults.standard.integer(forKey: "outputFormats")) ?? .all
+    }
+    set {
+      UserDefaults.standard.setValue(newValue.rawValue, forKey: "outputFormats")
+    }
   }
   
   static var shouldSaveMp4: Bool {
@@ -30,17 +40,54 @@ struct CapturaSettings {
   }
   
   static var backend: URL? {
-    if let url = UserDefaults.standard.string(forKey: "backendUrl") {
-      return URL(string: url)
+    get {
+      if let url = UserDefaults.standard.string(forKey: "backendUrl") {
+        return URL(string: url)
+      }
+      return nil
+    }
+    set {
+      UserDefaults.standard.setValue(newValue?.absoluteString, forKey: "backendUrl")
     }
-    return nil
   }
   
   static var backendFormat: OutputFormatSetting {
-    OutputFormatSetting(rawValue: UserDefaults.standard.integer(forKey: "backendFormat")) ?? .all
+    get {
+      OutputFormatSetting(rawValue: UserDefaults.standard.integer(forKey: "backendFormat")) ?? .gifOnly
+    }
+    set {
+      UserDefaults.standard.setValue(newValue.rawValue, forKey: "backendFormat")
+    }
   }
   
   static var shouldKeepLocalFiles: Bool {
-    UserDefaults.standard.bool(forKey: "keepFiles")
+    get {
+      UserDefaults.standard.bool(forKey: "keepFiles")
+    }
+    set {
+      UserDefaults.standard.set(newValue, forKey: "keepFiles")
+    }
+  }
+  
+  static var shouldAllowURLAutomation: Bool {
+    UserDefaults.standard.bool(forKey: "allowURLAutomation")
+  }
+  
+  static func apply(_ config: ConfigureAction) {
+    if let fps = config.fps {
+      frameRate = fps
+    }
+    if let outputs = config.outputs {
+      outputFormats = outputs
+    }
+    if let newBackend = config.backend {
+      backend = newBackend
+    }
+    if let backendOutput = config.backendOutput {
+      backendFormat = backendOutput
+    }
+    if let keepLocalFiles = config.keepLocalFiles {
+      shouldKeepLocalFiles = keepLocalFiles
+    }
   }
 }