This commit is contained in:
anlicheng 2026-03-24 15:10:58 +08:00
parent 97194e501e
commit 067ac7c092
5 changed files with 83 additions and 96 deletions

View File

@ -77,8 +77,6 @@ struct LoginView: View {
.padding(.bottom, 20)
}
.frame(width: 380, height: 520)
// macOS
.background(VisualEffectView(material: .hudWindow, blendingMode: .behindWindow))
.ignoresSafeArea()
}
@ -288,25 +286,6 @@ struct CustomSecureField: View {
}
}
// MARK: - 1. UI ( Material )
struct VisualEffectView: NSViewRepresentable {
let material: NSVisualEffectView.Material
let blendingMode: NSVisualEffectView.BlendingMode
func makeNSView(context: Context) -> NSVisualEffectView {
let view = NSVisualEffectView()
view.material = material
view.blendingMode = blendingMode
view.state = .active
return view
}
func updateNSView(_ nsView: NSVisualEffectView, context: Context) {
nsView.material = material
nsView.blendingMode = blendingMode
}
}
#Preview {
LoginView()
.environment(AppContext(noticePort: 0))

View File

@ -14,11 +14,10 @@ struct RegisterRootView: View {
var body: some View {
ZStack {
//
VisualEffectView(material: .underWindowBackground, blendingMode: .behindWindow)
Color.clear
.ignoresSafeArea()
Group {
ZStack(alignment: .center) {
switch registerModel.stage {
case .requestVerifyCode:
RegisterRequestVerifyCodeView()
@ -64,7 +63,6 @@ struct RegisterRootView: View {
.transition(.opacity) //
}
}
.frame(width: 500, height: 400)
}
}
@ -122,7 +120,9 @@ struct RegisterRequestVerifyCodeView: View {
.frame(width: 280)
Button(action: {
self.requestVerifyCode(username: model.username)
Task { @MainActor in
await self.requestVerifyCode(username: model.username)
}
}) {
Text("获取验证码")
.fontWeight(.medium)
@ -141,13 +141,15 @@ struct RegisterRequestVerifyCodeView: View {
}
}
private func requestVerifyCode(username: String) {
private func requestVerifyCode(username: String) async {
self.isProcessing = true
Task { @MainActor in
defer {
self.isProcessing = false
}
if username.isEmpty {
self.showAlert = true
self.errorMessage = "邮箱为空"
self.isProcessing = false
return
}
@ -173,8 +175,6 @@ struct RegisterRequestVerifyCodeView: View {
self.showAlert = true
self.errorMessage = "邮箱格式错误"
}
self.isProcessing = false
}
}
}

View File

@ -14,11 +14,10 @@ struct ResetPasswordRootView: View {
var body: some View {
ZStack {
// (macOS )
VisualEffectView(material: .underWindowBackground, blendingMode: .behindWindow)
Color.clear
.ignoresSafeArea()
Group {
ZStack(alignment: .center) {
switch resetPasswordModel.stage {
case .requestVerifyCode:
GetVerifyCodeView()
@ -60,7 +59,6 @@ struct ResetPasswordRootView: View {
.transition(.opacity) //
}
}
.frame(width: 500, height: 400)
}
}

View File

@ -9,32 +9,59 @@ import SwiftUI
struct RootView: View {
@Environment(AppContext.self) var appContext: AppContext
@State private var updateManager = AppUpdateManager.shared
var body: some View {
ZStack {
//
Group {
// 1.
// 使 ZStack Group
ZStack(alignment: .center) {
switch appContext.appScene {
case .login(username: let username):
LoginView(username: username)
.id("scene_login") // ID
case .logined:
NetworkView()
.id("scene_logined")
case .register:
RegisterRootView()
.id("scene_register")
case .resetPassword:
ResetPasswordRootView()
.id("scene_reset")
}
}
// 2.
// maxWidth/Height .infinity
// minWidth/minHeight
.frame(maxWidth: .infinity, maxHeight: .infinity)
// 3. RootView
.clipped()
.transition(.asymmetric(
insertion: .move(edge: .trailing).combined(with: .opacity),
removal: .move(edge: .trailing).combined(with: .opacity)
removal: .move(edge: .leading).combined(with: .opacity) // leading
))
//
//
if updateManager.showUpdateOverlay, let info = updateManager.updateInfo {
//
updateOverlay(info: info)
}
}
// 4. Scene
.animation(.spring(duration: 0.5), value: appContext.appScene)
.animation(.spring(duration: 0.4), value: updateManager.showUpdateOverlay)
// macOS
.background(VisualEffectView(material: .hudWindow, blendingMode: .behindWindow))
.task {
let checkUpdateResult = await updateManager.checkUpdate(isManual: false)
NSLog("[RootView] checkUpdateResult: \(checkUpdateResult)")
}
}
// body
@ViewBuilder
private func updateOverlay(info: SDLAPIClient.AppUpgradeInfo) -> some View {
ZStack {
Color.black.opacity(0.4)
.ignoresSafeArea()
.onTapGesture {
@ -43,26 +70,18 @@ struct RootView: View {
}
}
//
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
))
.zIndex(100) //
}
}
.animation(.spring(duration: 0.4), value: updateManager.showUpdateOverlay)
.task {
//
let checkUpdateResult = await updateManager.checkUpdate(isManual: false)
NSLog("[RootView] checkUpdateResult: \(checkUpdateResult)")
}
}
}
#Preview {

View File

@ -55,16 +55,7 @@ struct punchnetApp: App {
//.interactiveDismissDisabled() //
}
}
// .commands {
// CommandGroup(replacing: .appInfo) {
// Button {
// openWindow(id: "abortPunchnet")
// } label: {
// Text("About Punchnet")
// }
// }
// }
//.windowResizability(.contentSize)
.windowResizability(.contentSize)
.windowToolbarStyle(.unified)
.defaultPosition(.center)