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:
@@ -232,9 +232,7 @@ public class SWidget {
|
||||
public var item: widget_p
|
||||
|
||||
public var isActive: Bool {
|
||||
get {
|
||||
self.list.contains{ $0 == self.type }
|
||||
}
|
||||
get { self.list.contains{ $0 == self.type } }
|
||||
set {
|
||||
if newValue {
|
||||
self.list.append(self.type)
|
||||
@@ -251,12 +249,8 @@ public class SWidget {
|
||||
NextLog.shared.copy(category: self.module)
|
||||
}
|
||||
public var position: Int {
|
||||
get {
|
||||
Store.shared.int(key: "\(self.module)_\(self.type)_position", defaultValue: 0)
|
||||
}
|
||||
set {
|
||||
Store.shared.set(key: "\(self.module)_\(self.type)_position", value: newValue)
|
||||
}
|
||||
get { Store.shared.int(key: "\(self.module)_\(self.type)_position", defaultValue: 0) }
|
||||
set { Store.shared.set(key: "\(self.module)_\(self.type)_position", value: newValue) }
|
||||
}
|
||||
|
||||
private var list: [widget_t] {
|
||||
@@ -264,9 +258,7 @@ public class SWidget {
|
||||
let string = Store.shared.string(key: "\(self.module)_widget", defaultValue: self.defaultWidget.rawValue)
|
||||
return string.split(separator: ",").map{ (widget_t(rawValue: String($0)) ?? .unknown)}
|
||||
}
|
||||
set {
|
||||
Store.shared.set(key: "\(self.module)_widget", value: newValue.map{ $0.rawValue }.joined(separator: ","))
|
||||
}
|
||||
set { Store.shared.set(key: "\(self.module)_widget", value: newValue.map{ $0.rawValue }.joined(separator: ",")) }
|
||||
}
|
||||
|
||||
private var menuBarItem: NSStatusItem? = nil
|
||||
@@ -576,8 +568,6 @@ public class MenuBarView: NSView {
|
||||
public func removeWidget(type: widget_t) {
|
||||
if let view = self.subviews.first(where: { $0.identifier == NSUserInterfaceItemIdentifier(type.rawValue) }) {
|
||||
view.removeFromSuperview()
|
||||
} else {
|
||||
error("\(type) could not be removed from the one view because not found!")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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