Skip to content

Commit 7719743

Browse files
authored
Merge 5aa6847 into 71d2497
2 parents 71d2497 + 5aa6847 commit 7719743

25 files changed

Lines changed: 280 additions & 20 deletions

src/OpenClaw.Tray.WinUI/Helpers/LocalizationHelper.cs

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,16 +38,40 @@ public static string GetString(string resourceKey)
3838
{
3939
try
4040
{
41-
var candidate = Manager.MainResourceMap.GetValue($"Resources/{resourceKey}", GetContext());
42-
var value = candidate?.ValueAsString;
43-
return string.IsNullOrEmpty(value) ? resourceKey : value;
41+
var value = GetResourceValue(resourceKey);
42+
if (!string.IsNullOrEmpty(value))
43+
return value;
44+
45+
var propertySeparatorIndex = resourceKey.LastIndexOf('.');
46+
if (propertySeparatorIndex > 0 && propertySeparatorIndex < resourceKey.Length - 1)
47+
{
48+
var propertyResourceKey = resourceKey[..propertySeparatorIndex] + "/" + resourceKey[(propertySeparatorIndex + 1)..];
49+
value = GetResourceValue(propertyResourceKey);
50+
if (!string.IsNullOrEmpty(value))
51+
return value;
52+
}
53+
54+
return resourceKey;
4455
}
4556
catch
4657
{
4758
return resourceKey;
4859
}
4960
}
5061

62+
private static string? GetResourceValue(string resourceKey)
63+
{
64+
try
65+
{
66+
var candidate = Manager.MainResourceMap.GetValue($"Resources/{resourceKey}", GetContext());
67+
return candidate?.ValueAsString;
68+
}
69+
catch
70+
{
71+
return null;
72+
}
73+
}
74+
5175
/// <summary>
5276
/// Localized <see cref="string.Format(string, object[])"/>. Use for resw values that
5377
/// contain placeholders like "{0}". Catches <see cref="FormatException"/> caused by
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
namespace OpenClawTray.Helpers;
2+
3+
/// <summary>
4+
/// Maps HubWindow nav tags to localised page labels for cross-page
5+
/// "Back to {origin}" affordances. Reuses the sidebar
6+
/// <c>HubWindow_NavigationViewItem_*.Content</c> resw entries so page names
7+
/// are translated once and stay in sync with the sidebar.
8+
/// </summary>
9+
internal static class NavOriginLabels
10+
{
11+
public static string DisplayLabel(string? tag)
12+
{
13+
if (string.IsNullOrWhiteSpace(tag)) return string.Empty;
14+
var resourceKey = tag switch
15+
{
16+
"chat" => "HubWindow_NavigationViewItem_82.Content",
17+
"connection" => "HubWindow_NavigationViewItem_88.Content",
18+
"sessions" => "HubWindow_NavigationViewItem_91.Content",
19+
"skills" => "HubWindow_NavigationViewItem_97.Content",
20+
"channels" => "HubWindow_NavigationViewItem_109.Content",
21+
"instances" or "nodes" => "HubWindow_NavigationViewItem_112.Content",
22+
"agentevents" => "HubWindow_NavigationViewItem_94.Content",
23+
"bindings" => "HubWindow_NavigationViewItem_115.Content",
24+
"config" => "HubWindow_NavigationViewItem_118.Content",
25+
"usage" => "HubWindow_NavigationViewItem_121.Content",
26+
"cron" => "HubWindow_NavigationViewItem_124.Content",
27+
"voice" => "HubWindow_NavigationViewItem_Voice.Content",
28+
"settings" => "HubWindow_NavigationViewItem_133.Content",
29+
"permissions" => "HubWindow_NavigationViewItem_136.Content",
30+
"sandbox" => "HubWindow_NavigationViewItem_Sandbox.Content",
31+
"debug" => "HubWindow_NavigationViewItem_145.Content",
32+
"info" or "about" => "HubWindow_NavigationViewItem_148.Content",
33+
_ => null,
34+
};
35+
return resourceKey == null
36+
? char.ToUpperInvariant(tag![0]) + tag.Substring(1)
37+
: LocalizationHelper.GetString(resourceKey);
38+
}
39+
40+
public static string BackToLabel(string? tag) =>
41+
LocalizationHelper.Format("BackToOriginFormat", DisplayLabel(tag));
42+
}
43+
44+
45+

src/OpenClaw.Tray.WinUI/Pages/AboutPage.xaml.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ private void OnCheckUpdatesClick(object sender, RoutedEventArgs e)
138138

139139
private void OnMoreDiagnosticsClick(object sender, RoutedEventArgs e)
140140
{
141-
((IAppCommands)CurrentApp).Navigate("debug");
141+
((IAppCommands)CurrentApp).Navigate("debug", "info");
142142
}
143143

144144
private void OnDocumentationClick(object sender, RoutedEventArgs e)

src/OpenClaw.Tray.WinUI/Pages/BindingsPage.xaml.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public void Initialize()
5757
}
5858

5959
private void OnOpenConnectionClick(object sender, RoutedEventArgs e)
60-
=> ((IAppCommands)CurrentApp).Navigate("connection");
60+
=> ((IAppCommands)CurrentApp).Navigate("connection", "bindings");
6161

6262
private void OnAppStateChanged(object? sender, PropertyChangedEventArgs e)
6363
{

src/OpenClaw.Tray.WinUI/Pages/ChannelsPage.xaml.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1346,7 +1346,7 @@ private FrameworkElement BuildInlineConfigForm(ChannelRecord record)
13461346
{
13471347
Content = LocalizationHelper.GetString("ChannelsPage_OpenConfigPage"),
13481348
};
1349-
openConfigBtn.Click += (_, _) => ((IAppCommands)CurrentApp).Navigate("config");
1349+
openConfigBtn.Click += (_, _) => ((IAppCommands)CurrentApp).Navigate("config", "channels");
13501350
actionRow.Children.Add(saveBtn);
13511351
actionRow.Children.Add(openConfigBtn);
13521352
stack.Children.Add(actionRow);
@@ -1946,7 +1946,7 @@ private FrameworkElement BuildConfigPlaceholder(ChannelRecord record)
19461946
};
19471947
btn.Click += (_, _) =>
19481948
{
1949-
((IAppCommands)CurrentApp).Navigate("config");
1949+
((IAppCommands)CurrentApp).Navigate("config", "channels");
19501950
};
19511951
stack.Children.Add(btn);
19521952
return stack;

src/OpenClaw.Tray.WinUI/Pages/ChatPage.xaml.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ private void ShowFunctionalSurface()
266266
onStopSpeaking: () => app?.StopChatSpeaking(),
267267
onVoiceRequest: VoiceTranscribeAsync,
268268
onAttachClick: OnAttachClicked,
269-
onSettingsClick: () => _hub?.NavigateTo("voice"),
269+
onSettingsClick: () => _hub?.NavigateTo("voice", "chat"),
270270
onSpeakerMuteChanged: muted => (App.Current as App)?.SetChatSpeakerMuted(muted),
271271
initialMuted: CurrentApp.Settings?.VoiceTtsEnabled == false,
272272
suppressAutoDispose: true);
@@ -774,7 +774,7 @@ private async Task ShowVoiceSettingsDialogAsync(string title, string message, Ac
774774
private void NavigateToVoiceSettings()
775775
{
776776
if (_hub is not null)
777-
_hub.NavigateTo("voice");
777+
_hub.NavigateTo("voice", "chat");
778778
else
779779
(App.Current as App)?.ShowHub("voice");
780780
}

src/OpenClaw.Tray.WinUI/Pages/ConfigPage.xaml

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
66
xmlns:controls="using:Microsoft.UI.Xaml.Controls"
77
xmlns:toolkit="using:CommunityToolkit.WinUI.Controls"
8+
xmlns:helpers="using:OpenClawTray.Helpers"
89
xmlns:local="using:OpenClawTray.Controls">
910

1011
<Grid Padding="24,20,24,16">
@@ -17,8 +18,19 @@
1718
<RowDefinition Height="Auto"/>
1819
</Grid.RowDefinitions>
1920

20-
<!-- Page header -->
21-
<Grid Grid.Row="0" ColumnSpacing="16">
21+
<!-- Page header (with optional back-link when arriving via cross-page nav) -->
22+
<StackPanel Grid.Row="0" Spacing="4">
23+
<HyperlinkButton x:Name="BackOriginLink"
24+
Click="OnBackOriginClicked"
25+
Padding="0" Margin="0"
26+
Visibility="Collapsed"
27+
AutomationProperties.AutomationId="BackOriginLink">
28+
<StackPanel Orientation="Horizontal" Spacing="6">
29+
<FontIcon Glyph="{x:Bind helpers:FluentIconCatalog.Back, Mode=OneTime}" FontSize="12"/>
30+
<TextBlock x:Uid="BackToOriginGeneric" x:Name="BackOriginText" Text="Back"/>
31+
</StackPanel>
32+
</HyperlinkButton>
33+
<Grid ColumnSpacing="16">
2234
<Grid.ColumnDefinitions>
2335
<ColumnDefinition Width="*"/>
2436
<ColumnDefinition Width="Auto"/>
@@ -45,6 +57,7 @@
4557
</StackPanel>
4658
</Button>
4759
</Grid>
60+
</StackPanel>
4861

4962
<StackPanel Grid.Row="1" Spacing="8">
5063
<InfoBar x:Name="ConnectionInfoBar"

src/OpenClaw.Tray.WinUI/Pages/ConfigPage.xaml.cs

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using OpenClawTray.Controls;
99
using OpenClawTray.Helpers;
1010
using OpenClawTray.Services;
11+
using OpenClawTray.Windows;
1112
using System;
1213
using System.Collections.Generic;
1314
using System.ComponentModel;
@@ -34,6 +35,8 @@ public sealed partial class ConfigPage : Page
3435
private ConfigEditorSnapshot _editSnapshot = ConfigEditorSnapshot.Empty;
3536
private IOperatorGatewayClient? _permissionClient;
3637

38+
private string? _backOriginTag;
39+
3740
private string _selectedPath = "";
3841
private string _searchText = "";
3942
private bool _showSchemaFallback;
@@ -106,6 +109,7 @@ public void Initialize()
106109

107110
_appState = CurrentApp.AppState!;
108111
_appState.PropertyChanged += OnAppStateChanged;
112+
RefreshBackOriginLink();
109113
SubscribePermissionClient(CurrentApp.GatewayClient);
110114
Logger.Info("[ConfigPage] Initialize");
111115
if (CompleteReconnectIfReady())
@@ -124,6 +128,27 @@ public void Initialize()
124128
}
125129
}
126130

131+
private void RefreshBackOriginLink()
132+
{
133+
var hub = CurrentApp.ActiveHubWindow as HubWindow;
134+
var origin = hub?.LastNavigationOrigin;
135+
if (string.IsNullOrEmpty(origin))
136+
{
137+
_backOriginTag = null;
138+
BackOriginLink.Visibility = Visibility.Collapsed;
139+
return;
140+
}
141+
_backOriginTag = origin;
142+
BackOriginText.Text = NavOriginLabels.BackToLabel(origin);
143+
BackOriginLink.Visibility = Visibility.Visible;
144+
}
145+
146+
private void OnBackOriginClicked(object sender, RoutedEventArgs e)
147+
{
148+
if (!string.IsNullOrEmpty(_backOriginTag))
149+
((IAppCommands)CurrentApp).Navigate(_backOriginTag);
150+
}
151+
127152
public void UpdateConfig(JsonElement config)
128153
{
129154
var configSnapshot = config.Clone();
@@ -650,7 +675,7 @@ private void OnResetSection(object sender, RoutedEventArgs e)
650675

651676
private void OnOpenConnection(object sender, RoutedEventArgs e)
652677
{
653-
((IAppCommands)CurrentApp).Navigate("connection");
678+
((IAppCommands)CurrentApp).Navigate("connection", "config");
654679
}
655680

656681
private void OnOpenDashboard(object sender, RoutedEventArgs e)

src/OpenClaw.Tray.WinUI/Pages/ConnectionPage.xaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,18 @@
5555
<StackPanel Padding="24" Spacing="8"
5656
HorizontalAlignment="Stretch" MaxWidth="900">
5757

58+
<!-- Inline "Back to {origin}" link; visible only when arriving via a cross-page link. -->
59+
<HyperlinkButton x:Name="BackOriginLink"
60+
Click="OnBackOriginClicked"
61+
Padding="0" Margin="0,0,0,0"
62+
Visibility="Collapsed"
63+
AutomationProperties.AutomationId="BackOriginLink">
64+
<StackPanel Orientation="Horizontal" Spacing="6">
65+
<FontIcon Glyph="{x:Bind helpers:FluentIconCatalog.Back, Mode=OneTime}" FontSize="12"/>
66+
<TextBlock x:Uid="BackToOriginGeneric" x:Name="BackOriginText" Text="Back"/>
67+
</StackPanel>
68+
</HyperlinkButton>
69+
5870
<!-- ═════════════════════════════════════════════════════════
5971
PINNED MODIFIERS — render across every mode
6072
═════════════════════════════════════════════════════════ -->

src/OpenClaw.Tray.WinUI/Pages/ConnectionPage.xaml.cs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,31 @@ public void Initialize()
157157
UpdatePairingRequests(existingNode);
158158
if (_appState?.DevicePairList is { } existingDevice)
159159
UpdateDevicePairingRequests(existingDevice);
160+
161+
RefreshBackOriginLink();
162+
}
163+
164+
private string? _backOriginTag;
165+
166+
private void RefreshBackOriginLink()
167+
{
168+
var hub = CurrentApp.ActiveHubWindow as OpenClawTray.Windows.HubWindow;
169+
var origin = hub?.LastNavigationOrigin;
170+
if (string.IsNullOrEmpty(origin))
171+
{
172+
_backOriginTag = null;
173+
BackOriginLink.Visibility = Visibility.Collapsed;
174+
return;
175+
}
176+
_backOriginTag = origin;
177+
BackOriginText.Text = Helpers.NavOriginLabels.BackToLabel(origin);
178+
BackOriginLink.Visibility = Visibility.Visible;
179+
}
180+
181+
private void OnBackOriginClicked(object sender, RoutedEventArgs e)
182+
{
183+
if (!string.IsNullOrEmpty(_backOriginTag))
184+
((IAppCommands)CurrentApp).Navigate(_backOriginTag);
160185
}
161186

162187
private void OnPageUnloaded(object sender, RoutedEventArgs e)

0 commit comments

Comments
 (0)