Skip to content

Commit ab2aa39

Browse files
ranjeshjCopilot
andcommitted
Hide reconfigure for setup-managed WSL gateways
Co-authored-by: Copilot <[email protected]>
1 parent e0ce52d commit ab2aa39

7 files changed

Lines changed: 168 additions & 18 deletions

File tree

‎docs/ONBOARDING_WIZARD.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ The onboarding wizard is now the V2 setup flow for installing a new app-owned lo
44

55
## Overview
66

7-
On first launch, the wizard appears only when there is no usable saved gateway connection. Users with any existing local or external gateway manage connections from the tray app's Connections tab and can start setup intentionally with **Install new WSL Gateway**.
7+
On first launch, the wizard appears only when there is no usable saved gateway connection. Users with existing gateways manage connections from the tray app's Connections tab. The local WSL setup affordance in Connections is shown only when setup has not already created an app-owned WSL gateway on this device.
88

99
The V2 setup flow walks users through:
1010

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1190,6 +1190,7 @@ private TrayMenuSnapshot CaptureTrayMenuSnapshot()
11901190
// Show "Reconfigure" if there's an existing setup, "Setup Guide" if fresh
11911191
var hasExistingConfig = _settings != null
11921192
&& !StartupSetupState.RequiresSetup(_settings, IdentityDataPath, _gatewayRegistry);
1193+
var hasSetupManagedLocalWslGateway = WslKeepAlivePolicy.HasSetupManagedLocalGateway(_gatewayRegistry?.GetAll());
11931194
var setupMenuLabel = hasExistingConfig
11941195
? LocalizationHelper.GetString("Menu_Reconfigure")
11951196
: LocalizationHelper.GetString("Menu_SetupGuide");
@@ -1214,6 +1215,7 @@ private TrayMenuSnapshot CaptureTrayMenuSnapshot()
12141215
UsageCost = _appState?.UsageCost,
12151216
Settings = _settings,
12161217
SetupMenuLabel = setupMenuLabel,
1218+
ShowSetupMenuEntry = !hasSetupManagedLocalWslGateway,
12171219
};
12181220
}
12191221

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

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -109,20 +109,13 @@ public void Initialize()
109109
var settings = CurrentApp.Settings;
110110
if (settings == null) return;
111111

112-
// Local-WSL install entry points. The hub only exposes
113-
// OpenSetupAction on platforms where WSL tooling is wired up; if
114-
// it's null we hide the entry points so the user isn't offered a
115-
// button that does nothing.
112+
// Local-WSL install entry points are only useful until setup has
113+
// created its managed local WSL gateway record.
116114
// • WelcomeLocalWslSetupCard — get-started CTA on the empty-state
117115
// Welcome screen for first-run users.
118116
// • AddLocalWslItem — third method tab inside the Add Gateway
119117
// form, alongside Direct and Setup code.
120-
var localSetupAvailable = true;
121-
var localSetupVisibility = localSetupAvailable
122-
? Visibility.Visible
123-
: Visibility.Collapsed;
124-
WelcomeLocalWslSetupCard.Visibility = localSetupVisibility;
125-
AddLocalWslItem.Visibility = localSetupVisibility;
118+
UpdateLocalWslSetupVisibility();
126119

127120
if (_connectionManager != null)
128121
_connectionManager.StateChanged += OnManagerStateChanged;
@@ -203,11 +196,29 @@ private void OnRegistryChanged(object? sender, GatewayRegistryChangedEventArgs e
203196
{
204197
DispatcherQueue?.TryEnqueue(() =>
205198
{
199+
UpdateLocalWslSetupVisibility();
206200
LoadSavedGateways();
207201
RefreshFromSnapshot(_lastSnapshot);
208202
});
209203
}
210204

205+
private void UpdateLocalWslSetupVisibility()
206+
{
207+
var localSetupAvailable = !WslKeepAlivePolicy.HasSetupManagedLocalGateway(_gatewayRegistry?.GetAll());
208+
var localSetupVisibility = localSetupAvailable
209+
? Visibility.Visible
210+
: Visibility.Collapsed;
211+
212+
WelcomeLocalWslSetupCard.Visibility = localSetupVisibility;
213+
AddLocalWslItem.Visibility = localSetupVisibility;
214+
215+
if (!localSetupAvailable && AddLocalWslItem.IsSelected)
216+
{
217+
AddDirectItem.IsSelected = true;
218+
ShowAddPane("direct");
219+
}
220+
}
221+
211222
// ─── Plan apply ───────────────────────────────────────────────────
212223

213224
private void RefreshFromSnapshot(GatewayConnectionSnapshot snapshot)

‎src/OpenClaw.Tray.WinUI/Services/TrayMenuSnapshot.cs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,5 @@ internal sealed record TrayMenuSnapshot
3232
// ── Permisos y setup ──
3333
internal required SettingsManager? Settings { get; init; }
3434
internal required string SetupMenuLabel { get; init; }
35+
internal required bool ShowSetupMenuEntry { get; init; }
3536
}

‎src/OpenClaw.Tray.WinUI/Services/TrayMenuStateBuilder.cs‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,10 @@ internal void Build(TrayMenuWindow menu)
304304

305305
// Setup Guide / Reconfigure entry — label flips based on whether prior
306306
// configuration exists; routes to the existing "setup" action handler.
307-
menu.AddMenuItem(_snapshot.SetupMenuLabel, FluentIconCatalog.Build(FluentIconCatalog.Setup), "setup");
307+
if (_snapshot.ShowSetupMenuEntry)
308+
{
309+
menu.AddMenuItem(_snapshot.SetupMenuLabel, FluentIconCatalog.Build(FluentIconCatalog.Setup), "setup");
310+
}
308311

309312
// ── Footer ──
310313
menu.AddSeparator();

‎src/OpenClaw.Tray.WinUI/Services/WslKeepAlivePolicy.cs‎

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ namespace OpenClawTray.Services;
55

66
internal static class WslKeepAlivePolicy
77
{
8+
private const string DefaultSetupManagedDistroName = "OpenClawGateway";
9+
private const string DefaultSetupManagedFriendlyName = "Local (OpenClawGateway)";
10+
811
public static bool ShouldStart(GatewayRecord? activeRecord, string? legacyGatewayUrl)
912
{
1013
if (activeRecord is not null)
@@ -36,7 +39,7 @@ public static bool ShouldStart(GatewayRecord? activeRecord, string? legacyGatewa
3639
return environmentOverride;
3740
#endif
3841

39-
return "OpenClawGateway";
42+
return DefaultSetupManagedDistroName;
4043
}
4144

4245
public static IReadOnlyList<string> FindStaleSetupManagedDistroNames(
@@ -46,7 +49,7 @@ public static IReadOnlyList<string> FindStaleSetupManagedDistroNames(
4649
{
4750
var managedLocalDistros = records
4851
.Where(IsSetupManagedLocalRecord)
49-
.Select(r => r.SetupManagedDistroName)
52+
.Select(GetSetupManagedDistroName)
5053
.Where(name => !string.IsNullOrWhiteSpace(name))
5154
.ToHashSet(StringComparer.OrdinalIgnoreCase);
5255

@@ -61,6 +64,9 @@ public static IReadOnlyList<string> FindStaleSetupManagedDistroNames(
6164
.ToArray();
6265
}
6366

67+
public static bool HasSetupManagedLocalGateway(IEnumerable<GatewayRecord>? records) =>
68+
records?.Any(IsSetupManagedLocalRecord) == true;
69+
6470
public static bool IsKeepaliveCommandLine(string? commandLine, string distroName)
6571
{
6672
if (string.IsNullOrWhiteSpace(commandLine) || string.IsNullOrWhiteSpace(distroName))
@@ -90,14 +96,29 @@ public static bool TryGetMarkerDistroName(string markerJson, out string distroNa
9096
}
9197
}
9298

93-
private static bool IsSetupManagedLocalRecord(GatewayRecord record)
99+
public static bool IsSetupManagedLocalRecord(GatewayRecord record)
94100
{
95101
if (record.SshTunnel is not null)
96102
return false;
97103

98-
if (string.IsNullOrWhiteSpace(record.SetupManagedDistroName))
99-
return false;
104+
if (!string.IsNullOrWhiteSpace(record.SetupManagedDistroName))
105+
return record.IsLocal || LocalGatewayUrlClassifier.IsLocalGatewayUrl(record.Url);
106+
107+
return IsLegacyDefaultSetupManagedLocalRecord(record);
108+
}
109+
110+
private static string? GetSetupManagedDistroName(GatewayRecord record)
111+
{
112+
if (!string.IsNullOrWhiteSpace(record.SetupManagedDistroName))
113+
return record.SetupManagedDistroName;
100114

101-
return record.IsLocal || LocalGatewayUrlClassifier.IsLocalGatewayUrl(record.Url);
115+
return IsLegacyDefaultSetupManagedLocalRecord(record)
116+
? DefaultSetupManagedDistroName
117+
: null;
102118
}
119+
120+
private static bool IsLegacyDefaultSetupManagedLocalRecord(GatewayRecord record) =>
121+
record.IsLocal
122+
&& LocalGatewayUrlClassifier.IsLocalGatewayUrl(record.Url)
123+
&& string.Equals(record.FriendlyName, DefaultSetupManagedFriendlyName, StringComparison.Ordinal);
103124
}

‎tests/OpenClaw.Tray.Tests/WslKeepAlivePolicyTests.cs‎

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,118 @@ public void ResolveDistroName_PrefersRegistryManagedDistro()
7171
Assert.Equal("RegistryGateway", distroName);
7272
}
7373

74+
[Fact]
75+
public void HasSetupManagedLocalGateway_ReturnsTrueForSetupManagedLocalRecord()
76+
{
77+
var records = new[]
78+
{
79+
new GatewayRecord
80+
{
81+
Id = "local",
82+
Url = "ws://localhost:18789",
83+
IsLocal = true,
84+
SetupManagedDistroName = "OpenClawGateway",
85+
},
86+
};
87+
88+
Assert.True(WslKeepAlivePolicy.HasSetupManagedLocalGateway(records));
89+
}
90+
91+
[Fact]
92+
public void HasSetupManagedLocalGateway_ReturnsTrueForLegacyDefaultSetupManagedLocalRecord()
93+
{
94+
var records = new[]
95+
{
96+
new GatewayRecord
97+
{
98+
Id = "legacy-local",
99+
Url = "ws://localhost:18789",
100+
FriendlyName = "Local (OpenClawGateway)",
101+
IsLocal = true,
102+
},
103+
};
104+
105+
Assert.True(WslKeepAlivePolicy.HasSetupManagedLocalGateway(records));
106+
}
107+
108+
[Fact]
109+
public void HasSetupManagedLocalGateway_ReturnsFalseForManualLocalRecord()
110+
{
111+
var records = new[]
112+
{
113+
new GatewayRecord
114+
{
115+
Id = "manual-local",
116+
Url = "ws://localhost:18789",
117+
IsLocal = true,
118+
},
119+
};
120+
121+
Assert.False(WslKeepAlivePolicy.HasSetupManagedLocalGateway(records));
122+
}
123+
124+
[Fact]
125+
public void HasSetupManagedLocalGateway_ReturnsFalseForSshTunnelRecord()
126+
{
127+
var records = new[]
128+
{
129+
new GatewayRecord
130+
{
131+
Id = "ssh",
132+
Url = "ws://127.0.0.1:18789",
133+
IsLocal = true,
134+
SetupManagedDistroName = "OpenClawGateway",
135+
SshTunnel = new SshTunnelConfig("user", "example.test", 18789, 18789),
136+
},
137+
};
138+
139+
Assert.False(WslKeepAlivePolicy.HasSetupManagedLocalGateway(records));
140+
}
141+
142+
[Fact]
143+
public void HasSetupManagedLocalGateway_ReturnsFalseForRemoteRecord()
144+
{
145+
var records = new[]
146+
{
147+
new GatewayRecord
148+
{
149+
Id = "remote",
150+
Url = "wss://gateway.example.test",
151+
SetupManagedDistroName = "OpenClawGateway",
152+
},
153+
};
154+
155+
Assert.False(WslKeepAlivePolicy.HasSetupManagedLocalGateway(records));
156+
}
157+
158+
[Fact]
159+
public void HasSetupManagedLocalGateway_ReturnsFalseForNullRecords()
160+
{
161+
Assert.False(WslKeepAlivePolicy.HasSetupManagedLocalGateway(null));
162+
}
163+
164+
[Fact]
165+
public void FindStaleSetupManagedDistroNames_PreservesLegacyDefaultLocalDistro()
166+
{
167+
var records = new[]
168+
{
169+
new GatewayRecord
170+
{
171+
Id = "legacy-local",
172+
Url = "ws://localhost:18789",
173+
FriendlyName = "Local (OpenClawGateway)",
174+
IsLocal = true,
175+
},
176+
};
177+
178+
var stale = WslKeepAlivePolicy.FindStaleSetupManagedDistroNames(
179+
records,
180+
["OpenClawGateway"],
181+
setupStateDistroName: null);
182+
183+
Assert.Empty(stale);
184+
}
185+
74186
[Fact]
75187
public void FindStaleSetupManagedDistroNames_PreservesRegisteredLocalDistro_WhenRemoteIsActive()
76188
{

0 commit comments

Comments
 (0)