Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
37 changes: 37 additions & 0 deletions apps/desktop/src/ipc/methods/wsl.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,43 @@ describe("WSL IPC", () => {
),
);

it.effect("does not enumerate distros until the WSL backend is enabled", () => {
const distros = [
{ name: "Ubuntu", isDefault: true, version: 2 as const },
{ name: "Debian", isDefault: false, version: 2 as const },
];
const layer = Layer.mergeAll(
DesktopAppSettings.layerTest({
...DesktopAppSettings.DEFAULT_DESKTOP_SETTINGS,
wslDistro: "Debian",
}),
DesktopWslEnvironment.layerTest({ isAvailable: true, distros }),
layerWslBackend(),
layerLifecycle([]),
layerUnusedLifecycleRuntime,
);

return Effect.gen(function* () {
const wsl = yield* DesktopWslEnvironment.DesktopWslEnvironment;
const state = yield* getWslState.handler(undefined).pipe(
Effect.provideService(DesktopWslEnvironment.DesktopWslEnvironment, {
...wsl,
listDistros: Effect.die("must not enumerate distros"),
}),
Effect.flatMap(decodeWslState),
);
assert.equal(state.enabled, false);
assert.equal(state.available, true);
assert.equal(state.distro, "Debian");
assert.deepEqual(state.distros, []);

const enabledState = yield* invokeSetWslBackendEnabled(true);
assert.equal(enabledState.enabled, true);
assert.equal(enabledState.distro, "Debian");
assert.deepEqual(enabledState.distros, distros);
}).pipe(Effect.provide(layer));
});

it.effect("stages dual-backend preferences before enabling without relaunching", () => {
const relaunchReasons: Array<string> = [];
const layer = Layer.mergeAll(
Expand Down
6 changes: 3 additions & 3 deletions apps/desktop/src/ipc/methods/wsl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ const readWslState: Effect.Effect<
const wslBackend = yield* DesktopWslBackend.DesktopWslBackend;
const settings = yield* appSettings.get;
const available = settings.localEnvironmentEnabled && (yield* wslEnvironment.isAvailable);
// Only enumerate distros when WSL is actually available — listDistros on a
// non-WSL host would spawn wsl.exe and hit the timeout for nothing.
const distros = available ? yield* wslEnvironment.listDistros : [];
// Windows ships a wsl.exe stub that can prompt to install WSL when invoked.
// Keep disabled state reads from launching it to enumerate distros.
const distros = available && settings.wslBackendEnabled ? yield* wslEnvironment.listDistros : [];
const preflightError = yield* wslBackend.lastPreflightError;
return {
enabled: settings.wslBackendEnabled,
Expand Down
13 changes: 10 additions & 3 deletions apps/web/src/components/settings/ConnectionsSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3307,9 +3307,16 @@ export function ConnectionsSettings() {
Off
</SelectItem>
{desktopWslState.distros.length === 0 ? (
<SelectItem hideIndicator value={BACKEND_VALUE_DEFAULT_WSL}>
Default distro
</SelectItem>
<>
<SelectItem hideIndicator value={BACKEND_VALUE_DEFAULT_WSL}>
Default distro
</SelectItem>
{desktopWslState.distro !== null ? (
<SelectItem hideIndicator value={desktopWslState.distro}>
{desktopWslState.distro}
</SelectItem>
) : null}
</>
) : (
desktopWslState.distros.map((distro) => (
<SelectItem hideIndicator key={distro.name} value={distro.name}>
Expand Down
Loading