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