]> git.r.bdr.sh - rbdr/captura/blame - Captura/Data/CapturaSettings.swift
Adds configure support for URLs
[rbdr/captura] / Captura / Data / CapturaSettings.swift
CommitLineData
c9b9e1d6
RBR
1import Foundation
2
3struct CapturaSettings {
4 static var frameRate: Int {
ba17de89 5 get {
e42019cd 6 if UserDefaults.standard.object(forKey: "frameRate") == nil {
377442f2
RBR
7 return 10
8 } else {
e42019cd 9 return min(10, max(4, UserDefaults.standard.integer(forKey: "frameRate")))
377442f2 10 }
ba17de89
RBR
11 }
12 set {
e42019cd 13 UserDefaults.standard.setValue(newValue, forKey: "frameRate")
ba17de89 14 }
c9b9e1d6
RBR
15 }
16
17 static var outputFormats: OutputFormatSetting {
ba17de89 18 get {
e42019cd 19 OutputFormatSetting(rawValue: UserDefaults.standard.integer(forKey: "outputFormats")) ?? .all
ba17de89
RBR
20 }
21 set {
e42019cd 22 UserDefaults.standard.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 {
e42019cd 48 if let url = UserDefaults.standard.string(forKey: "backendUrl") {
ba17de89
RBR
49 return URL(string: url)
50 }
51 return nil
52 }
53 set {
e42019cd 54 UserDefaults.standard.setValue(newValue?.absoluteString, forKey: "backendUrl")
c9b9e1d6 55 }
533cd932
RBR
56 }
57
58 static var backendFormat: OutputFormatSetting {
ba17de89 59 get {
e42019cd 60 OutputFormatSetting(rawValue: UserDefaults.standard.integer(forKey: "backendFormat")) ?? .gifOnly
ba17de89
RBR
61 }
62 set {
e42019cd 63 UserDefaults.standard.setValue(newValue.rawValue, forKey: "backendFormat")
ba17de89 64 }
533cd932
RBR
65 }
66
67 static var shouldKeepLocalFiles: Bool {
ba17de89 68 get {
e42019cd 69 if UserDefaults.standard.object(forKey: "keepFiles") == nil {
377442f2
RBR
70 return true
71 } else {
e42019cd 72 return UserDefaults.standard.bool(forKey: "keepFiles")
377442f2 73 }
ba17de89
RBR
74 }
75 set {
e42019cd 76 UserDefaults.standard.set(newValue, forKey: "keepFiles")
ba17de89
RBR
77 }
78 }
79
80 static var shouldAllowURLAutomation: Bool {
377442f2 81 get {
e42019cd 82 UserDefaults.standard.bool(forKey: "allowURLAutomation")
377442f2
RBR
83 }
84 set {
e42019cd 85 UserDefaults.standard.setValue(newValue, forKey: "allowURLAutomation")
377442f2 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}