Only tweak .isLoading if profile is not ready

Result is sync and immediate otherwise.
This commit is contained in:
Davide De Rosa 2022-05-02 11:15:59 +02:00
parent d3bd41b251
commit 20be153b1a
1 changed files with 8 additions and 18 deletions

View File

@ -270,33 +270,23 @@ extension ProfileManager {
pp_log.debug("Profile \(id) is already current profile") pp_log.debug("Profile \(id) is already current profile")
return return
} }
currentProfile.isLoading = true
if isExistingProfile(withId: currentProfile.value.id) { if isExistingProfile(withId: currentProfile.value.id) {
pp_log.info("Committing changes of former current profile \(currentProfile.value.logDescription)") pp_log.info("Committing changes of former current profile \(currentProfile.value.logDescription)")
saveCurrentProfile() saveCurrentProfile()
} }
do {
let result = try profileEx(withId: id) let result = try profileEx(withId: id)
pp_log.info("Current profile: \(result.profile.logDescription)") pp_log.info("Current profile: \(result.profile.logDescription)")
currentProfile.value = result.profile
if result.isReady { if result.isReady {
currentProfile.isLoading = false currentProfile.value = result.profile
} else { } else {
currentProfile.isLoading = true
Task { Task {
try await makeProfileReady(result.profile) try await makeProfileReady(result.profile)
currentProfile.value = result.profile
currentProfile.isLoading = false currentProfile.isLoading = false
} }
} }
} catch {
currentProfile.value = .placeholder
currentProfile.isLoading = false
throw error
}
}
public func isCurrentProfileLoading() -> Bool {
currentProfile.isLoading
} }
public func isCurrentProfileExisting() -> Bool { public func isCurrentProfileExisting() -> Bool {