]>
Commit | Line | Data |
---|---|---|
5802c153 RBR |
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 | */ | |
c9b9e1d6 RBR |
17 | import Foundation |
18 | ||
19 | struct CapturaSettings { | |
20 | static var frameRate: Int { | |
ba17de89 | 21 | get { |
e42019cd | 22 | if UserDefaults.standard.object(forKey: "frameRate") == nil { |
377442f2 RBR |
23 | return 10 |
24 | } else { | |
e42019cd | 25 | return min(10, max(4, UserDefaults.standard.integer(forKey: "frameRate"))) |
377442f2 | 26 | } |
ba17de89 RBR |
27 | } |
28 | set { | |
e42019cd | 29 | UserDefaults.standard.setValue(newValue, forKey: "frameRate") |
ba17de89 | 30 | } |
c9b9e1d6 RBR |
31 | } |
32 | ||
33 | static var outputFormats: OutputFormatSetting { | |
ba17de89 | 34 | get { |
e42019cd | 35 | OutputFormatSetting(rawValue: UserDefaults.standard.integer(forKey: "outputFormats")) ?? .all |
ba17de89 RBR |
36 | } |
37 | set { | |
e42019cd | 38 | UserDefaults.standard.setValue(newValue.rawValue, forKey: "outputFormats") |
ba17de89 | 39 | } |
c9b9e1d6 RBR |
40 | } |
41 | ||
42 | static var shouldSaveMp4: Bool { | |
533cd932 | 43 | outputFormats.shouldSaveMp4() || (shouldUseBackend && shouldUploadMp4) |
c9b9e1d6 RBR |
44 | } |
45 | ||
46 | static var shouldSaveGif: Bool { | |
533cd932 | 47 | outputFormats.shouldSaveGif() || (shouldUseBackend && shouldUploadGif) |
c9b9e1d6 RBR |
48 | } |
49 | ||
533cd932 RBR |
50 | static var shouldUploadGif: Bool { |
51 | backendFormat.shouldSaveGif() | |
52 | } | |
c9b9e1d6 | 53 | |
533cd932 RBR |
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? { | |
ba17de89 | 63 | get { |
e42019cd | 64 | if let url = UserDefaults.standard.string(forKey: "backendUrl") { |
ba17de89 RBR |
65 | return URL(string: url) |
66 | } | |
67 | return nil | |
68 | } | |
69 | set { | |
e42019cd | 70 | UserDefaults.standard.setValue(newValue?.absoluteString, forKey: "backendUrl") |
c9b9e1d6 | 71 | } |
533cd932 RBR |
72 | } |
73 | ||
74 | static var backendFormat: OutputFormatSetting { | |
ba17de89 | 75 | get { |
e42019cd | 76 | OutputFormatSetting(rawValue: UserDefaults.standard.integer(forKey: "backendFormat")) ?? .gifOnly |
ba17de89 RBR |
77 | } |
78 | set { | |
e42019cd | 79 | UserDefaults.standard.setValue(newValue.rawValue, forKey: "backendFormat") |
ba17de89 | 80 | } |
533cd932 RBR |
81 | } |
82 | ||
83 | static var shouldKeepLocalFiles: Bool { | |
ba17de89 | 84 | get { |
e42019cd | 85 | if UserDefaults.standard.object(forKey: "keepFiles") == nil { |
377442f2 RBR |
86 | return true |
87 | } else { | |
e42019cd | 88 | return UserDefaults.standard.bool(forKey: "keepFiles") |
377442f2 | 89 | } |
ba17de89 RBR |
90 | } |
91 | set { | |
e42019cd | 92 | UserDefaults.standard.set(newValue, forKey: "keepFiles") |
ba17de89 RBR |
93 | } |
94 | } | |
95 | ||
96 | static var shouldAllowURLAutomation: Bool { | |
377442f2 | 97 | get { |
e42019cd | 98 | UserDefaults.standard.bool(forKey: "allowURLAutomation") |
377442f2 RBR |
99 | } |
100 | set { | |
e42019cd | 101 | UserDefaults.standard.setValue(newValue, forKey: "allowURLAutomation") |
377442f2 | 102 | } |
ba17de89 RBR |
103 | } |
104 | ||
105 | static func apply(_ config: ConfigureAction) { | |
106 | if let fps = config.fps { | |
107 | frameRate = fps | |
108 | } | |
109 | if let outputs = config.outputs { | |
110 | outputFormats = outputs | |
111 | } | |
112 | if let newBackend = config.backend { | |
113 | backend = newBackend | |
114 | } | |
115 | if let backendOutput = config.backendOutput { | |
116 | backendFormat = backendOutput | |
117 | } | |
118 | if let keepLocalFiles = config.keepLocalFiles { | |
119 | shouldKeepLocalFiles = keepLocalFiles | |
120 | } | |
c9b9e1d6 RBR |
121 | } |
122 | } |