fix: Release 模式下 delegate 被 ARC 释放导致菜单灰色/双击失效
This commit is contained in:
parent
e1cfb27e16
commit
6a8b5532bd
@ -5,6 +5,9 @@ import Speech
|
||||
/// 应用主控制器,协调 Fn 键(语音输入)和 Control 键(AI 助手)两种模式
|
||||
final class AppDelegate: NSObject, NSApplicationDelegate {
|
||||
|
||||
/// 防止 ARC 优化释放(NSApplication.delegate 是 weak)
|
||||
private static var retainedInstance: AppDelegate?
|
||||
|
||||
private let keyMonitor = KeyMonitor()
|
||||
private let speechRecognizer = SpeechRecognizer()
|
||||
private let audioMonitor = AudioLevelMonitor()
|
||||
@ -15,6 +18,11 @@ final class AppDelegate: NSObject, NSApplicationDelegate {
|
||||
private var isRecording = false
|
||||
private var finalTranscription: String = ""
|
||||
|
||||
override init() {
|
||||
super.init()
|
||||
Self.retainedInstance = self
|
||||
}
|
||||
|
||||
func applicationDidFinishLaunching(_ notification: Notification) {
|
||||
NSApp.setActivationPolicy(.accessory)
|
||||
beginPermissionFlow()
|
||||
|
||||
@ -5,4 +5,8 @@ let delegate = AppDelegate()
|
||||
|
||||
app.setActivationPolicy(.accessory)
|
||||
app.delegate = delegate
|
||||
|
||||
// NSApplication.delegate 是 weak 引用,必须保持强引用防止 ARC 优化释放
|
||||
withExtendedLifetime(delegate) {
|
||||
app.run()
|
||||
}
|
||||
|
||||
Binary file not shown.
Loading…
Reference in New Issue
Block a user