Skip to content

Commit

Permalink
Erase preferences of removed modules
Browse files Browse the repository at this point in the history
  • Loading branch information
keeshux committed Dec 10, 2024
1 parent da87c16 commit 62707c6
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ struct ProfileCoordinator: View {
@EnvironmentObject
private var iapManager: IAPManager

@EnvironmentObject
private var preferencesManager: PreferencesManager

let profileManager: ProfileManager

let profileEditor: ProfileEditor
Expand Down Expand Up @@ -133,7 +136,7 @@ private extension ProfileCoordinator {

// standard: always save, warn if purchase required
func onCommitEditingStandard() async throws {
let savedProfile = try await profileEditor.save(to: profileManager)
let savedProfile = try await profileEditor.save(to: profileManager, preferencesManager: preferencesManager)
do {
try iapManager.verify(savedProfile)
} catch AppError.ineligibleProfile(let requiredFeatures) {
Expand All @@ -151,7 +154,7 @@ private extension ProfileCoordinator {
paywallReason = .init(requiredFeatures)
return
}
try await profileEditor.save(to: profileManager)
try await profileEditor.save(to: profileManager, preferencesManager: preferencesManager)
onDismiss()
}

Expand Down
15 changes: 14 additions & 1 deletion Library/Sources/UILibrary/Business/ProfileEditor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -204,10 +204,23 @@ extension ProfileEditor {
}

@discardableResult
public func save(to profileManager: ProfileManager) async throws -> Profile {
public func save(to profileManager: ProfileManager, preferencesManager: PreferencesManager) async throws -> Profile {
do {
let newProfile = try build()
try await profileManager.save(newProfile, isLocal: true, remotelyShared: isShared)

removedModules.keys.forEach {
do {
pp_log(.App.profiles, .info, "Erase preferences for removed module \($0)")
let repository = try preferencesManager.preferencesRepository(forModuleWithId: $0)
repository.erase()
try repository.save()
} catch {
pp_log(.App.profiles, .error, "Unable to erase preferences for removed module \($0): \(error)")
}
}
removedModules.removeAll()

return newProfile
} catch {
pp_log(.App.profiles, .fault, "Unable to save edited profile: \(error)")
Expand Down

0 comments on commit 62707c6

Please sign in to comment.