fix(macos): stabilize menu width tracking
This commit is contained in:
@@ -751,14 +751,19 @@ final class MenuSessionsInjector: NSObject, NSMenuDelegate {
|
|||||||
if let openWidth = self.menuOpenWidth {
|
if let openWidth = self.menuOpenWidth {
|
||||||
return max(300, openWidth)
|
return max(300, openWidth)
|
||||||
}
|
}
|
||||||
let candidates: [CGFloat] = [
|
return self.currentMenuWidth(for: menu)
|
||||||
menu.size.width,
|
}
|
||||||
menu.minimumWidth,
|
|
||||||
self.lastKnownMenuWidth ?? 0,
|
private func menuWindowWidth(for menu: NSMenu) -> CGFloat? {
|
||||||
self.fallbackWidth,
|
var menuWindow: NSWindow?
|
||||||
]
|
for item in menu.items {
|
||||||
let resolved = candidates.max() ?? self.fallbackWidth
|
if let window = item.view?.window {
|
||||||
return max(300, resolved)
|
menuWindow = window
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
guard let width = menuWindow?.contentView?.bounds.width, width > 0 else { return nil }
|
||||||
|
return width
|
||||||
}
|
}
|
||||||
|
|
||||||
private func sortedNodeEntries() -> [InstanceInfo] {
|
private func sortedNodeEntries() -> [InstanceInfo] {
|
||||||
@@ -806,6 +811,9 @@ final class MenuSessionsInjector: NSObject, NSMenuDelegate {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private func currentMenuWidth(for menu: NSMenu) -> CGFloat {
|
private func currentMenuWidth(for menu: NSMenu) -> CGFloat {
|
||||||
|
if let width = self.menuWindowWidth(for: menu) {
|
||||||
|
return max(300, width)
|
||||||
|
}
|
||||||
let candidates: [CGFloat] = [
|
let candidates: [CGFloat] = [
|
||||||
menu.size.width,
|
menu.size.width,
|
||||||
menu.minimumWidth,
|
menu.minimumWidth,
|
||||||
|
|||||||
Reference in New Issue
Block a user