Prefix store keys with "Passepartout." domain

Also remove stale preferences from early betas after migrating
relevant ones.

Extend KeyValueStore with removeValue() for this purpose.
This commit is contained in:
Davide De Rosa 2022-06-17 09:32:56 +02:00
parent 02a9db057f
commit 85129f17af
8 changed files with 44 additions and 6 deletions

View File

@ -32,6 +32,6 @@ enum AppPreference: String, KeyStoreDomainLocation {
case didHandleSubreddit
var domain: String {
"App"
"Passepartout.App"
}
}

View File

@ -68,7 +68,7 @@ private extension PersistenceManager {
case persistenceAuthor
var domain: String {
"PersistenceManager"
"Passepartout.PersistenceManager"
}
}
}

View File

@ -35,9 +35,37 @@ private typealias Map = [String: Any]
// MARK: Migrate old store
extension UpgradeManager {
fileprivate enum LegacyStoreKey: String, KeyStoreLocation {
fileprivate enum LegacyStoreKey: String, KeyStoreLocation, CaseIterable {
case activeProfileId
case launchesOnLogin
case isStatusMenuEnabled
case isShowingFavorites
case confirmsQuit
case logFormat
case tunnelLogFormat
case masksPrivateData
case didHandleSubreddit
case persistenceAuthor
case didMigrateToV2
case other1 = "MasksPrivateData"
case other2 = "DidHandleSubreddit"
case other3 = "Convenience.Reviewer.LastVersion"
case other4 = "didMigrateKeychainContext"
var key: String {
rawValue
}
@ -50,6 +78,10 @@ extension UpgradeManager {
}
didMigrateToV2 = legacyDidMigrateToV2
}
LegacyStoreKey.allCases.forEach {
store.removeValue(forLocation: $0)
}
}
}

View File

@ -89,7 +89,7 @@ private extension UpgradeManager {
case didMigrateToV2
var domain: String {
"UpgradeManager"
"Passepartout.UpgradeManager"
}
}
}

View File

@ -298,7 +298,7 @@ private extension VPNManager {
case masksPrivateData
var domain: String {
"VPNManager"
"Passepartout.VPNManager"
}
}
}

View File

@ -484,7 +484,7 @@ private extension ProfileManager {
case activeProfileId
var domain: String {
"ProfileManager"
"Passepartout.ProfileManager"
}
}
}

View File

@ -43,4 +43,6 @@ public protocol KeyValueStore {
func setValue<L: KeyStoreLocation, V>(_ value: V, forLocation location: L)
func value<L: KeyStoreLocation, V>(forLocation location: L) -> V?
func removeValue<L: KeyStoreLocation>(forLocation location: L)
}

View File

@ -39,4 +39,8 @@ public struct UserDefaultsStore: KeyValueStore {
public func value<L: KeyStoreLocation, V>(forLocation location: L) -> V? {
defaults.value(forKey: location.key) as? V
}
public func removeValue<L: KeyStoreLocation>(forLocation location: L) {
defaults.removeObject(forKey: location.key)
}
}