]> git.r.bdr.sh - rbdr/captura/blobdiff - Captura/Data/CapturaSettings.swift
Attempt more AppleScript support
[rbdr/captura] / Captura / Data / CapturaSettings.swift
index 85368ea0695240404ce303ef403f6ccd82bed62e..2d0e70b63bfe80babfecbcbd67fba88a938eba72 100644 (file)
@@ -3,19 +3,23 @@ import Foundation
 struct CapturaSettings {
   static var frameRate: Int {
     get {
-      UserDefaults.standard.integer(forKey: "frameRate")
+      if NSUbiquitousKeyValueStore.default.object(forKey: "frameRate") == nil {
+        return 10
+      } else {
+        return min(10, max(4, Int(NSUbiquitousKeyValueStore.default.longLong(forKey: "frameRate"))))
+      }
     }
     set {
-      UserDefaults.standard.setValue(newValue, forKey: "frameRate")
+      NSUbiquitousKeyValueStore.default.setValue(newValue, forKey: "frameRate")
     }
   }
   
   static var outputFormats: OutputFormatSetting {
     get {
-      OutputFormatSetting(rawValue: UserDefaults.standard.integer(forKey: "outputFormats")) ?? .all
+      OutputFormatSetting(rawValue: Int(NSUbiquitousKeyValueStore.default.longLong(forKey: "outputFormats"))) ?? .all
     }
     set {
-      UserDefaults.standard.setValue(newValue.rawValue, forKey: "outputFormats")
+      NSUbiquitousKeyValueStore.default.setValue(newValue.rawValue, forKey: "outputFormats")
     }
   }
   
@@ -41,36 +45,45 @@ struct CapturaSettings {
   
   static var backend: URL? {
     get {
-      if let url = UserDefaults.standard.string(forKey: "backendUrl") {
+      if let url = NSUbiquitousKeyValueStore.default.string(forKey: "backendUrl") {
         return URL(string: url)
       }
       return nil
     }
     set {
-      UserDefaults.standard.setValue(newValue?.absoluteString, forKey: "backendUrl")
+      NSUbiquitousKeyValueStore.default.setValue(newValue?.absoluteString, forKey: "backendUrl")
     }
   }
   
   static var backendFormat: OutputFormatSetting {
     get {
-      OutputFormatSetting(rawValue: UserDefaults.standard.integer(forKey: "backendFormat")) ?? .gifOnly
+      OutputFormatSetting(rawValue: Int(NSUbiquitousKeyValueStore.default.longLong(forKey: "backendFormat"))) ?? .gifOnly
     }
     set {
-      UserDefaults.standard.setValue(newValue.rawValue, forKey: "backendFormat")
+      NSUbiquitousKeyValueStore.default.setValue(newValue.rawValue, forKey: "backendFormat")
     }
   }
   
   static var shouldKeepLocalFiles: Bool {
     get {
-      UserDefaults.standard.bool(forKey: "keepFiles")
+      if NSUbiquitousKeyValueStore.default.object(forKey: "keepFiles") == nil {
+        return true
+      } else {
+        return NSUbiquitousKeyValueStore.default.bool(forKey: "keepFiles")
+      }
     }
     set {
-      UserDefaults.standard.set(newValue, forKey: "keepFiles")
+      NSUbiquitousKeyValueStore.default.set(newValue, forKey: "keepFiles")
     }
   }
   
   static var shouldAllowURLAutomation: Bool {
-    UserDefaults.standard.bool(forKey: "allowURLAutomation")
+    get {
+      NSUbiquitousKeyValueStore.default.bool(forKey: "allowURLAutomation")
+    }
+    set {
+      NSUbiquitousKeyValueStore.default.setValue(newValue, forKey: "allowURLAutomation")
+    }
   }
   
   static func apply(_ config: ConfigureAction) {