Fix active profile not always cleared on deletion

Was only cleared if deleted profile was current profile.
This commit is contained in:
Davide De Rosa 2022-04-23 10:21:27 +02:00
parent dc66f514d9
commit 10537c5a29
1 changed files with 5 additions and 4 deletions

View File

@ -335,10 +335,6 @@ extension ProfileManager {
// IMPORTANT: invalidate current profile if deleted // IMPORTANT: invalidate current profile if deleted
if !currentProfile.value.isPlaceholder && !newHeaders.keys.contains(currentProfile.value.id) { if !currentProfile.value.isPlaceholder && !newHeaders.keys.contains(currentProfile.value.id) {
pp_log.info("\tCurrent profile deleted, invalidating...") pp_log.info("\tCurrent profile deleted, invalidating...")
if isCurrentProfileActive() {
pp_log.info("\tCurrent profile was also active, deactivating...")
activeProfileId = nil
}
currentProfile.value = .placeholder currentProfile.value = .placeholder
} }
@ -348,6 +344,11 @@ extension ProfileManager {
currentProfile.value = newProfile currentProfile.value = newProfile
} }
if let activeProfileId = activeProfileId, !newHeaders.keys.contains(activeProfileId) {
pp_log.info("\tActive profile was deleted")
self.activeProfileId = nil
}
// IMPORTANT: defer task to avoid recursive saves // IMPORTANT: defer task to avoid recursive saves
// FIXME: Core Data, not sure about this workaround // FIXME: Core Data, not sure about this workaround
Task { Task {