72 lines
2.2 KiB
Swift
72 lines
2.2 KiB
Swift
//
|
|
// RootView.swift
|
|
// punchnet
|
|
//
|
|
// Created by 安礼成 on 2026/1/19.
|
|
//
|
|
|
|
import SwiftUI
|
|
|
|
struct RootView: View {
|
|
@Environment(UserContext.self) var userContext
|
|
@Environment(AppContext.self) var appContext: AppContext
|
|
|
|
@State private var updateManager = AppUpdateManager.shared
|
|
|
|
var body: some View {
|
|
ZStack {
|
|
// 主要界面
|
|
Group {
|
|
switch appContext.appScene {
|
|
case .login(username: let username):
|
|
LoginView(username: username)
|
|
case .logined:
|
|
NetworkView()
|
|
case .register:
|
|
RegisterRootView()
|
|
case .resetPassword:
|
|
ResetPasswordRootView()
|
|
}
|
|
}
|
|
.transition(.asymmetric(
|
|
insertion: .move(edge: .trailing).combined(with: .opacity),
|
|
removal: .move(edge: .trailing).combined(with: .opacity)
|
|
))
|
|
|
|
// 自动更新遮罩
|
|
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()
|
|
}
|