fix: keep strong reference to AppDelegate and add direct 1s UI refresh timer
This commit is contained in:
parent
a1dee8f254
commit
a444501b06
1 changed files with 15 additions and 0 deletions
|
|
@ -5,13 +5,18 @@ import CoreAudio
|
||||||
|
|
||||||
@main
|
@main
|
||||||
final class AppDelegate: NSObject, NSApplicationDelegate {
|
final class AppDelegate: NSObject, NSApplicationDelegate {
|
||||||
|
private static var appDelegateInstance: AppDelegate?
|
||||||
|
|
||||||
private var statusItem: NSStatusItem!
|
private var statusItem: NSStatusItem!
|
||||||
private let tracker = BluetoothTracker.shared
|
private let tracker = BluetoothTracker.shared
|
||||||
private let updater = UpdaterService.shared
|
private let updater = UpdaterService.shared
|
||||||
|
private var refreshTimer: Timer?
|
||||||
|
|
||||||
static func main() {
|
static func main() {
|
||||||
let app = NSApplication.shared
|
let app = NSApplication.shared
|
||||||
let delegate = AppDelegate()
|
let delegate = AppDelegate()
|
||||||
|
// Strong reference to prevent ARC deallocation of weak NSApplication.delegate
|
||||||
|
appDelegateInstance = delegate
|
||||||
app.delegate = delegate
|
app.delegate = delegate
|
||||||
app.setActivationPolicy(.accessory)
|
app.setActivationPolicy(.accessory)
|
||||||
app.run()
|
app.run()
|
||||||
|
|
@ -45,6 +50,14 @@ final class AppDelegate: NSObject, NSApplicationDelegate {
|
||||||
// Start active tracking
|
// Start active tracking
|
||||||
tracker.startTracking()
|
tracker.startTracking()
|
||||||
|
|
||||||
|
// Direct main thread timer in AppDelegate for guaranteed 1-second UI refresh
|
||||||
|
let t = Timer.scheduledTimer(withTimeInterval: 1.0, repeats: true) { [weak self] _ in
|
||||||
|
self?.tracker.updateDeviceList()
|
||||||
|
self?.updateStatusItem()
|
||||||
|
}
|
||||||
|
RunLoop.main.add(t, forMode: .common)
|
||||||
|
self.refreshTimer = t
|
||||||
|
|
||||||
// Initial render
|
// Initial render
|
||||||
updateStatusItem()
|
updateStatusItem()
|
||||||
}
|
}
|
||||||
|
|
@ -123,6 +136,8 @@ final class AppDelegate: NSObject, NSApplicationDelegate {
|
||||||
|
|
||||||
@objc private func refreshClicked() {
|
@objc private func refreshClicked() {
|
||||||
tracker.refreshNow()
|
tracker.refreshNow()
|
||||||
|
updateStatusItem()
|
||||||
|
setupMenu()
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc private func updateClicked() {
|
@objc private func updateClicked() {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue