diff --git a/StikJIT/StikJITApp.swift b/StikJIT/StikJITApp.swift index 43aa666e..5df6a982 100644 --- a/StikJIT/StikJITApp.swift +++ b/StikJIT/StikJITApp.swift @@ -452,6 +452,9 @@ struct HeartbeatApp: App { @State private var show_alert = false @State private var alert_string = "" @State private var alert_title = "" + @State private var showTimeoutError = false + @State private var showLogs = false + @State private var timeoutTimer: Timer? @StateObject private var mount = MountingProgress.shared @StateObject private var dnsChecker = DNSChecker() // New DNS check state object @AppStorage("appTheme") private var appTheme: String = "system" @@ -530,6 +533,12 @@ struct HeartbeatApp: App { LoadingView(showAlert: $show_alert, alertTitle: $alert_title, alertMessage: $alert_string) .onAppear { dnsChecker.checkDNS() + timeoutTimer?.invalidate() + timeoutTimer = Timer.scheduledTimer(withTimeInterval: 30, repeats: false) { _ in + if isLoading2 { + showTimeoutError = true + } + } checkVPNConnection() { result, vpn_error in if result { if FileManager.default.fileExists(atPath: URL.documentsDirectory.appendingPathComponent("pairingFile.plist").path) { @@ -593,6 +602,34 @@ struct HeartbeatApp: App { print("Failed") } } + .overlay( + ZStack { + if showTimeoutError { + CustomErrorView( + title: "Connection Error", + message: "Check your connection and ensure your pairing file is valid and try again.", + onDismiss: { + showTimeoutError = false + }, + showButton: true, + primaryButtonText: "Continue Anyway", + secondaryButtonText: "View Logs", + onPrimaryButtonTap: { + isLoading2 = false + }, + onSecondaryButtonTap: { + showLogs = true + }, + showSecondaryButton: true + ) + } + } + ) + .sheet(isPresented: $showLogs, onDismiss: { + isLoading2 = false + }) { + ConsoleLogsView() + } } else { MainTabView() .onAppear { @@ -652,6 +689,12 @@ struct HeartbeatApp: App { startHeartbeatInBackground() } } + .onChange(of: isLoading2) { newValue in + if !newValue { + timeoutTimer?.invalidate() + timeoutTimer = nil + } + } .onChange(of: dnsChecker.dnsError) { newError in if let errorMsg = newError, !errorMsg.contains("Not connected to WiFi") { alert_title = "Network Issue"