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
39 changes: 38 additions & 1 deletion apps/desktop/src/ipc/methods/wsl.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import * as DesktopClientSettings from "../../settings/DesktopClientSettings.ts"
import * as DesktopWindow from "../../window/DesktopWindow.ts";
import * as DesktopWslBackend from "../../wsl/DesktopWslBackend.ts";
import * as DesktopWslEnvironment from "../../wsl/DesktopWslEnvironment.ts";
import { setWslBackendEnabled, setWslDistro, setWslOnly } from "./wsl.ts";
import { getWslState, setWslBackendEnabled, setWslDistro, setWslOnly } from "./wsl.ts";

const decodeWslState = Schema.decodeUnknownEffect(DesktopWslStateSchema);

Expand Down Expand Up @@ -84,6 +84,43 @@ const layerUnusedLifecycleRuntime = Layer.mergeAll(
);

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 WSL-only preferences and relaunches only after enabling", () => {
const relaunchReasons: Array<string> = [];
const layer = Layer.mergeAll(
Expand Down
4 changes: 2 additions & 2 deletions apps/desktop/src/ipc/methods/wsl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ const readWslState: Effect.Effect<
const wslBackend = yield* DesktopWslBackend.DesktopWslBackend;
const settings = yield* appSettings.get;
const available = settings.localEnvironmentEnabled && (yield* wslEnvironment.isAvailable);
// Listing distros on non-WSL hosts spawns wsl.exe only to time out.
const distros = available ? yield* wslEnvironment.listDistros : [];
// Windows ships a wsl.exe stub that can prompt to install WSL when invoked.
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 @@ -869,9 +869,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