LighthouseApp/macos/Runner/AppDelegate.swift
speakeloudest 75d4c48e41
Some checks failed
Build Windows / build (push) Has been cancelled
feat: 源码提交
2025-10-19 23:30:54 -07:00

64 lines
2.2 KiB
Swift
Executable File
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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)
}
}
//
override func applicationSupportsSecureRestorableState(_ app: NSApplication) -> Bool {
return true
}
// // 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
// }
}