Set activeProfileId immediately

Otherwise on app launch, active profile is rendered in 2 steps.
This commit is contained in:
Davide De Rosa 2022-04-28 17:52:16 +02:00
parent 56fa161e92
commit 1ef2b8c7a7
2 changed files with 6 additions and 10 deletions

View File

@ -140,9 +140,10 @@ class AppContext {
vpnManager.observeUpdates()
if let activeProfileId = appManager.activeProfileId {
profileManager.setActiveProfileId(activeProfileId)
Task {
do {
try await profileManager.loadActiveProfile(withId: activeProfileId)
try await profileManager.loadCurrentProfile(withId: activeProfileId)
} catch {
pp_log.warning("Unable to load active profile: \(error)")
}

View File

@ -87,6 +87,10 @@ public class ProfileManager: ObservableObject {
currentProfile = ObservableProfile()
}
public func setActiveProfileId(_ id: UUID) {
activeProfileId = id
}
}
// MARK: Index
@ -250,15 +254,6 @@ extension ProfileManager {
// MARK: Observation
extension ProfileManager {
public func loadActiveProfile(withId id: UUID) async throws {
guard isExistingProfile(withId: id) else {
pp_log.warning("Active profile \(id) does not exist, ignoring")
return
}
activeProfileId = id
try await loadCurrentProfile(withId: id)
}
public func loadCurrentProfile(withId id: UUID) async throws {
guard !isLoadingCurrentProfile else {
pp_log.warning("Already loading another profile")