mirror of
https://github.com/openclaw/openclaw.git
synced 2026-08-28 05:16:23 -06:00
99a2434f7b
* fix(macos): stabilize status menu width across hosted and native rows * fix(macos): format node worker termination status without optionals * refactor(macos): give status menu width one owner fittedTitle's hasImage/hasSubmenu/keyEquivalent parameters never changed the computation - the budget always included image, submenu, and shortcut chrome - because AppKit aligns those columns across the whole menu, so a per-item budget is the wrong model. Collapse to one menu-wide budget and drop the misleading knobs from all 13 call sites. * refactor(macos): keep the status menu header quiet when healthy A working system now says nothing: the header renders only operator- actionable trouble lines (colored text, no status bubbles), the healthy state is title + toggle + capability strip, and the churn sources that made the open menu jump are gone - relative check ages, 'health check running', and the per-tool activity label (the critter icon already animates work). Session-row kind icons go monochrome; green conveyed nothing actionable. Healthy title is 'OpenClaw' (or the primary gateway name with multiple gateways) since the toggle already communicates active. DashboardGatewayMenuModel.connectionLabel lost its last caller and is deleted with its test. * fix(macos): preserve structured node worker diagnostics in status menu * feat(macos): highlight hosted menu rows from AppKit's selection signal AppKit paints no selection behind NSMenuItem.view, so hosted session and device rows had no hover or keyboard highlight. HostedMenuRowView now draws the native selection material (rounded, emphasized) and flips the SwiftUI content through the existing menuItemHighlighted environment, driven by NSMenuDelegate.menu(_:willHighlight:) so pointer and arrow-key navigation both light up. Submenus get a shared highlight-only delegate; the controller's root-menu guards keep open/refresh paths unaffected. * refactor(macos): drop the manual Open Canvas action Canvas panels are agent-opened; a manual open action was noise. The Allow Canvas capability tile stays - that is the permission. Removes the menu action, the dock-menu item, and the now-orphaned AppNavigationActions.toggleCanvas. * fix(macos): clear hosted submenu selection when the submenu closes AppKit sends no willHighlight(nil) on submenu close, so a hosted device row selected there reopened still lit. The shared highlight delegate now resets its menu's hosted rows in menuDidClose; regression covers the close cycle. * style(macos): apply swiftformat to highlight delegate
52 lines
2.3 KiB
Swift
52 lines
2.3 KiB
Swift
import AppKit
|
|
|
|
/// Single owner of the status menu's width. Every row - hosted card or native
|
|
/// item - is built to this width, so the menu never sizes itself from content.
|
|
@MainActor
|
|
enum StatusMenuMetrics {
|
|
static let width: CGFloat = 330
|
|
|
|
/// Truncates a native row title to the width budget with a middle ellipsis.
|
|
/// Hosted cards do not need this: the renderer frames them at `width`.
|
|
static func fittedTitle(_ title: String) -> String {
|
|
let budget = self.titleWidthBudget
|
|
guard self.measuredWidth(title) > budget else { return title }
|
|
let characters = Array(title)
|
|
var bounds = (lower: 0, upper: characters.count)
|
|
var fitted = "…"
|
|
while bounds.lower <= bounds.upper {
|
|
let count = (bounds.lower + bounds.upper) / 2
|
|
let prefix = (count + 1) / 2
|
|
let candidate = String(characters.prefix(prefix)) + "…" + String(characters.suffix(count - prefix))
|
|
if self.measuredWidth(candidate) <= budget {
|
|
fitted = candidate
|
|
bounds.lower = count + 1
|
|
} else {
|
|
bounds.upper = count - 1
|
|
}
|
|
}
|
|
return fitted
|
|
}
|
|
|
|
/// AppKit aligns the image, submenu, and shortcut columns across every item
|
|
/// in a menu, so the budget is menu-wide rather than per item: this menu
|
|
/// always carries all three (icons on actions, submenus on sessions and
|
|
/// summaries, shortcuts on Settings and Quit).
|
|
static let titleWidthBudget: CGFloat = {
|
|
let probe = NSMenuItem(title: "M", action: nil, keyEquivalent: "q")
|
|
probe.image = NSImage(systemSymbolName: "circle", accessibilityDescription: nil)
|
|
let cell = NSMenuItemCell(textCell: probe.title)
|
|
cell.menuItem = probe
|
|
cell.font = NSFont.menuFont(ofSize: 0)
|
|
cell.calcSize()
|
|
var chrome = cell.cellSize.width - StatusMenuMetrics.measuredWidth(probe.title)
|
|
chrome += cell.stateImageWidth + StatusMenuMetrics.measuredWidth("▶")
|
|
chrome += cell.stateImageWidth + StatusMenuMetrics.measuredWidth("⌘q")
|
|
return StatusMenuMetrics.width - chrome
|
|
}()
|
|
|
|
private static func measuredWidth(_ value: String) -> CGFloat {
|
|
(value as NSString).size(withAttributes: [.font: NSFont.menuFont(ofSize: 0)]).width
|
|
}
|
|
}
|