初始化信息

This commit is contained in:
2025-10-13 18:08:02 +08:00
parent e302ebe176
commit 35a90f1635
616 changed files with 58357 additions and 25 deletions
+58
View File
@@ -0,0 +1,58 @@
import Cocoa
import FlutterMacOS
import window_manager
import UserNotifications
@main
class AppDelegate: FlutterAppDelegate {
override func applicationShouldTerminateAfterLastWindowClosed(_ sender: NSApplication) -> Bool {
//
return false
}
override func applicationDidFinishLaunching(_ aNotification: Notification) {
// Request notification authorization
UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .badge]) { granted, error in
if let error = error {
print("Error requesting notification authorization: \(error)")
}
}
}
//
override func applicationShouldHandleReopen(_ sender: NSApplication, hasVisibleWindows flag: Bool) -> Bool {
if !flag {
for window in NSApp.windows {
window.makeKeyAndOrderFront(nil)
NSApp.activate(ignoringOtherApps: true)
}
}
return true
}
// 退
override func applicationWillTerminate(_ notification: Notification) {
//
//
print("应用程序即将终止")
// Flutter
if let controller = NSApp.windows.first?.contentViewController as? FlutterViewController {
let channel = FlutterMethodChannel(name: "kaer_vpn/terminate", binaryMessenger: controller.engine.binaryMessenger)
channel.invokeMethod("onTerminate", arguments: nil)
}
}
// // window manager restore from dock: https://leanflutter.dev/blog/click-dock-icon-to-restore-after-closing-the-window
// override func applicationShouldHandleReopen(_ sender: NSApplication, hasVisibleWindows flag: Bool) -> Bool {
// if !flag {
// for window in NSApp.windows {
// if !window.isVisible {
// window.setIsVisible(true)
// }
// window.makeKeyAndOrderFront(self)
// NSApp.activate(ignoringOtherApps: true)
// }
// }
// return true
// }
}