From 85129f17af395d6ed76e020340baea1fcee81a2e Mon Sep 17 00:00:00 2001 From: Davide De Rosa Date: Fri, 17 Jun 2022 09:32:56 +0200 Subject: [PATCH] Prefix store keys with "Passepartout." domain Also remove stale preferences from early betas after migrating relevant ones. Extend KeyValueStore with removeValue() for this purpose. --- .../App/Constants/AppPreference.swift | 2 +- .../Managers/PersistenceManager.swift | 2 +- .../Managers/UpgradeManager+Migrations.swift | 34 ++++++++++++++++++- .../Managers/UpgradeManager.swift | 2 +- .../Managers/VPNManager.swift | 2 +- .../Managers/ProfileManager.swift | 2 +- .../{Models => Reusable}/KeyValueStore.swift | 2 ++ .../UserDefaultsStore.swift | 4 +++ 8 files changed, 44 insertions(+), 6 deletions(-) rename PassepartoutCore/Sources/PassepartoutUtils/{Models => Reusable}/KeyValueStore.swift (95%) rename PassepartoutCore/Sources/PassepartoutUtils/{Models => Reusable}/UserDefaultsStore.swift (90%) diff --git a/Passepartout/App/Constants/AppPreference.swift b/Passepartout/App/Constants/AppPreference.swift index 916a2b72..5dbcf2d4 100644 --- a/Passepartout/App/Constants/AppPreference.swift +++ b/Passepartout/App/Constants/AppPreference.swift @@ -32,6 +32,6 @@ enum AppPreference: String, KeyStoreDomainLocation { case didHandleSubreddit var domain: String { - "App" + "Passepartout.App" } } diff --git a/PassepartoutCore/Sources/PassepartoutCore/Managers/PersistenceManager.swift b/PassepartoutCore/Sources/PassepartoutCore/Managers/PersistenceManager.swift index 81d93d79..7054ba0b 100644 --- a/PassepartoutCore/Sources/PassepartoutCore/Managers/PersistenceManager.swift +++ b/PassepartoutCore/Sources/PassepartoutCore/Managers/PersistenceManager.swift @@ -68,7 +68,7 @@ private extension PersistenceManager { case persistenceAuthor var domain: String { - "PersistenceManager" + "Passepartout.PersistenceManager" } } } diff --git a/PassepartoutCore/Sources/PassepartoutCore/Managers/UpgradeManager+Migrations.swift b/PassepartoutCore/Sources/PassepartoutCore/Managers/UpgradeManager+Migrations.swift index 06cd4a42..3610bdb9 100644 --- a/PassepartoutCore/Sources/PassepartoutCore/Managers/UpgradeManager+Migrations.swift +++ b/PassepartoutCore/Sources/PassepartoutCore/Managers/UpgradeManager+Migrations.swift @@ -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) + } } } diff --git a/PassepartoutCore/Sources/PassepartoutCore/Managers/UpgradeManager.swift b/PassepartoutCore/Sources/PassepartoutCore/Managers/UpgradeManager.swift index 220b2854..1458da96 100644 --- a/PassepartoutCore/Sources/PassepartoutCore/Managers/UpgradeManager.swift +++ b/PassepartoutCore/Sources/PassepartoutCore/Managers/UpgradeManager.swift @@ -89,7 +89,7 @@ private extension UpgradeManager { case didMigrateToV2 var domain: String { - "UpgradeManager" + "Passepartout.UpgradeManager" } } } diff --git a/PassepartoutCore/Sources/PassepartoutCore/Managers/VPNManager.swift b/PassepartoutCore/Sources/PassepartoutCore/Managers/VPNManager.swift index f102e35b..c7a709c1 100644 --- a/PassepartoutCore/Sources/PassepartoutCore/Managers/VPNManager.swift +++ b/PassepartoutCore/Sources/PassepartoutCore/Managers/VPNManager.swift @@ -298,7 +298,7 @@ private extension VPNManager { case masksPrivateData var domain: String { - "VPNManager" + "Passepartout.VPNManager" } } } diff --git a/PassepartoutCore/Sources/PassepartoutProfiles/Managers/ProfileManager.swift b/PassepartoutCore/Sources/PassepartoutProfiles/Managers/ProfileManager.swift index 961c4fee..17fdaca4 100644 --- a/PassepartoutCore/Sources/PassepartoutProfiles/Managers/ProfileManager.swift +++ b/PassepartoutCore/Sources/PassepartoutProfiles/Managers/ProfileManager.swift @@ -484,7 +484,7 @@ private extension ProfileManager { case activeProfileId var domain: String { - "ProfileManager" + "Passepartout.ProfileManager" } } } diff --git a/PassepartoutCore/Sources/PassepartoutUtils/Models/KeyValueStore.swift b/PassepartoutCore/Sources/PassepartoutUtils/Reusable/KeyValueStore.swift similarity index 95% rename from PassepartoutCore/Sources/PassepartoutUtils/Models/KeyValueStore.swift rename to PassepartoutCore/Sources/PassepartoutUtils/Reusable/KeyValueStore.swift index 652659d1..ef4269d9 100644 --- a/PassepartoutCore/Sources/PassepartoutUtils/Models/KeyValueStore.swift +++ b/PassepartoutCore/Sources/PassepartoutUtils/Reusable/KeyValueStore.swift @@ -43,4 +43,6 @@ public protocol KeyValueStore { func setValue(_ value: V, forLocation location: L) func value(forLocation location: L) -> V? + + func removeValue(forLocation location: L) } diff --git a/PassepartoutCore/Sources/PassepartoutUtils/Models/UserDefaultsStore.swift b/PassepartoutCore/Sources/PassepartoutUtils/Reusable/UserDefaultsStore.swift similarity index 90% rename from PassepartoutCore/Sources/PassepartoutUtils/Models/UserDefaultsStore.swift rename to PassepartoutCore/Sources/PassepartoutUtils/Reusable/UserDefaultsStore.swift index 941b831c..5dab0eeb 100644 --- a/PassepartoutCore/Sources/PassepartoutUtils/Models/UserDefaultsStore.swift +++ b/PassepartoutCore/Sources/PassepartoutUtils/Reusable/UserDefaultsStore.swift @@ -39,4 +39,8 @@ public struct UserDefaultsStore: KeyValueStore { public func value(forLocation location: L) -> V? { defaults.value(forKey: location.key) as? V } + + public func removeValue(forLocation location: L) { + defaults.removeObject(forKey: location.key) + } }