Skip to content

Commit

Permalink
Update MenuBarManager.swift
Browse files Browse the repository at this point in the history
  • Loading branch information
jordanbaird committed Feb 16, 2024
1 parent 4cb9c95 commit 811dd36
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions Ice/MenuBar/MenuBarManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -380,22 +380,24 @@ final class MenuBarManager: ObservableObject {
}

do {
// get the largest x-coordinate of all items
guard
let application = Application(frontmostApplication),
let menuBar: UIElement = try application.attribute(.menuBar),
let children: [UIElement] = try menuBar.arrayAttribute(.children),
let maxX = try children.compactMap({ try ($0.attribute(.frame) as CGRect?)?.maxX }).max()
let children: [UIElement] = try menuBar.arrayAttribute(.children)
else {
mainMenuMaxX = 0
menuBar = nil
self.mainMenuMaxX = 0
self.menuBar = nil
return
}
mainMenuMaxX = maxX
self.mainMenuMaxX = try children.reduce(into: 0) { result, child in
if let frame: CGRect = try child.attribute(.frame) {
result += frame.width
}
}
self.menuBar = menuBar
} catch {
mainMenuMaxX = 0
menuBar = nil
self.mainMenuMaxX = 0
self.menuBar = nil
Logger.menuBarManager.error("Error updating main menu maxX: \(error)")
}
}
Expand Down

0 comments on commit 811dd36

Please sign in to comment.