Save current profile one way

Skip updating currentProfile.value when intentionally saving
current profile.
This commit is contained in:
Davide De Rosa 2022-04-28 16:58:36 +02:00
parent 03cb05da7e
commit 56fa161e92

View File

@ -185,7 +185,7 @@ extension ProfileManager {
return profile
}
public func saveProfile(_ profile: Profile, isActive: Bool?) {
public func saveProfile(_ profile: Profile, isActive: Bool?, updateIfCurrent: Bool = true) {
guard !profile.isPlaceholder else {
assertionFailure("Placeholder")
return
@ -204,8 +204,8 @@ extension ProfileManager {
}
}
// IMPORTANT: refresh live copy if just saved
if isCurrentProfile(profile.id) {
// IMPORTANT: refresh live copy if just saved (e.g. via intents)
if updateIfCurrent && isCurrentProfile(profile.id) {
pp_log.info("Saved profile is also current profile, updating...")
currentProfile.value = profile
}
@ -309,14 +309,7 @@ extension ProfileManager {
}
public func saveCurrentProfile() {
guard !currentProfile.value.isPlaceholder else {
pp_log.debug("No current profile or deleted, not persisting")
return
}
saveProfile(
currentProfile.value,
isActive: currentProfile.value.id == activeProfileId
)
saveProfile(currentProfile.value, isActive: nil, updateIfCurrent: false)
}
}