Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/OpenClaw.Tray.WinUI/Chat/ChannelGroup.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
namespace OpenClawTray.Chat;

public record ChannelGroup(string AgentLabel, (string Id, string Title)[] Sessions);
107 changes: 66 additions & 41 deletions src/OpenClaw.Tray.WinUI/Chat/OpenClawComposer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ namespace OpenClawTray.Chat;
/// banner that <c>InputBar</c> used to render are preserved here above the
/// composer.
/// </summary>
public record ChannelGroup(string AgentLabel, (string Id, string Title)[] Sessions);

public record OpenClawComposerProps(
string ConnectionState,
bool TurnActive,
Expand Down Expand Up @@ -249,10 +247,17 @@ public override Element Render()
// Build grouped session ComboBox directly (bypassing the FunctionalUI
// ComboBox helper which only supports flat string[] items).
var groups = Props.AvailableChannels;
var channelCombo = Border()
.Set(border =>
var channelComboRef = UseRef<ComboBox?>(null);
var channelGroupsRef = UseRef<SessionPickerSnapshot?>(null);
var channelChangedRef = UseRef(Props.OnChannelChanged);
var channelComboUpdatingRef = UseRef(false);
channelChangedRef.Current = Props.OnChannelChanged;
var channelCombo = Border(Native(() =>
{
var cb = channelComboRef.Current;
if (cb is null)
{
var cb = new ComboBox
cb = new ComboBox
{
MinWidth = 0,
Width = double.NaN,
Expand All @@ -266,49 +271,69 @@ public override Element Render()
Microsoft.UI.Xaml.Automation.AutomationProperties.SetName(
cb,
LocalizationHelper.GetString("Chat_Composer_Accessibility_Session"));
cb.SelectionChanged += (_, _) =>
{
if (!channelComboUpdatingRef.Current &&
cb.SelectedItem is ComboBoxItem { Tag: string id })
channelChangedRef.Current(id);
};
channelComboRef.Current = cb;
}

ComboBoxItem? selectedItem = null;
foreach (var group in groups)
return cb;
}))
.Set(_ =>
{
var cb = channelComboRef.Current;
if (cb is null) return;

var groupsChanged = channelGroupsRef.Current?.Matches(groups) != true;
channelComboUpdatingRef.Current = true;
try
{
if (groups.Length > 1)
{
cb.Items.Add(new ComboBoxItem
{
Content = group.AgentLabel,
IsEnabled = false,
FontWeight = Microsoft.UI.Text.FontWeights.SemiBold,
FontSize = 10,
Padding = new Thickness(4, 2, 4, 2),
IsHitTestVisible = false,
});
}
foreach (var session in group.Sessions)
if (groupsChanged)
{
var item = new ComboBoxItem
cb.Items.Clear();
foreach (var group in groups)
{
Content = session.Title,
Tag = session.Id,
Padding = groups.Length > 1
? new Thickness(16, 4, 4, 4)
: new Thickness(8, 4, 4, 4),
};
cb.Items.Add(item);
if (session.Id == (Props.ChannelId ?? ""))
selectedItem = item;
if (groups.Length > 1)
{
cb.Items.Add(new ComboBoxItem
{
Content = group.AgentLabel,
IsEnabled = false,
FontWeight = Microsoft.UI.Text.FontWeights.SemiBold,
FontSize = 10,
Padding = new Thickness(4, 2, 4, 2),
IsHitTestVisible = false,
});
}
foreach (var session in group.Sessions)
{
cb.Items.Add(new ComboBoxItem
{
Content = session.Title,
Tag = session.Id,
Padding = groups.Length > 1
? new Thickness(16, 4, 4, 4)
: new Thickness(8, 4, 4, 4),
});
}
}
channelGroupsRef.Current = SessionPickerSnapshot.Capture(groups);
}
}

if (selectedItem != null)
cb.SelectedItem = selectedItem;

var onChanged = Props.OnChannelChanged;
cb.SelectionChanged += (_, _) =>
var selectedId = Props.ChannelId ?? "";
var selectedItem = cb.Items
.OfType<ComboBoxItem>()
.FirstOrDefault(item => item.Tag is string id && id == selectedId);
if (!ReferenceEquals(cb.SelectedItem, selectedItem))
cb.SelectedItem = selectedItem;
}
finally
{
if (cb.SelectedItem is ComboBoxItem { Tag: string id })
onChanged(id);
};

border.Child = cb;
channelComboUpdatingRef.Current = false;
}
});

// ── Model picker (provider-rich) ─────────────────────────────────
Expand Down
37 changes: 37 additions & 0 deletions src/OpenClaw.Tray.WinUI/Chat/SessionPickerSnapshot.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
namespace OpenClawTray.Chat;

internal sealed class SessionPickerSnapshot
{
private readonly ChannelGroup[] _groups;

private SessionPickerSnapshot(ChannelGroup[] groups)
{
_groups = groups;
}

public static SessionPickerSnapshot Capture(ChannelGroup[] groups) =>
new(groups.Select(group =>
new ChannelGroup(group.AgentLabel, group.Sessions.ToArray())).ToArray());

public bool Matches(ChannelGroup[] groups)
{
if (_groups.Length != groups.Length)
return false;

for (var groupIndex = 0; groupIndex < groups.Length; groupIndex++)
{
var previous = _groups[groupIndex];
var current = groups[groupIndex];
if (previous.AgentLabel != current.AgentLabel || previous.Sessions.Length != current.Sessions.Length)
return false;

for (var sessionIndex = 0; sessionIndex < current.Sessions.Length; sessionIndex++)
{
if (previous.Sessions[sessionIndex] != current.Sessions[sessionIndex])
return false;
}
}

return true;
}
}
Loading