fix menu
This commit is contained in:
parent
0cf5f40fae
commit
213addcc4a
@ -36,23 +36,42 @@ struct punchnetApp: App {
|
||||
var body: some Scene {
|
||||
WindowGroup(id: "mainWindow") {
|
||||
ContentView()
|
||||
.frame(minWidth: 300, maxWidth: 300, minHeight: 500, maxHeight: 500)
|
||||
.onAppear {
|
||||
// 获取主屏幕的尺寸
|
||||
guard let screenFrame = NSScreen.main?.frame else { return }
|
||||
|
||||
// 获取当前应用的窗口(假设只有一个窗口)
|
||||
NSApplication.shared.windows.forEach { window in
|
||||
// 计算窗口的中心位置
|
||||
let windowWidth = window.frame.width
|
||||
let windowHeight = window.frame.height
|
||||
let centerX = (screenFrame.width - windowWidth) / 2
|
||||
let centerY = (screenFrame.height - windowHeight) / 2
|
||||
|
||||
// 设置窗口位置
|
||||
window.setFrameOrigin(NSPoint(x: centerX, y: centerY))
|
||||
}
|
||||
}
|
||||
}
|
||||
.commands {
|
||||
CommandGroup(replacing: .appInfo) {
|
||||
Button {
|
||||
openWindow(id: "abortSDLAN")
|
||||
openWindow(id: "abortPunchnet")
|
||||
} label: {
|
||||
Text("About sdlan")
|
||||
Text("About Punchnet")
|
||||
}
|
||||
}
|
||||
}
|
||||
.windowResizability(.contentSize)
|
||||
|
||||
Window("", id: "abortSDLAN") {
|
||||
|
||||
Window("", id: "abortPunchnet") {
|
||||
AbortView()
|
||||
.frame(minWidth: 300, maxWidth: 300, minHeight: 500, maxHeight: 500)
|
||||
}
|
||||
|
||||
//.modelContainer(sharedModelContainer)
|
||||
MenuBarExtra("sdlanApp", systemImage: "hammer") {
|
||||
MenuBarExtra("punchnet", image: "logo_32") {
|
||||
VStack {
|
||||
Button(action: {
|
||||
self.menuClick()
|
||||
@ -74,17 +93,12 @@ struct punchnetApp: App {
|
||||
private func menuClick() {
|
||||
switch self.vpnManager.vpnStatus {
|
||||
case .disconnected:
|
||||
if token.isEmpty {
|
||||
let windows = NSApplication.shared.windows
|
||||
if let window = windows.first(where: {$0.title == "sdlan"}) {
|
||||
window.level = .floating
|
||||
} else {
|
||||
self.openWindow(id: "mainWindow")
|
||||
}
|
||||
} else {
|
||||
Task {
|
||||
try await vpnManager.enableVpn(options: ["token": token as NSObject])
|
||||
}
|
||||
Task {
|
||||
try await vpnManager.enableVpn(options: [
|
||||
"version:": SystemConfig.version as NSObject,
|
||||
"installed_channel": SystemConfig.installedChannel as NSObject,
|
||||
"token": token as NSObject
|
||||
])
|
||||
}
|
||||
case .connected:
|
||||
Task {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user