From 80b56cabc2d33b5f96fbd82bc6247ce5713e692b Mon Sep 17 00:00:00 2001 From: the sun gif man Date: Tue, 10 Feb 2026 21:11:04 -0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=A4=96=20macos:=20force=20session=20previ?= =?UTF-8?q?ew=20submenu=20repaint=20after=20async=20load=20(#13890)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../OpenClaw/MenuSessionsInjector.swift | 52 ++++++++++--------- 1 file changed, 28 insertions(+), 24 deletions(-) diff --git a/apps/macos/Sources/OpenClaw/MenuSessionsInjector.swift b/apps/macos/Sources/OpenClaw/MenuSessionsInjector.swift index 7ab9a64ca62..9b6bb099341 100644 --- a/apps/macos/Sources/OpenClaw/MenuSessionsInjector.swift +++ b/apps/macos/Sources/OpenClaw/MenuSessionsInjector.swift @@ -585,34 +585,38 @@ extension MenuSessionsInjector { let item = NSMenuItem() item.tag = self.tag item.isEnabled = false - let view = AnyView(SessionMenuPreviewView( - width: width, - maxLines: maxLines, - title: title, - items: [], - status: .loading)) - let hosting = NSHostingView(rootView: view) - hosting.frame.size.width = max(1, width) - let size = hosting.fittingSize - hosting.frame = NSRect(origin: .zero, size: NSSize(width: width, height: size.height)) - item.view = hosting + let view = AnyView( + SessionMenuPreviewView( + width: width, + maxLines: maxLines, + title: title, + items: [], + status: .loading) + .environment(\.isEnabled, true)) + let hosted = HighlightedMenuItemHostView(rootView: view, width: width) + item.view = hosted - let task = Task { [weak hosting] in + let task = Task { [weak hosted, weak item] in let snapshot = await SessionMenuPreviewLoader.load(sessionKey: sessionKey, maxItems: 10) guard !Task.isCancelled else { return } + await MainActor.run { - guard let hosting else { return } - let nextView = AnyView(SessionMenuPreviewView( - width: width, - maxLines: maxLines, - title: title, - items: snapshot.items, - status: snapshot.status)) - hosting.rootView = nextView - hosting.invalidateIntrinsicContentSize() - hosting.frame.size.width = max(1, width) - let size = hosting.fittingSize - hosting.frame.size.height = size.height + let nextView = AnyView( + SessionMenuPreviewView( + width: width, + maxLines: maxLines, + title: title, + items: snapshot.items, + status: snapshot.status) + .environment(\.isEnabled, true)) + + if let item { + item.view = HighlightedMenuItemHostView(rootView: nextView, width: width) + return + } + + guard let hosted else { return } + hosted.update(rootView: nextView, width: width) } } self.previewTasks.append(task)