import AppKit import Ch45Kit import SwiftUI final class AppDelegate: NSObject, NSApplicationDelegate { func applicationDidFinishLaunching(_ notification: Notification) { NSLog("ch45: did finish launching") } func applicationWillTerminate(_ notification: Notification) { NSLog("ch45: will terminate") } func applicationShouldTerminateAfterLastWindowClosed(_ sender: NSApplication) -> Bool { true } } @main struct Ch45App: App { @NSApplicationDelegateAdaptor(AppDelegate.self) private var delegate @Environment(\.scenePhase) private var phase var body: some Scene { WindowGroup("生命周期与 Bundle") { VStack(spacing: 14) { LifecycleBoard() Text("bundle:\(Bundle.main.bundlePath)") .font(.system(size: 10, design: .monospaced)) .textSelection(.enabled) Text("阶段:\(phaseText)") .font(.footnote) .foregroundStyle(.secondary) } .padding(20) .frame(minWidth: 400, minHeight: 420) } } private var phaseText: String { switch phase { case .active: "active" case .inactive: "inactive" case .background: "background" @unknown default: "unknown" } } }