]> git.r.bdr.sh - rbdr/captura/blob - Captura/Data/CapturaSettings.swift
85368ea0695240404ce303ef403f6ccd82bed62e
[rbdr/captura] / Captura / Data / CapturaSettings.swift
1 import Foundation
2
3 struct CapturaSettings {
4 static var frameRate: Int {
5 get {
6 UserDefaults.standard.integer(forKey: "frameRate")
7 }
8 set {
9 UserDefaults.standard.setValue(newValue, forKey: "frameRate")
10 }
11 }
12
13 static var outputFormats: OutputFormatSetting {
14 get {
15 OutputFormatSetting(rawValue: UserDefaults.standard.integer(forKey: "outputFormats")) ?? .all
16 }
17 set {
18 UserDefaults.standard.setValue(newValue.rawValue, forKey: "outputFormats")
19 }
20 }
21
22 static var shouldSaveMp4: Bool {
23 outputFormats.shouldSaveMp4() || (shouldUseBackend && shouldUploadMp4)
24 }
25
26 static var shouldSaveGif: Bool {
27 outputFormats.shouldSaveGif() || (shouldUseBackend && shouldUploadGif)
28 }
29
30 static var shouldUploadGif: Bool {
31 backendFormat.shouldSaveGif()
32 }
33
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? {
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")
51 }
52 }
53
54 static var backendFormat: OutputFormatSetting {
55 get {
56 OutputFormatSetting(rawValue: UserDefaults.standard.integer(forKey: "backendFormat")) ?? .gifOnly
57 }
58 set {
59 UserDefaults.standard.setValue(newValue.rawValue, forKey: "backendFormat")
60 }
61 }
62
63 static var shouldKeepLocalFiles: Bool {
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 }
92 }
93 }