Serialize active profile immediately

Otherwise:

- Switch from former active profile A to B
- Connect to now active profile B
- Kill app
- Reopen app
- App shows connected to profile A

Because active profile was not saved immediately on switch.

Unnecessary now to also save it on background persist().
This commit is contained in:
Davide De Rosa 2022-04-22 10:03:11 +02:00
parent 7095791428
commit 322bdf2993
3 changed files with 7 additions and 1 deletions

View File

@ -84,7 +84,6 @@ extension OrganizerView {
}
private func persist() {
appManager.activeProfileId = profileManager.activeProfileId
profileManager.persist()
}
}

View File

@ -28,6 +28,8 @@ import PassepartoutCore
extension ProfileView {
struct VPNSection: View {
@ObservedObject private var appManager: AppManager
@ObservedObject private var profileManager: ProfileManager
@ObservedObject private var providerManager: ProviderManager
@ -51,6 +53,7 @@ extension ProfileView {
}
init(currentProfile: ObservableProfile, isLoaded: Bool) {
appManager = .shared
profileManager = .shared
providerManager = .shared
vpnManager = .shared
@ -109,6 +112,9 @@ extension ProfileView {
Button(L10n.Profile.Items.UseProfile.caption) {
withAnimation {
profileManager.activateCurrentProfile()
// IMPORTANT: save immediately to keep in sync with VPN status
appManager.activeProfileId = profileManager.activeProfileId
}
Task {
await vpnManager.disable()

View File

@ -153,6 +153,7 @@ extension AppManager: AppPreferences {
}
set {
defaults.set(newValue?.uuidString, forKey: DefaultKey.activeProfileId.rawValue)
defaults.synchronize()
objectWillChange.send()
}
}