Revert async loadCurrentProfile()

Make action sync, but internally async (makeProfileReady). If not
doing so, UI on launch will not be able to show active profile
immediately. WelcomeView would appear for a moment.

Observe isReloadingCurrentProfile.

See 2b1efb8fec
This commit is contained in:
Davide De Rosa 2022-04-28 18:56:28 +02:00
parent 1ef2b8c7a7
commit 2c2e794b00
4 changed files with 19 additions and 24 deletions

View File

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

View File

@ -158,13 +158,11 @@ extension OrganizerView.ProfilesList {
}
private func presentProfile(withId id: UUID) {
Task {
isPresentingProfile = true
do {
try await profileManager.loadCurrentProfile(withId: id)
} catch {
pp_log.error("Unable to load profile: \(error)")
}
isPresentingProfile = true
do {
try profileManager.loadCurrentProfile(withId: id)
} catch {
pp_log.error("Unable to load profile: \(error)")
}
}

View File

@ -212,12 +212,10 @@ extension ProfileView {
return
}
if switchCurrentProfile {
Task {
do {
try await profileManager.loadCurrentProfile(withId: copy.id)
} catch {
pp_log.warning("Unable to load profile duplicate: \(error)")
}
do {
try profileManager.loadCurrentProfile(withId: copy.id)
} catch {
pp_log.warning("Unable to load profile duplicate: \(error)")
}
}
}

View File

@ -254,7 +254,7 @@ extension ProfileManager {
// MARK: Observation
extension ProfileManager {
public func loadCurrentProfile(withId id: UUID) async throws {
public func loadCurrentProfile(withId id: UUID) throws {
guard !isLoadingCurrentProfile else {
pp_log.warning("Already loading another profile")
return
@ -272,13 +272,14 @@ extension ProfileManager {
let result = try profileEx(withId: id)
pp_log.info("Current profile: \(result.profile.logDescription)")
currentProfile.value = result.profile
if result.isReady {
currentProfile.value = result.profile
isLoadingCurrentProfile = false
} else {
try await makeProfileReady(result.profile)
currentProfile.value = result.profile
isLoadingCurrentProfile = false
Task {
try await makeProfileReady(result.profile)
isLoadingCurrentProfile = false
}
}
} catch {
currentProfile.value = .placeholder