From 20be153b1acd9e48f303d1aef6f092ec38c1c44f Mon Sep 17 00:00:00 2001 From: Davide De Rosa Date: Mon, 2 May 2022 11:15:59 +0200 Subject: [PATCH] Only tweak .isLoading if profile is not ready Result is sync and immediate otherwise. --- .../Managers/ProfileManager.swift | 26 ++++++------------- 1 file changed, 8 insertions(+), 18 deletions(-) diff --git a/PassepartoutCore/Sources/PassepartoutProfiles/Managers/ProfileManager.swift b/PassepartoutCore/Sources/PassepartoutProfiles/Managers/ProfileManager.swift index 34bdd80d..bcec14be 100644 --- a/PassepartoutCore/Sources/PassepartoutProfiles/Managers/ProfileManager.swift +++ b/PassepartoutCore/Sources/PassepartoutProfiles/Managers/ProfileManager.swift @@ -270,35 +270,25 @@ extension ProfileManager { pp_log.debug("Profile \(id) is already current profile") return } - currentProfile.isLoading = true if isExistingProfile(withId: currentProfile.value.id) { pp_log.info("Committing changes of former current profile \(currentProfile.value.logDescription)") saveCurrentProfile() } - do { - let result = try profileEx(withId: id) - pp_log.info("Current profile: \(result.profile.logDescription)") + let result = try profileEx(withId: id) + pp_log.info("Current profile: \(result.profile.logDescription)") + if result.isReady { currentProfile.value = result.profile - if result.isReady { + } else { + currentProfile.isLoading = true + Task { + try await makeProfileReady(result.profile) + currentProfile.value = result.profile currentProfile.isLoading = false - } else { - Task { - try await makeProfileReady(result.profile) - currentProfile.isLoading = false - } } - } catch { - currentProfile.value = .placeholder - currentProfile.isLoading = false - throw error } } - public func isCurrentProfileLoading() -> Bool { - currentProfile.isLoading - } - public func isCurrentProfileExisting() -> Bool { isExistingProfile(withId: currentProfile.value.id) }