]> git.r.bdr.sh - rbdr/captura/blame_incremental - Captura/Data/CapturaSettings.swift
Add multimonitor support
[rbdr/captura] / Captura / Data / CapturaSettings.swift
... / ...
CommitLineData
1import Foundation
2
3struct CapturaSettings {
4 static var frameRate: Int {
5 get {
6 if UserDefaults.standard.object(forKey: "frameRate") == nil {
7 return 10
8 } else {
9 return min(10, max(4, UserDefaults.standard.integer(forKey: "frameRate")))
10 }
11 }
12 set {
13 UserDefaults.standard.setValue(newValue, forKey: "frameRate")
14 }
15 }
16
17 static var outputFormats: OutputFormatSetting {
18 get {
19 OutputFormatSetting(rawValue: UserDefaults.standard.integer(forKey: "outputFormats")) ?? .all
20 }
21 set {
22 UserDefaults.standard.setValue(newValue.rawValue, forKey: "outputFormats")
23 }
24 }
25
26 static var shouldSaveMp4: Bool {
27 outputFormats.shouldSaveMp4() || (shouldUseBackend && shouldUploadMp4)
28 }
29
30 static var shouldSaveGif: Bool {
31 outputFormats.shouldSaveGif() || (shouldUseBackend && shouldUploadGif)
32 }
33
34 static var shouldUploadGif: Bool {
35 backendFormat.shouldSaveGif()
36 }
37
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? {
47 get {
48 if let url = UserDefaults.standard.string(forKey: "backendUrl") {
49 return URL(string: url)
50 }
51 return nil
52 }
53 set {
54 UserDefaults.standard.setValue(newValue?.absoluteString, forKey: "backendUrl")
55 }
56 }
57
58 static var backendFormat: OutputFormatSetting {
59 get {
60 OutputFormatSetting(rawValue: UserDefaults.standard.integer(forKey: "backendFormat")) ?? .gifOnly
61 }
62 set {
63 UserDefaults.standard.setValue(newValue.rawValue, forKey: "backendFormat")
64 }
65 }
66
67 static var shouldKeepLocalFiles: Bool {
68 get {
69 if UserDefaults.standard.object(forKey: "keepFiles") == nil {
70 return true
71 } else {
72 return UserDefaults.standard.bool(forKey: "keepFiles")
73 }
74 }
75 set {
76 UserDefaults.standard.set(newValue, forKey: "keepFiles")
77 }
78 }
79
80 static var shouldAllowURLAutomation: Bool {
81 get {
82 UserDefaults.standard.bool(forKey: "allowURLAutomation")
83 }
84 set {
85 UserDefaults.standard.setValue(newValue, forKey: "allowURLAutomation")
86 }
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 }
105 }
106}