StikDebug/StikDebug/App/StikDebugApp.swift
2026-05-20 10:07:09 -04:00

58 lines
1.5 KiB
Swift

//
// StikDebugApp.swift
// StikDebug
//
// Created by Stephen on 3/26/25.
//
import SwiftUI
@main
struct StikDebugApp: App {
@Environment(\.scenePhase) private var scenePhase
@State private var shouldAttemptTunnelReconnect = false
init() {
AppBootstrapper.configure()
}
var body: some Scene {
WindowGroup {
MainTabView()
.task {
await downloadMissingDeveloperDiskImageFiles()
}
.onChange(of: scenePhase) { _, newPhase in
handleScenePhaseChange(newPhase)
}
}
}
private func handleScenePhaseChange(_ newPhase: ScenePhase) {
switch newPhase {
case .background:
shouldAttemptTunnelReconnect = true
case .active:
if shouldAttemptTunnelReconnect {
shouldAttemptTunnelReconnect = false
startTunnelInBackground(showErrorUI: false)
}
default:
break
}
}
private func downloadMissingDeveloperDiskImageFiles() async {
do {
try await DeveloperDiskImageService.shared.downloadMissingFiles()
} catch {
await MainActor.run {
showAlert(
title: "An Error has Occurred",
message: "[Download DDI Error]: \(error.localizedDescription)",
showOk: true
)
}
}
}
}