fix: fixed popup open registration when module is enabled after the app has been running (#2540)

This commit is contained in:
Serhiy Mytrovtsiy
2025-08-30 22:28:08 +02:00
parent 053f265bdb
commit 16efe9dda8
2 changed files with 28 additions and 14 deletions

View File

@@ -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 {