diff --git a/StikDebug/App/StikDebugApp.swift b/StikDebug/App/StikDebugApp.swift index 5ccd112..d6c70f9 100644 --- a/StikDebug/App/StikDebugApp.swift +++ b/StikDebug/App/StikDebugApp.swift @@ -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( diff --git a/StikDebug/Views/HomeView.swift b/StikDebug/Views/HomeView.swift index a7b1b54..363ba80 100644 --- a/StikDebug/Views/HomeView.swift +++ b/StikDebug/Views/HomeView.swift @@ -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)