69 lines
1.8 KiB
Swift
69 lines
1.8 KiB
Swift
//
|
|
// MainMenuBar.swift
|
|
// punchnet
|
|
//
|
|
// Created by 安礼成 on 2026/3/24.
|
|
//
|
|
|
|
import SwiftUI
|
|
|
|
struct MainMenuBar: View {
|
|
@State private var vpnManager = VPNManager.shared
|
|
@Environment(AppContext.self) private var appContext: AppContext
|
|
@Environment(\.openWindow) private var openWindow
|
|
@Environment(\.dismissWindow) private var dismissWindow
|
|
|
|
var body: some View {
|
|
VStack {
|
|
switch self.vpnManager.vpnStatus {
|
|
case .connected:
|
|
Button(action: {
|
|
Task { @MainActor in
|
|
try await vpnManager.disableVpn()
|
|
}
|
|
}, label: {
|
|
Text("停止")
|
|
})
|
|
case .disconnected:
|
|
Button(action: {
|
|
Task { @MainActor in
|
|
await self.startVPN()
|
|
}
|
|
}, label: {
|
|
Text("启动")
|
|
})
|
|
}
|
|
|
|
Divider()
|
|
|
|
// Button("打开控制面板") {
|
|
// openWindow(id: appContext.isLoggedIn ? "logined" : "login")
|
|
// }
|
|
|
|
SettingsLink {
|
|
Text("设置")
|
|
}
|
|
.buttonStyle(.plain)
|
|
|
|
Divider()
|
|
|
|
Button(action: {
|
|
NSApplication.shared.terminate(nil)
|
|
}, label: {
|
|
Text("退出应用")
|
|
})
|
|
}
|
|
}
|
|
|
|
private func startVPN() async {
|
|
if let options = appContext.vpnOptions {
|
|
try? await vpnManager.enableVpn(options: options)
|
|
dismissWindow(id: "login")
|
|
openWindow(id: "logined")
|
|
} else {
|
|
openWindow(id: "login")
|
|
}
|
|
}
|
|
|
|
}
|