Fix JIT race on cold URL-scheme launch

This commit is contained in:
CelloSerenity 2026-07-26 00:34:07 -06:00
parent 03b7c109ac
commit c1189928d4
2 changed files with 24 additions and 2 deletions

View file

@ -45,6 +45,7 @@ struct StikDebugApp: App {
private func downloadMissingDeveloperDiskImageFiles() async {
do {
try await DeveloperDiskImageService.shared.downloadMissingFiles()
MountingProgress.shared.pubMount()
} catch {
await MainActor.run {
showAlert(

View file

@ -308,8 +308,18 @@ struct HomeView: View {
let keepAliveLease = DebugKeepAliveLease()
defer { keepAliveLease.invalidate() }
if triggeredByURLScheme {
sleep(1)
if triggeredByURLScheme, !waitForJITPrerequisites() {
DispatchQueue.main.async {
withAnimation {
debugFeedback = nil
}
showAlert(
title: "Failed to Enable JIT".localized,
message: "The device connection or Developer Disk Image wasn't ready in time. Open StikDebug directly, wait for it to finish connecting, then try again.".localized,
showOk: true
)
}
return
}
let finishProcessing: (Bool, String?) -> Void = { success, detail in
@ -384,6 +394,17 @@ struct HomeView: View {
}
}
private func waitForJITPrerequisites(timeout: TimeInterval = 20) -> Bool {
let deadline = Date().addingTimeInterval(timeout)
while Date() < deadline {
if TunnelManager.shared.isConnected && MountingProgress.shared.coolisMounted {
return true
}
usleep(250_000)
}
return TunnelManager.shared.isConnected && MountingProgress.shared.coolisMounted
}
private func base64URLToBase64(_ base64url: String) -> String {
var base64 = base64url.replacingOccurrences(of: "-", with: "+").replacingOccurrences(of: "_", with: "/")
let pad = 4 - (base64.count % 4)