mirror of
https://github.com/morgan9e/macos-stats
synced 2026-04-14 00:04:15 +09:00
fix: fixed popup open registration when module is enabled after the app has been running (#2540)
This commit is contained in:
@@ -58,10 +58,14 @@ internal class CombinedView: NSObject, NSGestureRecognizerDelegate {
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(listenForOneView), name: .toggleOneView, object: nil)
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(listenForModuleRearrrange), name: .moduleRearrange, object: nil)
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(listenCombinedModulesPopup), name: .combinedModulesPopup, object: nil)
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(listenForModule), name: .toggleModule, object: nil)
|
||||
}
|
||||
|
||||
deinit {
|
||||
NotificationCenter.default.removeObserver(self, name: .toggleOneView, object: nil)
|
||||
NotificationCenter.default.removeObserver(self, name: .moduleRearrange, object: nil)
|
||||
NotificationCenter.default.removeObserver(self, name: .combinedModulesPopup, object: nil)
|
||||
NotificationCenter.default.removeObserver(self, name: .toggleModule, object: nil)
|
||||
}
|
||||
|
||||
public func enable() {
|
||||
@@ -205,6 +209,26 @@ internal class CombinedView: NSObject, NSGestureRecognizerDelegate {
|
||||
self.menuBarItem?.button?.sendAction(on: [.leftMouseDown, .rightMouseDown])
|
||||
}
|
||||
}
|
||||
|
||||
@objc private func listenForModule(_ notification: Notification) {
|
||||
guard let name = notification.userInfo?["module"] as? String,
|
||||
let state = notification.userInfo?["state"] as? Bool,
|
||||
state,
|
||||
let module = self.activeModules.first(where: { $0.name == name }) else { return }
|
||||
|
||||
module.menuBar.widgets.forEach { w in
|
||||
w.item.onClick = {
|
||||
if let window = w.item.window {
|
||||
NotificationCenter.default.post(name: .togglePopup, object: nil, userInfo: [
|
||||
"module": module.name,
|
||||
"widget": w.type,
|
||||
"origin": window.frame.origin,
|
||||
"center": window.frame.width/2
|
||||
])
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private class Popup: NSStackView, Popup_p {
|
||||
|
||||
Reference in New Issue
Block a user