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
154 lines
5.2 KiB
Swift
154 lines
5.2 KiB
Swift
import AppKit
|
|
import Observation
|
|
import QuartzCore
|
|
import SwiftUI
|
|
|
|
/// Lightweight, borderless panel for in-app "toast" notifications (bypasses macOS Notification Center).
|
|
@MainActor
|
|
@Observable
|
|
final class NotifyOverlayController {
|
|
static let shared = NotifyOverlayController()
|
|
|
|
private(set) var model = Model()
|
|
var isVisible: Bool {
|
|
self.model.isVisible
|
|
}
|
|
|
|
struct Model {
|
|
var title: String = ""
|
|
var body: String = ""
|
|
var isVisible: Bool = false
|
|
}
|
|
|
|
private var window: NSPanel?
|
|
private var hostingView: NSHostingView<NotifyOverlayView>?
|
|
private var dismissTask: Task<Void, Never>?
|
|
|
|
private let width: CGFloat = 360
|
|
private let padding: CGFloat = 12
|
|
private let maxHeight: CGFloat = 220
|
|
private let minHeight: CGFloat = 64
|
|
|
|
func present(title: String, body: String, autoDismissAfter: TimeInterval = 6) {
|
|
self.dismissTask?.cancel()
|
|
self.model.title = title
|
|
self.model.body = body
|
|
self.ensureWindow()
|
|
self.hostingView?.rootView = NotifyOverlayView(controller: self)
|
|
self.presentWindow()
|
|
|
|
if autoDismissAfter > 0 {
|
|
self.dismissTask = Task { [weak self] in
|
|
try? await Task.sleep(nanoseconds: UInt64(autoDismissAfter * 1_000_000_000))
|
|
await MainActor.run { self?.dismiss() }
|
|
}
|
|
}
|
|
}
|
|
|
|
func dismiss() {
|
|
self.dismissTask?.cancel()
|
|
self.dismissTask = nil
|
|
guard let window else { return }
|
|
|
|
OverlayPanelFactory.animateDismissAndHide(window: window, offsetX: 8, offsetY: 6) {
|
|
self.model.isVisible = false
|
|
}
|
|
}
|
|
|
|
// MARK: - Private
|
|
|
|
private func presentWindow() {
|
|
self.ensureWindow()
|
|
self.hostingView?.rootView = NotifyOverlayView(controller: self)
|
|
let target = self.targetFrame()
|
|
let isFirst = !self.model.isVisible
|
|
if isFirst { self.model.isVisible = true }
|
|
OverlayPanelFactory.present(
|
|
window: self.window,
|
|
isFirstPresent: isFirst,
|
|
target: target)
|
|
{ window in
|
|
self.updateWindowFrame(animate: true)
|
|
window.orderFrontRegardless()
|
|
}
|
|
}
|
|
|
|
private func ensureWindow() {
|
|
if self.window != nil { return }
|
|
let panel = OverlayPanelFactory.makePanel(
|
|
contentRect: NSRect(x: 0, y: 0, width: self.width, height: self.minHeight),
|
|
level: .statusBar,
|
|
hasShadow: true)
|
|
|
|
let host = NSHostingView(rootView: NotifyOverlayView(controller: self))
|
|
host.translatesAutoresizingMaskIntoConstraints = false
|
|
panel.contentView = host
|
|
self.hostingView = host
|
|
self.window = panel
|
|
}
|
|
|
|
private func targetFrame() -> NSRect {
|
|
guard let screen = NSScreen.main else { return .zero }
|
|
let height = self.measuredHeight()
|
|
let size = NSSize(width: self.width, height: height)
|
|
let visible = screen.visibleFrame
|
|
let origin = CGPoint(x: visible.maxX - size.width - 8, y: visible.maxY - size.height - 8)
|
|
return NSRect(origin: origin, size: size)
|
|
}
|
|
|
|
private func updateWindowFrame(animate: Bool = false) {
|
|
OverlayPanelFactory.applyFrame(window: self.window, target: self.targetFrame(), animate: animate)
|
|
}
|
|
|
|
private func measuredHeight() -> CGFloat {
|
|
let maxWidth = self.width - self.padding * 2
|
|
let titleFont = NSFont.systemFont(ofSize: 13, weight: .semibold)
|
|
let bodyFont = NSFont.systemFont(ofSize: 12, weight: .regular)
|
|
|
|
let titleRect = (self.model.title as NSString).boundingRect(
|
|
with: CGSize(width: maxWidth, height: .greatestFiniteMagnitude),
|
|
options: [.usesLineFragmentOrigin, .usesFontLeading],
|
|
attributes: [.font: titleFont],
|
|
context: nil)
|
|
|
|
let bodyRect = (self.model.body as NSString).boundingRect(
|
|
with: CGSize(width: maxWidth, height: .greatestFiniteMagnitude),
|
|
options: [.usesLineFragmentOrigin, .usesFontLeading],
|
|
attributes: [.font: bodyFont],
|
|
context: nil)
|
|
|
|
let contentHeight = ceil(titleRect.height + 6 + bodyRect.height)
|
|
let total = contentHeight + self.padding * 2
|
|
return max(self.minHeight, min(total, self.maxHeight))
|
|
}
|
|
}
|
|
|
|
private struct NotifyOverlayView: View {
|
|
var controller: NotifyOverlayController
|
|
|
|
var body: some View {
|
|
VStack(alignment: .leading, spacing: 6) {
|
|
Text(self.controller.model.title)
|
|
.font(.system(size: 13, weight: .semibold))
|
|
.foregroundStyle(.primary)
|
|
.lineLimit(1)
|
|
|
|
Text(self.controller.model.body)
|
|
.font(.system(size: 12))
|
|
.foregroundStyle(.secondary)
|
|
.lineLimit(4)
|
|
.fixedSize(horizontal: false, vertical: true)
|
|
}
|
|
.padding(12)
|
|
.background(
|
|
RoundedRectangle(cornerRadius: 12, style: .continuous)
|
|
.fill(.regularMaterial))
|
|
.overlay(
|
|
RoundedRectangle(cornerRadius: 12, style: .continuous)
|
|
.strokeBorder(Color.black.opacity(0.08), lineWidth: 1))
|
|
.onTapGesture {
|
|
self.controller.dismiss()
|
|
}
|
|
}
|
|
}
|