X-Git-Url: https://git.r.bdr.sh/rbdr/captura/blobdiff_plain/533cd932281300fb444c07e80f81fc683a410b60..377442f2f1f0f08bc525393c9bd1c84f159c5159:/Captura/Data/CapturaSettings.swift?ds=sidebyside diff --git a/Captura/Data/CapturaSettings.swift b/Captura/Data/CapturaSettings.swift index 01ef78c..2d0e70b 100644 --- a/Captura/Data/CapturaSettings.swift +++ b/Captura/Data/CapturaSettings.swift @@ -2,11 +2,25 @@ import Foundation struct CapturaSettings { static var frameRate: Int { - UserDefaults.standard.integer(forKey: "frameRate") + get { + if NSUbiquitousKeyValueStore.default.object(forKey: "frameRate") == nil { + return 10 + } else { + return min(10, max(4, Int(NSUbiquitousKeyValueStore.default.longLong(forKey: "frameRate")))) + } + } + set { + NSUbiquitousKeyValueStore.default.setValue(newValue, forKey: "frameRate") + } } static var outputFormats: OutputFormatSetting { - OutputFormatSetting(rawValue: UserDefaults.standard.integer(forKey: "outputFormats")) ?? .all + get { + OutputFormatSetting(rawValue: Int(NSUbiquitousKeyValueStore.default.longLong(forKey: "outputFormats"))) ?? .all + } + set { + NSUbiquitousKeyValueStore.default.setValue(newValue.rawValue, forKey: "outputFormats") + } } static var shouldSaveMp4: Bool { @@ -30,17 +44,63 @@ struct CapturaSettings { } static var backend: URL? { - if let url = UserDefaults.standard.string(forKey: "backendUrl") { - return URL(string: url) + get { + if let url = NSUbiquitousKeyValueStore.default.string(forKey: "backendUrl") { + return URL(string: url) + } + return nil + } + set { + NSUbiquitousKeyValueStore.default.setValue(newValue?.absoluteString, forKey: "backendUrl") } - return nil } static var backendFormat: OutputFormatSetting { - OutputFormatSetting(rawValue: UserDefaults.standard.integer(forKey: "backendFormat")) ?? .all + get { + OutputFormatSetting(rawValue: Int(NSUbiquitousKeyValueStore.default.longLong(forKey: "backendFormat"))) ?? .gifOnly + } + set { + NSUbiquitousKeyValueStore.default.setValue(newValue.rawValue, forKey: "backendFormat") + } } static var shouldKeepLocalFiles: Bool { - UserDefaults.standard.bool(forKey: "keepFiles") + get { + if NSUbiquitousKeyValueStore.default.object(forKey: "keepFiles") == nil { + return true + } else { + return NSUbiquitousKeyValueStore.default.bool(forKey: "keepFiles") + } + } + set { + NSUbiquitousKeyValueStore.default.set(newValue, forKey: "keepFiles") + } + } + + static var shouldAllowURLAutomation: Bool { + get { + NSUbiquitousKeyValueStore.default.bool(forKey: "allowURLAutomation") + } + set { + NSUbiquitousKeyValueStore.default.setValue(newValue, 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 + } } }