From d71f3b1dc5447b48dffd949b6278844d5caa1d5c Mon Sep 17 00:00:00 2001 From: Josh Gratton Date: Mon, 18 May 2026 11:08:43 -0400 Subject: [PATCH] feat(web): consolidate WSL backend toggle and distro picker into one Select Two separate controls for "is the WSL backend on?" and "which distro does it run on?" was confusing. They're the same decision. Merge them into a single dropdown: "Off" stops the backend, any distro entry starts it on that distro. The confirmation paths (disable, switch distro) keep their existing copy and gating against hasWslRegistrationToLose. --- .../settings/ConnectionsSettings.tsx | 160 +++++++++--------- 1 file changed, 81 insertions(+), 79 deletions(-) diff --git a/apps/web/src/components/settings/ConnectionsSettings.tsx b/apps/web/src/components/settings/ConnectionsSettings.tsx index bb07d42b3a..3e3c9d5539 100644 --- a/apps/web/src/components/settings/ConnectionsSettings.tsx +++ b/apps/web/src/components/settings/ConnectionsSettings.tsx @@ -104,11 +104,11 @@ import { useServerConfig } from "~/rpc/serverState"; const DEFAULT_TAILSCALE_SERVE_PORT = 443; -// Sentinel for the "track the WSL default distro" option in the -// distro picker. The colon is rejected by DISTRO_NAME_PATTERN -// (validated on the desktop side) so it can never collide with a -// real distro name. +// Sentinels for the consolidated WSL backend picker. The colon is +// rejected by DISTRO_NAME_PATTERN (validated on the desktop side) so +// neither can collide with a real distro name. const BACKEND_VALUE_DEFAULT_WSL = "backend:default-wsl"; +const BACKEND_VALUE_WSL_OFF = "backend:wsl-off"; const accessTimestampFormatter = new Intl.DateTimeFormat(undefined, { dateStyle: "medium", @@ -2421,37 +2421,47 @@ export function ConnectionsSettings() { return false; }, [savedEnvironmentsById]); - const handleToggleWslBackend = useCallback( - (enabled: boolean) => { - if (!desktopBridge || !desktopWslState || desktopWslState.enabled === enabled) return; - // Enabling is non-destructive: it just starts a new backend - // alongside the Windows one. Skip the dialog. Disabling only - // prompts when there's actual WSL state in the registry that the - // user might lose access to. - if (!enabled && hasWslRegistrationToLose) { - setPendingWslChange({ kind: "disable" }); - return; - } - void applyWslSettingChange(() => desktopBridge.setWslBackendEnabled(enabled)); - }, - [applyWslSettingChange, desktopBridge, desktopWslState, hasWslRegistrationToLose], - ); - - const handleSelectWslDistro = useCallback( + // Single picker for "WSL backend off" vs "running on distro X". The + // dropdown maps "Off" to disable and any distro entry to enable + + // run on that distro. Splitting these into a separate switch and + // dropdown was confusing — they're the same decision. + const handleSelectWslMode = useCallback( (value: string) => { if (!desktopBridge || !desktopWslState) return; - const nextDistro = value === BACKEND_VALUE_DEFAULT_WSL ? null : value; const defaultDistroName = desktopWslState.distros.find((distro) => distro.isDefault)?.name ?? null; - // Treat null and "the actual default distro" as the same selection - // so picking the highlighted row doesn't trigger a setting change. - const resolvedCurrent = desktopWslState.distro ?? defaultDistroName; + if (value === BACKEND_VALUE_WSL_OFF) { + if (!desktopWslState.enabled) return; + // Disabling only prompts when there's actual WSL state in the + // registry the user might lose access to. + if (hasWslRegistrationToLose) { + setPendingWslChange({ kind: "disable" }); + return; + } + void applyWslSettingChange(() => desktopBridge.setWslBackendEnabled(false)); + return; + } + const nextDistro = value === BACKEND_VALUE_DEFAULT_WSL ? null : value; const resolvedNext = nextDistro ?? defaultDistroName; + if (!desktopWslState.enabled) { + // Was off, user picked a distro: turn the backend on. No state + // to lose, no confirmation. Write the distro first if it + // differs from what's persisted so the backend comes up on the + // right one. + const persistedDistro = desktopWslState.distro; + const distroChanged = persistedDistro !== nextDistro; + void applyWslSettingChange(async () => { + if (distroChanged) { + await desktopBridge.setWslDistro(nextDistro); + } + return await desktopBridge.setWslBackendEnabled(true); + }); + return; + } + // Already enabled — treat as a distro switch. Skip the change if + // the user re-picked the row that's already selected. + const resolvedCurrent = desktopWslState.distro ?? defaultDistroName; if (resolvedCurrent === resolvedNext) return; - // Switching distros restarts the WSL backend on a different - // Linux home, which interrupts whatever's running on the current - // distro. Prompt before doing that, but only when there's - // already-registered WSL state worth warning about. if (hasWslRegistrationToLose) { setPendingWslChange({ kind: "distro", nextDistro }); return; @@ -2498,68 +2508,60 @@ export function ConnectionsSettings() { // dropdown then renders a single placeholder that matches). const defaultDistroName = desktopWslState.distros.find((distro) => distro.isDefault)?.name ?? null; - const distroSelectValue = - desktopWslState.distro ?? defaultDistroName ?? BACKEND_VALUE_DEFAULT_WSL; + const selectValue = !desktopWslState.enabled + ? BACKEND_VALUE_WSL_OFF + : (desktopWslState.distro ?? defaultDistroName ?? BACKEND_VALUE_DEFAULT_WSL); + const selectLabel = + selectValue === BACKEND_VALUE_WSL_OFF + ? "Off" + : selectValue === BACKEND_VALUE_DEFAULT_WSL + ? "Default distro" + : selectValue; return ( <> {desktopWslError} ) : null } control={ - handleToggleWslBackend(checked)} - aria-label="Enable WSL backend" - /> + } /> - {desktopWslState.enabled ? ( - { - if (typeof value !== "string") return; - handleSelectWslDistro(value); - }} - > - - - {distroSelectValue === BACKEND_VALUE_DEFAULT_WSL - ? "Default distro" - : distroSelectValue} - - - - {desktopWslState.distros.length === 0 ? ( - - Default distro - - ) : ( - desktopWslState.distros.map((distro) => ( - - {distro.name} - {distro.isDefault ? " (default)" : ""} - - )) - )} - - - } - /> - ) : null} {desktopWslState.enabled ? (