]> git.r.bdr.sh - rbdr/captura/blame_incremental - Captura/Data/CapturaSettings.swift
Format the code
[rbdr/captura] / Captura / Data / CapturaSettings.swift
... / ...
CommitLineData
1/*
2 Copyright (C) 2024 Rubén Beltrán del Río
3
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see https://captura.tranquil.systems.
16 */
17import Foundation
18
19struct CapturaSettings {
20 static var frameRate: Int {
21 get {
22 if UserDefaults.standard.object(forKey: "frameRate") == nil {
23 return 10
24 } else {
25 return min(10, max(4, UserDefaults.standard.integer(forKey: "frameRate")))
26 }
27 }
28 set {
29 UserDefaults.standard.setValue(newValue, forKey: "frameRate")
30 }
31 }
32
33 static var outputFormats: OutputFormatSetting {
34 get {
35 OutputFormatSetting(rawValue: UserDefaults.standard.integer(forKey: "outputFormats")) ?? .all
36 }
37 set {
38 UserDefaults.standard.setValue(newValue.rawValue, forKey: "outputFormats")
39 }
40 }
41
42 static var shouldSaveMp4: Bool {
43 outputFormats.shouldSaveMp4() || (shouldUseBackend && shouldUploadMp4)
44 }
45
46 static var shouldSaveGif: Bool {
47 outputFormats.shouldSaveGif() || (shouldUseBackend && shouldUploadGif)
48 }
49
50 static var shouldUploadGif: Bool {
51 backendFormat.shouldSaveGif()
52 }
53
54 static var shouldUploadMp4: Bool {
55 backendFormat.shouldSaveMp4()
56 }
57
58 static var shouldUseBackend: Bool {
59 backend != nil
60 }
61
62 static var backend: URL? {
63 get {
64 if let url = UserDefaults.standard.string(forKey: "backendUrl") {
65 return URL(string: url)
66 }
67 return nil
68 }
69 set {
70 UserDefaults.standard.setValue(newValue?.absoluteString, forKey: "backendUrl")
71 }
72 }
73
74 static var backendFormat: OutputFormatSetting {
75 get {
76 OutputFormatSetting(rawValue: UserDefaults.standard.integer(forKey: "backendFormat"))
77 ?? .gifOnly
78 }
79 set {
80 UserDefaults.standard.setValue(newValue.rawValue, forKey: "backendFormat")
81 }
82 }
83
84 static var shouldKeepLocalFiles: Bool {
85 get {
86 if UserDefaults.standard.object(forKey: "keepFiles") == nil {
87 return true
88 } else {
89 return UserDefaults.standard.bool(forKey: "keepFiles")
90 }
91 }
92 set {
93 UserDefaults.standard.set(newValue, forKey: "keepFiles")
94 }
95 }
96
97 static var shouldAllowURLAutomation: Bool {
98 get {
99 UserDefaults.standard.bool(forKey: "allowURLAutomation")
100 }
101 set {
102 UserDefaults.standard.setValue(newValue, forKey: "allowURLAutomation")
103 }
104 }
105
106 static func apply(_ config: ConfigureAction) {
107 if let fps = config.fps {
108 frameRate = fps
109 }
110 if let outputs = config.outputs {
111 outputFormats = outputs
112 }
113 if let newBackend = config.backend {
114 backend = newBackend
115 }
116 if let backendOutput = config.backendOutput {
117 backendFormat = backendOutput
118 }
119 if let keepLocalFiles = config.keepLocalFiles {
120 shouldKeepLocalFiles = keepLocalFiles
121 }
122 }
123}