Some checks failed
ClawSweeper Dispatch / dispatch (push) Has been cancelled
CodeQL / Security High (actions) (push) Has been cancelled
CodeQL / Security High (channel-runtime-boundary) (push) Has been cancelled
CodeQL / Security High (core-auth-secrets) (push) Has been cancelled
CodeQL / Security High (mcp-process-tool-boundary) (push) Has been cancelled
CodeQL / Security High (network-ssrf-boundary) (push) Has been cancelled
CodeQL / Security High (plugin-trust-boundary) (push) Has been cancelled
CodeQL / Security High (process-exec-boundary) (push) Has been cancelled
Docs Sync Publish Repo / sync-publish-repo (push) Has been cancelled
Docs / docs (push) Has been cancelled
OpenClaw Stable Main Closeout / Resolve stable release closeout inputs (push) Has been cancelled
OpenClaw Stable Main Closeout / Verify stable main closeout (push) Has been cancelled
Workflow Sanity / no-tabs (push) Has been cancelled
Workflow Sanity / actionlint (push) Has been cancelled
Workflow Sanity / generated-doc-baselines (push) Has been cancelled
CI / runner-admission (push) Has been cancelled
CI / preflight (push) Has been cancelled
CI / security-fast (push) Has been cancelled
CI / pnpm-store-warmup (push) Has been cancelled
CI / build-artifacts (push) Has been cancelled
CI / native-i18n (push) Has been cancelled
CI / ${{ matrix.check_name }} (push) Has been cancelled
CI / ${{ matrix.checkName }} (push) Has been cancelled
CI / checks-node-compat-node22 (push) Has been cancelled
CI / check-bundled-channel-config-metadata (push) Has been cancelled
CI / check-dependencies (push) Has been cancelled
CI / check-guards (push) Has been cancelled
CI / check-lint (push) Has been cancelled
CI / check-prod-types (push) Has been cancelled
CI / check-shrinkwrap (push) Has been cancelled
CI / check-test-types (push) Has been cancelled
CI / check-additional-boundaries-a (push) Has been cancelled
CI / check-additional-boundaries-bcd (push) Has been cancelled
CI / check-additional-extension-bundled (push) Has been cancelled
CI / check-additional-extension-channels (push) Has been cancelled
CI / check-additional-extension-package-boundary (push) Has been cancelled
CI / check-additional-runtime-topology-architecture (push) Has been cancelled
CI / check-session-accessor-boundary (push) Has been cancelled
CI / check-session-transcript-reader-boundary (push) Has been cancelled
CI / check-docs (push) Has been cancelled
CI / skills-python (push) Has been cancelled
CI / macos-swift (push) Has been cancelled
CI / ios-build (push) Has been cancelled
CI / ci-timings-summary (push) Has been cancelled
Native App Locale Refresh / Refresh native fa (push) Has been cancelled
Native App Locale Refresh / Refresh native fr (push) Has been cancelled
Native App Locale Refresh / Refresh native hi (push) Has been cancelled
Native App Locale Refresh / Refresh native id (push) Has been cancelled
Native App Locale Refresh / Refresh native it (push) Has been cancelled
Native App Locale Refresh / Refresh native ja-JP (push) Has been cancelled
Control UI Locale Refresh / plan (push) Has been cancelled
Control UI Locale Refresh / Refresh ${{ matrix.locale }} (push) Has been cancelled
Control UI Locale Refresh / Commit control UI locale refresh (push) Has been cancelled
Live Media Runner Image / Build live media runner image (push) Has been cancelled
Native App Locale Refresh / Refresh native ar (push) Has been cancelled
Native App Locale Refresh / Refresh native de (push) Has been cancelled
Native App Locale Refresh / Refresh native es (push) Has been cancelled
Native App Locale Refresh / Refresh native ko (push) Has been cancelled
Native App Locale Refresh / Refresh native nl (push) Has been cancelled
Native App Locale Refresh / Refresh native pl (push) Has been cancelled
Native App Locale Refresh / Refresh native pt-BR (push) Has been cancelled
Native App Locale Refresh / Refresh native ru (push) Has been cancelled
Native App Locale Refresh / Refresh native sv (push) Has been cancelled
Native App Locale Refresh / Refresh native th (push) Has been cancelled
Native App Locale Refresh / Refresh native tr (push) Has been cancelled
Native App Locale Refresh / Refresh native uk (push) Has been cancelled
Native App Locale Refresh / Refresh native vi (push) Has been cancelled
Native App Locale Refresh / Refresh native zh-CN (push) Has been cancelled
Native App Locale Refresh / Refresh native zh-TW (push) Has been cancelled
Native App Locale Refresh / Commit native locale refresh (push) Has been cancelled
Plugin Init Scaffold Validation / Validate provider scaffold (push) Has been cancelled
Plugin NPM Release / preview_plugins_npm (push) Has been cancelled
Plugin NPM Release / Validate release publish approval (push) Has been cancelled
Plugin NPM Release / preview_plugin_pack (push) Has been cancelled
Plugin NPM Release / publish_plugins_npm (push) Has been cancelled
Sandbox Common Smoke / sandbox-common-smoke (push) Has been cancelled
Website Installer Sync / static (push) Has been cancelled
Website Installer Sync / linux-docker (push) Has been cancelled
Website Installer Sync / macos-installer (push) Has been cancelled
Website Installer Sync / windows-installer (push) Has been cancelled
Website Installer Sync / sync-website (push) Has been cancelled
Adolf is a fork/vendored clone of github.com/openclaw/openclaw (v2026.6.11), free to diverge. Tree copied sans upstream .git; upstream remote added for future syncs. Node pinned to 24 (.nvmrc); engines already require >=22.19. Preserves docs/ARCHITECTURE.md. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LeqyaxJF2nbRXJtae2kNB2
270 lines
8.9 KiB
Swift
270 lines
8.9 KiB
Swift
import AppKit
|
|
import Observation
|
|
import QuartzCore
|
|
import SwiftUI
|
|
|
|
/// Hover-only HUD anchored to the menu bar item. Click expands into full Web Chat.
|
|
@MainActor
|
|
@Observable
|
|
final class HoverHUDController {
|
|
static let shared = HoverHUDController()
|
|
|
|
struct Model {
|
|
var isVisible: Bool = false
|
|
var isSuppressed: Bool = false
|
|
var hoveringStatusItem: Bool = false
|
|
var hoveringPanel: Bool = false
|
|
}
|
|
|
|
private(set) var model = Model()
|
|
|
|
private var window: NSPanel?
|
|
private var hostingView: NSHostingView<HoverHUDView>?
|
|
private var dismissMonitor: Any?
|
|
private var dismissTask: Task<Void, Never>?
|
|
private var showTask: Task<Void, Never>?
|
|
private var anchorProvider: (() -> NSRect?)?
|
|
|
|
private let width: CGFloat = 360
|
|
private let height: CGFloat = 74
|
|
private let padding: CGFloat = 8
|
|
private let hoverShowDelay: TimeInterval = 0.18
|
|
|
|
func setSuppressed(_ suppressed: Bool) {
|
|
self.model.isSuppressed = suppressed
|
|
if suppressed {
|
|
self.showTask?.cancel()
|
|
self.showTask = nil
|
|
self.dismiss(reason: "suppressed")
|
|
}
|
|
}
|
|
|
|
func statusItemHoverChanged(inside: Bool, anchorProvider: @escaping () -> NSRect?) {
|
|
self.model.hoveringStatusItem = inside
|
|
self.anchorProvider = anchorProvider
|
|
|
|
guard !self.model.isSuppressed else { return }
|
|
|
|
if inside {
|
|
self.dismissTask?.cancel()
|
|
self.dismissTask = nil
|
|
self.showTask?.cancel()
|
|
self.showTask = Task { [weak self] in
|
|
guard let self else { return }
|
|
try? await Task.sleep(nanoseconds: UInt64(self.hoverShowDelay * 1_000_000_000))
|
|
await MainActor.run { [weak self] in
|
|
guard let self else { return }
|
|
guard !Task.isCancelled else { return }
|
|
guard self.model.hoveringStatusItem else { return }
|
|
guard !self.model.isSuppressed else { return }
|
|
self.present()
|
|
}
|
|
}
|
|
} else {
|
|
self.showTask?.cancel()
|
|
self.showTask = nil
|
|
self.scheduleDismiss()
|
|
}
|
|
}
|
|
|
|
func panelHoverChanged(inside: Bool) {
|
|
self.model.hoveringPanel = inside
|
|
if inside {
|
|
self.dismissTask?.cancel()
|
|
self.dismissTask = nil
|
|
} else if !self.model.hoveringStatusItem {
|
|
self.scheduleDismiss()
|
|
}
|
|
}
|
|
|
|
func openChat() {
|
|
guard let anchorProvider = self.anchorProvider else { return }
|
|
self.dismiss(reason: "openChat")
|
|
Task { @MainActor in
|
|
let sessionKey = await WebChatManager.shared.preferredSessionKey()
|
|
WebChatManager.shared.togglePanel(sessionKey: sessionKey, anchorProvider: anchorProvider)
|
|
}
|
|
}
|
|
|
|
func dismiss(reason: String = "explicit") {
|
|
self.dismissTask?.cancel()
|
|
self.dismissTask = nil
|
|
self.removeDismissMonitor()
|
|
guard let window else {
|
|
self.model.isVisible = false
|
|
return
|
|
}
|
|
|
|
if !self.model.isVisible {
|
|
window.orderOut(nil)
|
|
return
|
|
}
|
|
|
|
OverlayPanelFactory.animateDismissAndHide(window: window, offsetX: 0, offsetY: 6, duration: 0.14) {
|
|
self.model.isVisible = false
|
|
}
|
|
}
|
|
|
|
// MARK: - Private
|
|
|
|
private func scheduleDismiss() {
|
|
self.dismissTask?.cancel()
|
|
self.dismissTask = Task { [weak self] in
|
|
try? await Task.sleep(nanoseconds: 250_000_000)
|
|
await MainActor.run {
|
|
guard let self else { return }
|
|
if self.model.hoveringStatusItem || self.model.hoveringPanel { return }
|
|
self.dismiss(reason: "hoverExit")
|
|
}
|
|
}
|
|
}
|
|
|
|
private func present() {
|
|
guard !self.model.isSuppressed else { return }
|
|
self.ensureWindow()
|
|
self.hostingView?.rootView = HoverHUDView(controller: self)
|
|
let target = self.targetFrame()
|
|
|
|
guard let window else { return }
|
|
self.installDismissMonitor()
|
|
|
|
if !self.model.isVisible {
|
|
self.model.isVisible = true
|
|
let start = target.offsetBy(dx: 0, dy: 8)
|
|
OverlayPanelFactory.animatePresent(window: window, from: start, to: target)
|
|
} else {
|
|
window.orderFrontRegardless()
|
|
self.updateWindowFrame(animate: true)
|
|
}
|
|
}
|
|
|
|
private func ensureWindow() {
|
|
if self.window != nil { return }
|
|
let panel = OverlayPanelFactory.makePanel(
|
|
contentRect: NSRect(x: 0, y: 0, width: self.width, height: self.height),
|
|
level: .statusBar,
|
|
hasShadow: true)
|
|
|
|
let host = NSHostingView(rootView: HoverHUDView(controller: self))
|
|
host.translatesAutoresizingMaskIntoConstraints = false
|
|
panel.contentView = host
|
|
self.hostingView = host
|
|
self.window = panel
|
|
}
|
|
|
|
private func targetFrame() -> NSRect {
|
|
guard let anchor = self.anchorProvider?() else {
|
|
return WindowPlacement.topRightFrame(
|
|
size: NSSize(width: self.width, height: self.height),
|
|
padding: self.padding)
|
|
}
|
|
|
|
let screen = NSScreen.screens.first { screen in
|
|
screen.frame.contains(anchor.origin) || screen.frame.contains(NSPoint(x: anchor.midX, y: anchor.midY))
|
|
} ?? NSScreen.main
|
|
|
|
let bounds = (screen?.visibleFrame ?? .zero).insetBy(dx: self.padding, dy: self.padding)
|
|
return WindowPlacement.anchoredBelowFrame(
|
|
size: NSSize(width: self.width, height: self.height),
|
|
anchor: anchor,
|
|
padding: self.padding,
|
|
in: bounds)
|
|
}
|
|
|
|
private func updateWindowFrame(animate: Bool = false) {
|
|
OverlayPanelFactory.applyFrame(window: self.window, target: self.targetFrame(), animate: animate)
|
|
}
|
|
|
|
private func installDismissMonitor() {
|
|
if ProcessInfo.processInfo.isRunningTests { return }
|
|
guard self.dismissMonitor == nil, let window else { return }
|
|
self.dismissMonitor = NSEvent.addGlobalMonitorForEvents(matching: [
|
|
.leftMouseDown,
|
|
.rightMouseDown,
|
|
.otherMouseDown,
|
|
]) { [weak self] _ in
|
|
guard let self, self.model.isVisible else { return }
|
|
let pt = NSEvent.mouseLocation
|
|
if !window.frame.contains(pt) {
|
|
Task { @MainActor in self.dismiss(reason: "outsideClick") }
|
|
}
|
|
}
|
|
}
|
|
|
|
private func removeDismissMonitor() {
|
|
OverlayPanelFactory.clearGlobalEventMonitor(&self.dismissMonitor)
|
|
}
|
|
}
|
|
|
|
private struct HoverHUDView: View {
|
|
var controller: HoverHUDController
|
|
private let activityStore = WorkActivityStore.shared
|
|
|
|
private var statusTitle: String {
|
|
if self.activityStore.iconState.isWorking { return "Working" }
|
|
return "Idle"
|
|
}
|
|
|
|
private var detail: String {
|
|
if let current = self.activityStore.current?.label, !current.isEmpty { return current }
|
|
if let last = self.activityStore.lastToolLabel, !last.isEmpty { return last }
|
|
return "No recent activity"
|
|
}
|
|
|
|
private var symbolName: String {
|
|
if self.activityStore.iconState.isWorking {
|
|
return self.activityStore.iconState.badgeSymbolName
|
|
}
|
|
return "moon.zzz.fill"
|
|
}
|
|
|
|
private var dotColor: Color {
|
|
if self.activityStore.iconState.isWorking {
|
|
return Color(nsColor: NSColor.systemGreen.withAlphaComponent(0.7))
|
|
}
|
|
return .secondary
|
|
}
|
|
|
|
var body: some View {
|
|
HStack(alignment: .top, spacing: 10) {
|
|
Circle()
|
|
.fill(self.dotColor)
|
|
.frame(width: 7, height: 7)
|
|
.padding(.top, 5)
|
|
|
|
VStack(alignment: .leading, spacing: 4) {
|
|
Text(self.statusTitle)
|
|
.font(.system(size: 13, weight: .semibold))
|
|
.foregroundStyle(.primary)
|
|
Text(self.detail)
|
|
.font(.system(size: 12))
|
|
.foregroundStyle(.secondary)
|
|
.lineLimit(2)
|
|
.truncationMode(.middle)
|
|
.fixedSize(horizontal: false, vertical: true)
|
|
}
|
|
|
|
Spacer(minLength: 8)
|
|
|
|
Image(systemName: self.symbolName)
|
|
.font(.system(size: 14, weight: .semibold))
|
|
.foregroundStyle(.secondary)
|
|
.padding(.top, 1)
|
|
}
|
|
.padding(12)
|
|
.background(
|
|
RoundedRectangle(cornerRadius: 14, style: .continuous)
|
|
.fill(.regularMaterial))
|
|
.overlay(
|
|
RoundedRectangle(cornerRadius: 14, style: .continuous)
|
|
.strokeBorder(Color.black.opacity(0.10), lineWidth: 1))
|
|
.contentShape(Rectangle())
|
|
.onHover { inside in
|
|
self.controller.panelHoverChanged(inside: inside)
|
|
}
|
|
.onTapGesture {
|
|
self.controller.openChat()
|
|
}
|
|
}
|
|
}
|