]> git.r.bdr.sh - rbdr/captura/blame - Captura/Data/CapturaSettings.swift
Add AppleScript support
[rbdr/captura] / Captura / Data / CapturaSettings.swift
CommitLineData
c9b9e1d6
RBR
1import Foundation
2
3struct CapturaSettings {
4 static var frameRate: Int {
ba17de89 5 get {
377442f2
RBR
6 if NSUbiquitousKeyValueStore.default.object(forKey: "frameRate") == nil {
7 return 10
8 } else {
9 return min(10, max(4, Int(NSUbiquitousKeyValueStore.default.longLong(forKey: "frameRate"))))
10 }
ba17de89
RBR
11 }
12 set {
377442f2 13 NSUbiquitousKeyValueStore.default.setValue(newValue, forKey: "frameRate")
ba17de89 14 }
c9b9e1d6
RBR
15 }
16
17 static var outputFormats: OutputFormatSetting {
ba17de89 18 get {
377442f2 19 OutputFormatSetting(rawValue: Int(NSUbiquitousKeyValueStore.default.longLong(forKey: "outputFormats"))) ?? .all
ba17de89
RBR
20 }
21 set {
377442f2 22 NSUbiquitousKeyValueStore.default.setValue(newValue.rawValue, forKey: "outputFormats")
ba17de89 23 }
c9b9e1d6
RBR
24 }
25
26 static var shouldSaveMp4: Bool {
533cd932 27 outputFormats.shouldSaveMp4() || (shouldUseBackend && shouldUploadMp4)
c9b9e1d6
RBR
28 }
29
30 static var shouldSaveGif: Bool {
533cd932 31 outputFormats.shouldSaveGif() || (shouldUseBackend && shouldUploadGif)
c9b9e1d6
RBR
32 }
33
533cd932
RBR
34 static var shouldUploadGif: Bool {
35 backendFormat.shouldSaveGif()
36 }
c9b9e1d6 37
533cd932
RBR
38 static var shouldUploadMp4: Bool {
39 backendFormat.shouldSaveMp4()
40 }
41
42 static var shouldUseBackend: Bool {
43 backend != nil
44 }
45
46 static var backend: URL? {
ba17de89 47 get {
377442f2 48 if let url = NSUbiquitousKeyValueStore.default.string(forKey: "backendUrl") {
ba17de89
RBR
49 return URL(string: url)
50 }
51 return nil
52 }
53 set {
377442f2 54 NSUbiquitousKeyValueStore.default.setValue(newValue?.absoluteString, forKey: "backendUrl")
c9b9e1d6 55 }
533cd932
RBR
56 }
57
58 static var backendFormat: OutputFormatSetting {
ba17de89 59 get {
377442f2 60 OutputFormatSetting(rawValue: Int(NSUbiquitousKeyValueStore.default.longLong(forKey: "backendFormat"))) ?? .gifOnly
ba17de89
RBR
61 }
62 set {
377442f2 63 NSUbiquitousKeyValueStore.default.setValue(newValue.rawValue, forKey: "backendFormat")
ba17de89 64 }
533cd932
RBR
65 }
66
67 static var shouldKeepLocalFiles: Bool {
ba17de89 68 get {
377442f2
RBR
69 if NSUbiquitousKeyValueStore.default.object(forKey: "keepFiles") == nil {
70 return true
71 } else {
72 return NSUbiquitousKeyValueStore.default.bool(forKey: "keepFiles")
73 }
ba17de89
RBR
74 }
75 set {
377442f2 76 NSUbiquitousKeyValueStore.default.set(newValue, forKey: "keepFiles")
ba17de89
RBR
77 }
78 }
79
80 static var shouldAllowURLAutomation: Bool {
377442f2
RBR
81 get {
82 NSUbiquitousKeyValueStore.default.bool(forKey: "allowURLAutomation")
83 }
84 set {
85 NSUbiquitousKeyValueStore.default.setValue(newValue, forKey: "allowURLAutomation")
86 }
ba17de89
RBR
87 }
88
89 static func apply(_ config: ConfigureAction) {
90 if let fps = config.fps {
91 frameRate = fps
92 }
93 if let outputs = config.outputs {
94 outputFormats = outputs
95 }
96 if let newBackend = config.backend {
97 backend = newBackend
98 }
99 if let backendOutput = config.backendOutput {
100 backendFormat = backendOutput
101 }
102 if let keepLocalFiles = config.keepLocalFiles {
103 shouldKeepLocalFiles = keepLocalFiles
104 }
c9b9e1d6
RBR
105 }
106}