session-ios/SignalServiceKit/src/Loki/Utilities/LKUserDefaults.swift

66 lines
2.0 KiB
Swift
Raw Normal View History

2020-02-19 06:45:38 +01:00
import Foundation
public enum LKUserDefaults {
public enum Bool : Swift.String {
case hasLaunchedOnce
2020-05-19 01:12:41 +02:00
case hasSeenGIFMetadataWarning
2020-07-30 07:19:19 +02:00
case hasSeenMultiDeviceRemovalSheet
2020-02-19 06:45:38 +01:00
case hasSeenOpenGroupSuggestionSheet
case hasViewedSeed
/// Whether the device was unlinked as a slave device (used to notify the user on the landing screen).
case wasUnlinked
2020-03-27 05:08:26 +01:00
case isUsingFullAPNs
2020-02-19 06:45:38 +01:00
}
2020-02-20 06:59:05 +01:00
public enum Date : Swift.String {
case lastProfilePictureUpload
}
2020-02-19 06:45:38 +01:00
public enum Double : Swift.String {
case lastDeviceTokenUpload = "lastDeviceTokenUploadTime"
}
public enum String {
case slaveDeviceName(Swift.String)
case deviceToken
/// `nil` if this is a master device or if the user hasn't linked a device.
case masterHexEncodedPublicKey
public var key: Swift.String {
switch self {
case .slaveDeviceName(let hexEncodedPublicKey): return "\(hexEncodedPublicKey)_display_name"
case .deviceToken: return "deviceToken"
case .masterHexEncodedPublicKey: return "masterDeviceHexEncodedPublicKey"
}
}
}
}
public extension UserDefaults {
public subscript(bool: LKUserDefaults.Bool) -> Bool {
get { return self.bool(forKey: bool.rawValue) }
set { set(newValue, forKey: bool.rawValue) }
}
2020-02-20 06:59:05 +01:00
public subscript(date: LKUserDefaults.Date) -> Date? {
get { return self.object(forKey: date.rawValue) as? Date }
set { set(newValue, forKey: date.rawValue) }
}
2020-02-19 06:45:38 +01:00
public subscript(double: LKUserDefaults.Double) -> Double {
get { return self.double(forKey: double.rawValue) }
set { set(newValue, forKey: double.rawValue) }
}
public subscript(string: LKUserDefaults.String) -> String? {
get { return self.string(forKey: string.key) }
set { set(newValue, forKey: string.key) }
}
public var isMasterDevice: Bool {
return (self[.masterHexEncodedPublicKey] == nil)
}
}