Ignore non-existing active profile

This commit is contained in:
Davide De Rosa 2022-05-01 20:39:24 +02:00
parent 472b5e4b41
commit acbc1980f9
2 changed files with 7 additions and 3 deletions

View File

@ -139,8 +139,7 @@ class AppContext {
profileManager.observeUpdates()
vpnManager.observeUpdates()
if let activeProfileId = appManager.activeProfileId {
profileManager.setActiveProfileId(activeProfileId)
if let activeProfileId = appManager.activeProfileId, profileManager.setActiveProfileId(activeProfileId) {
do {
try profileManager.loadCurrentProfile(withId: activeProfileId)
} catch {

View File

@ -86,8 +86,13 @@ public class ProfileManager: ObservableObject {
currentProfile = ObservableProfile()
}
public func setActiveProfileId(_ id: UUID) {
public func setActiveProfileId(_ id: UUID) -> Bool {
guard isExistingProfile(withId: id) else {
pp_log.warning("Active profile \(id) does not exist, ignoring")
return false
}
activeProfileId = id
return true
}
}