Skip to content

Commit 5fdba1d

Browse files
bkudiessCopilot
andcommitted
Merge origin/main into calebeden-restore-compaction-card
Co-authored-by: Copilot App <[email protected]>
2 parents 81f8098 + ff19012 commit 5fdba1d

17 files changed

Lines changed: 610 additions & 748 deletions

‎src/OpenClaw.Tray.WinUI/App.xaml‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@
3434
<SolidColorBrush x:Key="SubtleFillColorSecondaryBrush" Color="{ThemeResource SubtleFillColorSecondary}" />
3535
<SolidColorBrush x:Key="SubtleFillColorTertiaryBrush" Color="{ThemeResource SubtleFillColorTertiary}" />
3636
<SolidColorBrush x:Key="TextFillColorSecondaryBrush" Color="{ThemeResource TextFillColorSecondary}" />
37+
<SolidColorBrush x:Key="ConnectionCapabilityPillSuccessBrush" Color="{ThemeResource SystemFillColorSuccess}" Opacity="0.14" />
38+
<SolidColorBrush x:Key="ConnectionCapabilityPillCautionBrush" Color="{ThemeResource SystemFillColorCaution}" Opacity="0.14" />
39+
<SolidColorBrush x:Key="ConnectionCapabilityPillCriticalBrush" Color="{ThemeResource SystemFillColorCritical}" Opacity="0.14" />
40+
<SolidColorBrush x:Key="ChatUserBubbleSelectionHighlightBrush" Color="{ThemeResource SystemAccentColorDark2}" />
41+
<x:Double x:Key="ChatAccessibleBorderThickness">1</x:Double>
42+
<x:Boolean x:Key="HubNavigationUseHighContrastIcons">False</x:Boolean>
3743

3844
<!-- Composer scrim: the chat timeline dissolves into the composer dock via a
3945
vertical fade from transparent to the base surface fill. FunctionalUI
@@ -57,6 +63,12 @@
5763
<SolidColorBrush x:Key="SubtleFillColorSecondaryBrush" Color="{ThemeResource SubtleFillColorSecondary}" />
5864
<SolidColorBrush x:Key="SubtleFillColorTertiaryBrush" Color="{ThemeResource SubtleFillColorTertiary}" />
5965
<SolidColorBrush x:Key="TextFillColorSecondaryBrush" Color="{ThemeResource TextFillColorSecondary}" />
66+
<SolidColorBrush x:Key="ConnectionCapabilityPillSuccessBrush" Color="{ThemeResource SystemFillColorSuccess}" Opacity="0.14" />
67+
<SolidColorBrush x:Key="ConnectionCapabilityPillCautionBrush" Color="{ThemeResource SystemFillColorCaution}" Opacity="0.14" />
68+
<SolidColorBrush x:Key="ConnectionCapabilityPillCriticalBrush" Color="{ThemeResource SystemFillColorCritical}" Opacity="0.14" />
69+
<SolidColorBrush x:Key="ChatUserBubbleSelectionHighlightBrush" Color="{ThemeResource SystemAccentColorDark2}" />
70+
<x:Double x:Key="ChatAccessibleBorderThickness">1</x:Double>
71+
<x:Boolean x:Key="HubNavigationUseHighContrastIcons">False</x:Boolean>
6072

6173
<!-- Light mirror of ChatComposerFadeBrush (SolidBackgroundFillColorBase light #F3F3F3). -->
6274
<LinearGradientBrush x:Key="ChatComposerFadeBrush" StartPoint="0,0" EndPoint="0,1">
@@ -74,6 +86,12 @@
7486
<SolidColorBrush x:Key="SubtleFillColorSecondaryBrush" Color="{ThemeResource SystemColorButtonFaceColor}" />
7587
<SolidColorBrush x:Key="SubtleFillColorTertiaryBrush" Color="{ThemeResource SystemColorButtonFaceColor}" />
7688
<SolidColorBrush x:Key="TextFillColorSecondaryBrush" Color="{ThemeResource SystemColorWindowTextColor}" />
89+
<SolidColorBrush x:Key="ConnectionCapabilityPillSuccessBrush" Color="{ThemeResource SystemColorWindowColor}" />
90+
<SolidColorBrush x:Key="ConnectionCapabilityPillCautionBrush" Color="{ThemeResource SystemColorWindowColor}" />
91+
<SolidColorBrush x:Key="ConnectionCapabilityPillCriticalBrush" Color="{ThemeResource SystemColorWindowColor}" />
92+
<SolidColorBrush x:Key="ChatUserBubbleSelectionHighlightBrush" Color="{ThemeResource SystemColorHighlightColor}" />
93+
<x:Double x:Key="ChatAccessibleBorderThickness">2</x:Double>
94+
<x:Boolean x:Key="HubNavigationUseHighContrastIcons">True</x:Boolean>
7795

7896
<!-- High-contrast follows the system window color so the scrim stays legible. -->
7997
<LinearGradientBrush x:Key="ChatComposerFadeBrush" StartPoint="0,0" EndPoint="0,1">
@@ -83,6 +101,20 @@
83101
</ResourceDictionary>
84102
</ResourceDictionary.ThemeDictionaries>
85103

104+
<Style x:Key="ChatUserBubbleSelectionStyle" TargetType="RichTextBlock">
105+
<Setter Property="SelectionHighlightColor" Value="{ThemeResource ChatUserBubbleSelectionHighlightBrush}"/>
106+
</Style>
107+
<Style x:Key="ChatToolCardBorderStyle" TargetType="Border">
108+
<Setter Property="Background" Value="{ThemeResource CardBackgroundFillColorDefaultBrush}"/>
109+
<Setter Property="BorderBrush" Value="{ThemeResource ControlStrokeColorDefaultBrush}"/>
110+
<Setter Property="BorderThickness" Value="{ThemeResource ChatAccessibleBorderThickness}"/>
111+
</Style>
112+
<Style x:Key="ChatCompactionCardStyle" TargetType="Border">
113+
<Setter Property="Background" Value="{ThemeResource CardBackgroundFillColorDefaultBrush}"/>
114+
<Setter Property="BorderBrush" Value="{ThemeResource ControlStrokeColorDefaultBrush}"/>
115+
<Setter Property="BorderThickness" Value="{ThemeResource ChatAccessibleBorderThickness}"/>
116+
</Style>
117+
86118
<!-- Hub NavigationView selection indicator follows the user's Windows accent. -->
87119
<SolidColorBrush x:Key="NavigationViewSelectionIndicatorForeground"
88120
Color="{ThemeResource SystemAccentColor}"/>

‎src/OpenClaw.Tray.WinUI/Chat/OpenClawChatTimeline.cs‎

Lines changed: 3 additions & 149 deletions
Original file line numberDiff line numberDiff line change
@@ -207,121 +207,6 @@ private static FontFamily s_chatTextFontFamily
207207
}
208208
}
209209

210-
// Per-DispatcherQueue selection-highlight brushes for the user
211-
// bubble. The bubble background is the user's chosen system accent
212-
// (which may be red, green, purple, …), so a hardcoded color would
213-
// clash whenever the accent is non-blue. SystemAccentColorDark2 is
214-
// the OS-defined "darker shade of the current accent" — guaranteed
215-
// darker than the bubble's AccentFillColorDefault background and
216-
// high-contrast against the bubble's white foreground for every
217-
// accent. In High Contrast the bubble switches to
218-
// SystemColorHighlight (often near-black), so we fall back to the
219-
// OS-guaranteed SystemColorHighlightColor for the band there.
220-
//
221-
// SolidColorBrush is a DependencyObject with thread affinity, so a
222-
// single static instance would crash with RPC_E_WRONG_THREAD if a
223-
// second window on a different dispatcher ever tried to use it.
224-
// Keying by DispatcherQueue keeps one shared brush per window while
225-
// still avoiding per-render allocation. ConditionalWeakTable lets a
226-
// closing window's brush be collected with its dispatcher. The
227-
// brush's Color is mutated in place when the source color changes
228-
// (e.g. user switches their accent in Windows Settings) so
229-
// already-rendered TextBlocks update atomically.
230-
private static readonly System.Runtime.CompilerServices.ConditionalWeakTable<
231-
Microsoft.UI.Dispatching.DispatcherQueue, SolidColorBrush> s_accentDarkByDispatcher = new();
232-
private static readonly System.Runtime.CompilerServices.ConditionalWeakTable<
233-
Microsoft.UI.Dispatching.DispatcherQueue, SolidColorBrush> s_hcHighlightByDispatcher = new();
234-
// AccessibilitySettings is a WinRT object with DispatcherQueue
235-
// affinity: an instance created on one dispatcher cannot reliably
236-
// be read from another. We deliberately avoid Lazy<>: Lazy
237-
// permanently caches the factory's result, so a single failed
238-
// construction would cache null forever and silently disable the
239-
// High Contrast code path. Per-dispatcher cache keyed by
240-
// ConditionalWeakTable lets each window have its own instance,
241-
// collected when its dispatcher dies. On any thrown exception we
242-
// drop the cached instance so the next render retries from scratch.
243-
private static readonly System.Runtime.CompilerServices.ConditionalWeakTable<
244-
Microsoft.UI.Dispatching.DispatcherQueue,
245-
global::Windows.UI.ViewManagement.AccessibilitySettings> s_a11yByDispatcher = new();
246-
247-
private static bool TryDetectHighContrast()
248-
{
249-
var dispatcher = Microsoft.UI.Dispatching.DispatcherQueue.GetForCurrentThread();
250-
if (dispatcher is null)
251-
{
252-
// Off-thread caller (tests, design-time). One-shot, no caching.
253-
try { return new global::Windows.UI.ViewManagement.AccessibilitySettings().HighContrast; }
254-
catch { return false; }
255-
}
256-
if (!s_a11yByDispatcher.TryGetValue(dispatcher, out var settings))
257-
{
258-
try
259-
{
260-
settings = new global::Windows.UI.ViewManagement.AccessibilitySettings();
261-
s_a11yByDispatcher.Add(dispatcher, settings);
262-
}
263-
catch { return false; }
264-
}
265-
try { return settings.HighContrast; }
266-
catch
267-
{
268-
// Drop the cached instance so the next call retries.
269-
s_a11yByDispatcher.Remove(dispatcher);
270-
return false;
271-
}
272-
}
273-
274-
private static SolidColorBrush GetUserBubbleSelectionBrush(bool isHighContrast)
275-
{
276-
var dispatcher = Microsoft.UI.Dispatching.DispatcherQueue.GetForCurrentThread();
277-
var table = isHighContrast ? s_hcHighlightByDispatcher : s_accentDarkByDispatcher;
278-
var color = isHighContrast
279-
? TryGetThemeColor("SystemColorHighlightColor", Microsoft.UI.Colors.Blue)
280-
: TryGetThemeColor("SystemAccentColorDark2", Microsoft.UI.Colors.DarkBlue);
281-
282-
// No dispatcher means we're being called off-thread (e.g.
283-
// from a unit test). Allocate a one-shot brush — it can't be
284-
// safely cached without a dispatcher to key it on.
285-
if (dispatcher is null)
286-
return new SolidColorBrush(color);
287-
288-
if (!table.TryGetValue(dispatcher, out var brush))
289-
{
290-
brush = new SolidColorBrush(color);
291-
table.Add(dispatcher, brush);
292-
}
293-
else if (brush.Color != color)
294-
{
295-
// Mutate in place rather than reallocating: TextBlocks
296-
// rendered earlier hold a reference to this brush, so
297-
// updating .Color updates them atomically without waiting
298-
// for the next render pass.
299-
brush.Color = color;
300-
}
301-
return brush;
302-
}
303-
304-
private static Color TryGetThemeColor(string key, Color fallback)
305-
{
306-
try
307-
{
308-
var app = Application.Current;
309-
if (app is null) return fallback;
310-
if (app.Resources.TryGetValue(key, out var v))
311-
{
312-
// Theme dictionaries usually store Color, but a custom
313-
// theme override can supply a SolidColorBrush under the
314-
// same key. Accept either rather than silently falling
315-
// back to DarkBlue / Blue when the resource is present
316-
// but wrapped in a brush.
317-
if (v is Color c) return c;
318-
if (v is SolidColorBrush brush) return brush.Color;
319-
}
320-
}
321-
catch (Exception ex) { OpenClawTray.Services.Logger.Debug($"ChatTimeline: resource brush lookup failed (unpackaged/test host?): {ex.Message}"); }
322-
return fallback;
323-
}
324-
325210
private static void ApplyPlainSelectableInlines(TextBlock textBlock, string? text)
326211
{
327212
var normalized = text ?? string.Empty;
@@ -1020,12 +905,7 @@ static Element TimelineInset(Element child, double top = 2, double bottom = 2) =
1020905
// the bubble surface below is opaque (Mica/acrylic isn't being
1021906
// used directly), so the LayerOnAcrylic family would render
1022907
// incorrectly in dark/HC themes.
1023-
var toolCardBgBrush = themeBrush("CardBackgroundFillColorDefaultBrush");
1024908
var toolCardBorderBrush = themeBrush("ControlStrokeColorDefaultBrush");
1025-
// High-contrast themes need a thicker border to render at all
1026-
// (WinUI guidance: 2px minimum). Detect once at render time so the
1027-
// tool card border stays visible when HC is on, normal 1px otherwise.
1028-
double toolCardBorderThickness = TryDetectHighContrast() ? 2 : 1;
1029909

1030910
// Avatar: 36×36 circle (Kenny uses circular avatars). Same constructor
1031911
// as before but radius defaults to half the size for a perfect circle.
@@ -1409,12 +1289,6 @@ Element RenderUserEntry(ChatTimelineItem entry, bool startsBurst, bool endsBurst
14091289
var entryMeta = MetaFor(entry.Id);
14101290
if (hasMessage)
14111291
{
1412-
// Resolve HC + selection brush once per render method call
1413-
// rather than per Set-lambda re-run. HC state cannot change
1414-
// mid-render, and the brush is cached per-dispatcher so
1415-
// every user bubble in this render shares the same instance.
1416-
bool isHighContrast = TryDetectHighContrast();
1417-
var selectionHighlightBrush = GetUserBubbleSelectionBrush(isHighContrast);
14181292
bubbleChildren.Add(
14191293
RichTextBlock()
14201294
.Set(t =>
@@ -1431,23 +1305,7 @@ Element RenderUserEntry(ChatTimelineItem entry, bool startsBurst, bool endsBurst
14311305
t.Width = double.NaN;
14321306
t.MinWidth = 0;
14331307
t.MaxWidth = double.PositiveInfinity;
1434-
// The default SelectionHighlightColor is the
1435-
// system accent — which equals the user bubble's
1436-
// background — so the highlight band is invisible
1437-
// against the bubble, and WinUI does NOT auto-
1438-
// invert an explicitly-set Foreground for
1439-
// selected glyphs. Outside High Contrast, use a
1440-
// darker shade of the current accent
1441-
// (SystemAccentColorDark2) so the band tracks
1442-
// whichever accent the user picked while keeping
1443-
// the white foreground readable. In High Contrast
1444-
// the bubble background switches to
1445-
// SystemColorHighlight (often near-black), where
1446-
// an accent-derived band may drop below WCAG
1447-
// 3:1, so fall back to the system selection
1448-
// color the OS guarantees contrasts with both
1449-
// surfaces.
1450-
t.SelectionHighlightColor = selectionHighlightBrush;
1308+
t.Style = (Style)Application.Current.Resources["ChatUserBubbleSelectionStyle"];
14511309
// Render the message as a single Paragraph (one Run)
14521310
// so the whole user message is one continuous
14531311
// selection scope — matching the assistant bubble's
@@ -1974,10 +1832,9 @@ Element PhantomChevron() => Caption("▸")
19741832
ToolName: null, ToolResult: aggregateStatus, ToolOutput: null));
19751833

19761834
Element CardOf(Element[] rowEls) => Border(VStack(0, rowEls))
1977-
.Background(toolCardBgBrush)
1978-
.WithBorder(toolCardBorderBrush, toolCardBorderThickness)
19791835
.Set(b =>
19801836
{
1837+
b.Style = (Style)Application.Current.Resources["ChatToolCardBorderStyle"];
19811838
// CornerRadius is uniform across the card; setting it
19821839
// directly works because rounding nests under the
19831840
// Border's BorderThickness.
@@ -2349,8 +2206,6 @@ Element RenderCompactionEntry(ChatTimelineItem entry)
23492206
LocalizationHelper.GetString("Chat_Compaction_Title"),
23502207
LocalizationHelper.GetString("Chat_Compaction_MetricsFormat"),
23512208
LocalizationHelper.GetString("Chat_Compaction_FallbackDetail"));
2352-
var borderThickness = TryDetectHighContrast() ? 2 : 1;
2353-
23542209
return TimelineInset(
23552210
Border(
23562211
VStack(3,
@@ -2368,8 +2223,7 @@ Element RenderCompactionEntry(ChatTimelineItem entry)
23682223
t.TextAlignment = TextAlignment.Center;
23692224
}).Foreground(themeBrush("TextFillColorSecondaryBrush"))
23702225
)
2371-
).Background(themeBrush("CardBackgroundFillColorDefaultBrush"))
2372-
.WithBorder(themeBrush("ControlStrokeColorDefaultBrush"), borderThickness)
2226+
).Set(b => b.Style = (Style)Application.Current.Resources["ChatCompactionCardStyle"])
23732227
.CornerRadius(8)
23742228
.Padding(16, 10, 16, 10)
23752229
.HAlign(HorizontalAlignment.Stretch)

0 commit comments

Comments
 (0)