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
This commit is contained in:
Stephen B 2025-07-23 17:58:05 -04:00 • committed by GitHub
parent e6cd761092
commit afefeb1ff6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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"