2024-06-19 15:15:27 +00:00
|
|
|
import Foundation
|
|
|
|
|
|
|
|
// Wrapper
|
|
|
|
@propertyWrapper
|
|
|
|
struct Storage<T> {
|
|
|
|
private let key: String
|
|
|
|
private let defaultValue: T
|
|
|
|
|
|
|
|
init(key: String, defaultValue: T) {
|
|
|
|
self.key = key
|
|
|
|
self.defaultValue = defaultValue
|
|
|
|
}
|
|
|
|
|
|
|
|
var wrappedValue: T {
|
|
|
|
get {
|
|
|
|
// Read value from UserDefaults
|
|
|
|
UserDefaults.standard.object(forKey: key) as? T ?? defaultValue
|
|
|
|
}
|
|
|
|
set {
|
|
|
|
// Set value to UserDefaults
|
|
|
|
UserDefaults.standard.set(newValue, forKey: key)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Storage
|
2024-09-16 15:58:28 +00:00
|
|
|
private let kOmemoDeviceId = "conversations.classic.user.defaults.omemoDeviceId"
|
2024-09-19 15:14:05 +00:00
|
|
|
private let kSecureChatsByDefault = "conversations.classic.user.defaults.secureChatsByDefault"
|
2024-06-19 15:15:27 +00:00
|
|
|
|
|
|
|
enum UserSettings {
|
2024-09-16 15:58:28 +00:00
|
|
|
@Storage(key: kOmemoDeviceId, defaultValue: 0)
|
|
|
|
static var omemoDeviceId: UInt32
|
2024-09-19 15:14:05 +00:00
|
|
|
|
|
|
|
@Storage(key: kSecureChatsByDefault, defaultValue: false)
|
|
|
|
static var secureChatsByDefault: Bool
|
2024-10-07 16:58:02 +00:00
|
|
|
|
|
|
|
static func reset() {
|
|
|
|
omemoDeviceId = 0
|
|
|
|
secureChatsByDefault = false
|
|
|
|
}
|
2024-06-19 15:15:27 +00:00
|
|
|
}
|