From 2a23ab8493ece6a523edd9add75db2a6218112f9 Mon Sep 17 00:00:00 2001 From: Serhiy Mytrovtsiy Date: Wed, 5 Nov 2025 19:46:41 +0100 Subject: [PATCH] fix: fixed bug on macOS 26 when settings autosaveName to menu bar item prevents it from loading (#2768) --- Kit/module/widget.swift | 30 ++++++++++++++--------------- Stats/Supporting Files/Info.plist | 2 +- Stats/Views/CombinedView.swift | 4 +++- Stats/helpers.swift | 4 +++- Widgets/Supporting Files/Info.plist | 2 +- 5 files changed, 22 insertions(+), 20 deletions(-) diff --git a/Kit/module/widget.swift b/Kit/module/widget.swift index 76916975..c45a2cda 100644 --- a/Kit/module/widget.swift +++ b/Kit/module/widget.swift @@ -213,6 +213,12 @@ open class WidgetWrapper: NSView, widget_p { return width } + public func redraw() { + DispatchQueue.main.async { [weak self] in + self?.display() + } + } + open func settings() -> NSView { return NSView() } open override func mouseDown(with event: NSEvent) { @@ -318,18 +324,12 @@ public class SWidget { public func setMenuBarItem(state: Bool) { if state { - let prevTag = "NSStatusItem Preferred Position \(self.module)_\(self.type.name())" - let prevPosition = Store.shared.int(key: prevTag, defaultValue: -1) - if prevPosition != -1 { - Store.shared.set(key: "NSStatusItem Preferred Position \(self.module)_\(self.type.rawValue)", value: prevPosition) - Store.shared.remove(prevTag) - } - restoreNSStatusItemPosition(id: "\(self.module)_\(self.type.rawValue)") - DispatchQueue.main.async(execute: { self.menuBarItem = NSStatusBar.system.statusItem(withLength: self.item.frame.width) - self.menuBarItem?.autosaveName = "\(self.module)_\(self.type.rawValue)" + DispatchQueue.main.async(execute: { + self.menuBarItem?.autosaveName = "\(self.module)_\(self.type.rawValue)" + }) if self.item.frame.origin.x != self.originX { self.item.setFrameOrigin(NSPoint(x: self.originX, y: self.item.frame.origin.y)) } @@ -393,12 +393,8 @@ public class MenuBar { private var _active: Bool = false public var active: Bool { - get { - self.queue.sync { self._active } - } - set { - self.queue.sync { self._active = newValue } - } + get { self.queue.sync { self._active } } + set { self.queue.sync { self._active = newValue } } } init(moduleName: String) { @@ -475,7 +471,9 @@ public class MenuBar { if state && self.active { restoreNSStatusItemPosition(id: self.moduleName) self.menuBarItem = NSStatusBar.system.statusItem(withLength: 0) - self.menuBarItem?.autosaveName = self.moduleName + DispatchQueue.main.async(execute: { + self.menuBarItem?.autosaveName = self.moduleName + }) self.menuBarItem?.isVisible = true self.menuBarItem?.button?.addSubview(self.view) diff --git a/Stats/Supporting Files/Info.plist b/Stats/Supporting Files/Info.plist index edd34983..ebe4c11b 100755 --- a/Stats/Supporting Files/Info.plist +++ b/Stats/Supporting Files/Info.plist @@ -17,7 +17,7 @@ CFBundleShortVersionString $(MARKETING_VERSION) CFBundleVersion - 726 + 739 Description Simple macOS system monitor in your menu bar LSApplicationCategoryType diff --git a/Stats/Views/CombinedView.swift b/Stats/Views/CombinedView.swift index 8b88805c..10a5f619 100644 --- a/Stats/Views/CombinedView.swift +++ b/Stats/Views/CombinedView.swift @@ -70,7 +70,9 @@ internal class CombinedView: NSObject, NSGestureRecognizerDelegate { public func enable() { self.menuBarItem = NSStatusBar.system.statusItem(withLength: 0) - self.menuBarItem?.autosaveName = "CombinedModules" + DispatchQueue.main.async(execute: { + self.menuBarItem?.autosaveName = "CombinedModules" + }) self.menuBarItem?.button?.addSubview(self.view) self.menuBarItem?.button?.image = NSImage() self.menuBarItem?.button?.toolTip = localizedString("Combined modules") diff --git a/Stats/helpers.swift b/Stats/helpers.swift index 66d20ef8..8e35267d 100644 --- a/Stats/helpers.swift +++ b/Stats/helpers.swift @@ -257,7 +257,9 @@ extension AppDelegate { internal func icon() { if self.pauseState { self.menuBarItem = NSStatusBar.system.statusItem(withLength: AppIcon.size.width) - self.menuBarItem?.autosaveName = "Stats" + DispatchQueue.main.async(execute: { + self.menuBarItem?.autosaveName = "Stats" + }) self.menuBarItem?.button?.addSubview(AppIcon()) self.menuBarItem?.button?.target = self diff --git a/Widgets/Supporting Files/Info.plist b/Widgets/Supporting Files/Info.plist index 9de999e6..89bb4d78 100644 --- a/Widgets/Supporting Files/Info.plist +++ b/Widgets/Supporting Files/Info.plist @@ -13,7 +13,7 @@ CFBundleShortVersionString 2.11.58 CFBundleVersion - 726 + 739 NSExtension NSExtensionPointIdentifier