Skip to content

Commit afefeb1

Browse files
authored
Add timeout alert with log viewer (#238)
* Add timeout error and log viewer * Fix parameter order in timeout alert * Add timeout timer for loading * Update timeout actions and log view * Open ConsoleLogsView from timeout alert * Open logs without dismissing loading
1 parent e6cd761 commit afefeb1

1 file changed

Lines changed: 43 additions & 0 deletions

File tree

StikJIT/StikJITApp.swift

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,9 @@ struct HeartbeatApp: App {
452452
@State private var show_alert = false
453453
@State private var alert_string = ""
454454
@State private var alert_title = ""
455+
@State private var showTimeoutError = false
456+
@State private var showLogs = false
457+
@State private var timeoutTimer: Timer?
455458
@StateObject private var mount = MountingProgress.shared
456459
@StateObject private var dnsChecker = DNSChecker() // New DNS check state object
457460
@AppStorage("appTheme") private var appTheme: String = "system"
@@ -530,6 +533,12 @@ struct HeartbeatApp: App {
530533
LoadingView(showAlert: $show_alert, alertTitle: $alert_title, alertMessage: $alert_string)
531534
.onAppear {
532535
dnsChecker.checkDNS()
536+
timeoutTimer?.invalidate()
537+
timeoutTimer = Timer.scheduledTimer(withTimeInterval: 30, repeats: false) { _ in
538+
if isLoading2 {
539+
showTimeoutError = true
540+
}
541+
}
533542
checkVPNConnection() { result, vpn_error in
534543
if result {
535544
if FileManager.default.fileExists(atPath: URL.documentsDirectory.appendingPathComponent("pairingFile.plist").path) {
@@ -593,6 +602,34 @@ struct HeartbeatApp: App {
593602
print("Failed")
594603
}
595604
}
605+
.overlay(
606+
ZStack {
607+
if showTimeoutError {
608+
CustomErrorView(
609+
title: "Connection Error",
610+
message: "Check your connection and ensure your pairing file is valid and try again.",
611+
onDismiss: {
612+
showTimeoutError = false
613+
},
614+
showButton: true,
615+
primaryButtonText: "Continue Anyway",
616+
secondaryButtonText: "View Logs",
617+
onPrimaryButtonTap: {
618+
isLoading2 = false
619+
},
620+
onSecondaryButtonTap: {
621+
showLogs = true
622+
},
623+
showSecondaryButton: true
624+
)
625+
}
626+
}
627+
)
628+
.sheet(isPresented: $showLogs, onDismiss: {
629+
isLoading2 = false
630+
}) {
631+
ConsoleLogsView()
632+
}
596633
} else {
597634
MainTabView()
598635
.onAppear {
@@ -652,6 +689,12 @@ struct HeartbeatApp: App {
652689
startHeartbeatInBackground()
653690
}
654691
}
692+
.onChange(of: isLoading2) { newValue in
693+
if !newValue {
694+
timeoutTimer?.invalidate()
695+
timeoutTimer = nil
696+
}
697+
}
655698
.onChange(of: dnsChecker.dnsError) { newError in
656699
if let errorMsg = newError, !errorMsg.contains("Not connected to WiFi") {
657700
alert_title = "Network Issue"

0 commit comments

Comments
 (0)