// // RootView.swift // punchnet // // Created by 安礼成 on 2026/1/19. // import SwiftUI struct RootView: View { @Environment(UserContext.self) var userContext @State private var updateManager = AppUpdateManager.shared var body: some View { ZStack { // 主要界面 Group { if userContext.isLogined { NetworkView() } else { LoginView() } } // 自动更新遮罩 if updateManager.showUpdateOverlay, let info = updateManager.updateInfo { // 遮罩背景 Color.black.opacity(0.4) .ignoresSafeArea() .onTapGesture { if !info.forceUpdate { updateManager.showUpdateOverlay = false } } // 弹窗卡片 AppUpdateView(info: info) { updateManager.showUpdateOverlay = false } .clipShape(RoundedRectangle(cornerRadius: 16)) .shadow(color: .black.opacity(0.3), radius: 20) .transition(.asymmetric( insertion: .scale(scale: 0.9).combined(with: .opacity), removal: .opacity )) } } .animation(.spring(duration: 0.4), value: updateManager.showUpdateOverlay) .task { // 启动时静默检查 let checkUpdateResult = await updateManager.checkUpdate(isManual: false) NSLog("[RootView] checkUpdateResult: \(checkUpdateResult)") } } } #Preview { RootView() }