mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-12 07:20:45 +00:00
🤖 macos: force session preview submenu repaint after async load (#13890)
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user