From abe4c779b8d95b99b7e7332abe92b7eda0b0a97f Mon Sep 17 00:00:00 2001 From: Davide Date: Thu, 7 Nov 2024 01:48:39 +0100 Subject: [PATCH] Improve startup time (#822) Profiles were loaded after reading receipt, which took at least a second on iOS. Potential regression from #821 --- .../Business/ExtendedTunnel.swift | 4 ++++ .../UILibrary/Business/AppContext.swift | 19 ++++++++++++------- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/Passepartout/Library/Sources/CommonLibrary/Business/ExtendedTunnel.swift b/Passepartout/Library/Sources/CommonLibrary/Business/ExtendedTunnel.swift index 531438b2..29ab3455 100644 --- a/Passepartout/Library/Sources/CommonLibrary/Business/ExtendedTunnel.swift +++ b/Passepartout/Library/Sources/CommonLibrary/Business/ExtendedTunnel.swift @@ -99,20 +99,24 @@ extension ExtendedTunnel { } public func prepare(purge: Bool) async throws { + pp_log(.app, .notice, "Prepare tunnel and purge stale data (\(purge))...") try await tunnel.prepare(purge: purge) } public func install(_ profile: Profile) async throws { + pp_log(.app, .notice, "Install profile \(profile.id)...") let newProfile = try processedProfile(profile) try await tunnel.install(newProfile, connect: false, title: processedTitle) } public func connect(with profile: Profile) async throws { + pp_log(.app, .notice, "Connect to profile \(profile.id)...") let newProfile = try processedProfile(profile) try await tunnel.install(newProfile, connect: true, title: processedTitle) } public func disconnect() async throws { + pp_log(.app, .notice, "Disconnect...") try await tunnel.disconnect() } diff --git a/Passepartout/Library/Sources/UILibrary/Business/AppContext.swift b/Passepartout/Library/Sources/UILibrary/Business/AppContext.swift index 2113be98..bb23ed29 100644 --- a/Passepartout/Library/Sources/UILibrary/Business/AppContext.swift +++ b/Passepartout/Library/Sources/UILibrary/Business/AppContext.swift @@ -67,14 +67,19 @@ public final class AppContext: ObservableObject { return } isActivating = true + pp_log(.app, .notice, "Application became active") Task { - do { - pp_log(.app, .notice, "Application became active") - await iapManager.reloadReceipt() - pp_log(.app, .notice, "Prepare tunnel and purge stale data...") - try await tunnel.prepare(purge: true) - } catch { - pp_log(.app, .fault, "Unable to prepare tunnel: \(error)") + await withTaskGroup(of: Void.self) { group in + group.addTask { + do { + try await self.tunnel.prepare(purge: true) + } catch { + pp_log(.app, .fault, "Unable to prepare tunnel: \(error)") + } + } + group.addTask { + await self.iapManager.reloadReceipt() + } } isActivating = false }