Improve startup time (#822)

Profiles were loaded after reading receipt, which took at least a second
on iOS.

Potential regression from #821
This commit is contained in:
Davide 2024-11-07 01:48:39 +01:00 committed by GitHub
parent a1b7679fb0
commit abe4c779b8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 16 additions and 7 deletions

View File

@ -99,20 +99,24 @@ extension ExtendedTunnel {
} }
public func prepare(purge: Bool) async throws { public func prepare(purge: Bool) async throws {
pp_log(.app, .notice, "Prepare tunnel and purge stale data (\(purge))...")
try await tunnel.prepare(purge: purge) try await tunnel.prepare(purge: purge)
} }
public func install(_ profile: Profile) async throws { public func install(_ profile: Profile) async throws {
pp_log(.app, .notice, "Install profile \(profile.id)...")
let newProfile = try processedProfile(profile) let newProfile = try processedProfile(profile)
try await tunnel.install(newProfile, connect: false, title: processedTitle) try await tunnel.install(newProfile, connect: false, title: processedTitle)
} }
public func connect(with profile: Profile) async throws { public func connect(with profile: Profile) async throws {
pp_log(.app, .notice, "Connect to profile \(profile.id)...")
let newProfile = try processedProfile(profile) let newProfile = try processedProfile(profile)
try await tunnel.install(newProfile, connect: true, title: processedTitle) try await tunnel.install(newProfile, connect: true, title: processedTitle)
} }
public func disconnect() async throws { public func disconnect() async throws {
pp_log(.app, .notice, "Disconnect...")
try await tunnel.disconnect() try await tunnel.disconnect()
} }

View File

@ -67,15 +67,20 @@ public final class AppContext: ObservableObject {
return return
} }
isActivating = true isActivating = true
Task {
do {
pp_log(.app, .notice, "Application became active") pp_log(.app, .notice, "Application became active")
await iapManager.reloadReceipt() Task {
pp_log(.app, .notice, "Prepare tunnel and purge stale data...") await withTaskGroup(of: Void.self) { group in
try await tunnel.prepare(purge: true) group.addTask {
do {
try await self.tunnel.prepare(purge: true)
} catch { } catch {
pp_log(.app, .fault, "Unable to prepare tunnel: \(error)") pp_log(.app, .fault, "Unable to prepare tunnel: \(error)")
} }
}
group.addTask {
await self.iapManager.reloadReceipt()
}
}
isActivating = false isActivating = false
} }
} }