From 2afae370fc55a777c68218b0b1e5eacceaa706c0 Mon Sep 17 00:00:00 2001 From: Josh Gratton Date: Tue, 2 Jun 2026 20:15:10 -0400 Subject: [PATCH] fix(desktop): apply WSL distro changes in wsl-only mode + unblock recovery button MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Two WSL-mode edge cases from review: Medium (cursor) — WSL-only distro change ignored: in wsl-only mode the pool's primary IS the WSL backend and its distro is captured when that backend starts. setWslDistro only persisted + reconciled, but reconcile deliberately skips the secondary in wsl-only mode, so nothing restarted the primary — the old distro kept serving while labels/IPC showed the new one. setWslDistro now relaunches (like the wsl-only toggle) when wslOnly && the distro actually changed; dual-backend mode still swaps the secondary via reconcile. The renderer routes wsl-only distro changes through the existing "Switch WSL distro?" confirm so the relaunch isn't a surprise. High (macroscope) — recovery button non-functional: the "Switch to Windows" recovery row in renderWslRow is shown when `enabled || wslOnly`, but handleSelectWslMode's WSL-off path returned early on `!enabled` alone, so when WSL went unavailable with wsl-only persisted (enabled false, wslOnly true) the button did nothing. The guard is now `!enabled && !wslOnly`, matching the row's visibility; the disable flow then clears wslOnly and relaunches onto Windows. --- apps/desktop/src/ipc/methods/wsl.ts | 15 ++++++++++++++- .../components/settings/ConnectionsSettings.tsx | 12 ++++++++++-- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/apps/desktop/src/ipc/methods/wsl.ts b/apps/desktop/src/ipc/methods/wsl.ts index 75a103d0ef..93c3434650 100644 --- a/apps/desktop/src/ipc/methods/wsl.ts +++ b/apps/desktop/src/ipc/methods/wsl.ts @@ -63,7 +63,20 @@ export const setWslDistro = makeIpcMethod({ handler: Effect.fn("desktop.ipc.wsl.setDistro")(function* (distro) { const appSettings = yield* DesktopAppSettings.DesktopAppSettings; const wslBackend = yield* DesktopWslBackend.DesktopWslBackend; - yield* appSettings.setWslDistro(distro); + const lifecycle = yield* DesktopLifecycle.DesktopLifecycle; + const change = yield* appSettings.setWslDistro(distro); + const settings = yield* appSettings.get; + // In wsl-only mode the pool's primary IS the WSL backend, and its distro + // is captured when that backend starts. reconcile only manages the + // dual-mode secondary (it skips registering one when wslOnly), so it can't + // swap the primary's distro — relaunch so the primary comes back up on the + // newly selected distro, same as the wsl-only toggle. In dual-backend mode + // the secondary wsl: instance is swapped by reconcile instead. + if (settings.wslOnly && change.changed) { + const state = yield* readWslState; + yield* lifecycle.relaunch(`wslDistro=${distro ?? "default"}`); + return state; + } yield* wslBackend.reconcile; return yield* readWslState; }), diff --git a/apps/web/src/components/settings/ConnectionsSettings.tsx b/apps/web/src/components/settings/ConnectionsSettings.tsx index f04025358d..636409d669 100644 --- a/apps/web/src/components/settings/ConnectionsSettings.tsx +++ b/apps/web/src/components/settings/ConnectionsSettings.tsx @@ -2617,7 +2617,11 @@ export function ConnectionsSettings() { const defaultDistroName = desktopWslState.distros.find((distro) => distro.isDefault)?.name ?? null; if (value === BACKEND_VALUE_WSL_OFF) { - if (!desktopWslState.enabled) return; + // Match the recovery row's visibility (`enabled || wslOnly`): when WSL + // went unavailable while wsl-only was persisted, `enabled` can be false + // while `wslOnly` is true, and the "Switch to Windows" button must + // still clear that state instead of silently no-op'ing. + if (!desktopWslState.enabled && !desktopWslState.wslOnly) return; const wasWslOnly = desktopWslState.wslOnly; // Confirm when there's WSL state to lose, OR when wsl-only is // on (turning the only running backend off needs to switch @@ -2643,7 +2647,11 @@ export function ConnectionsSettings() { // the user re-picked the row that's already selected. const resolvedCurrent = desktopWslState.distro ?? defaultDistroName; if (resolvedCurrent === resolvedNext) return; - if (hasWslRegistrationToLose) { + // Confirm when there's WSL registration to lose, OR in wsl-only mode: + // there the primary IS the WSL backend, so a distro change relaunches + // the app (the IPC handler does this) rather than swapping a secondary, + // and the user should see that coming. + if (hasWslRegistrationToLose || desktopWslState.wslOnly) { setPendingWslChange({ kind: "distro", nextDistro }); return; }