From eb5a03ea98e5bc565ed9dc39f259688598dae11d Mon Sep 17 00:00:00 2001 From: Josh Gratton Date: Sun, 17 May 2026 13:28:31 -0400 Subject: [PATCH] feat(web): replace WSL swap dialog with a toggle + distro picker MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The WSL section in ConnectionsSettings was still shaped as a "switch backend" decision: pick local-or-wsl from one dropdown, confirm in a modal, watch a "restarting backend" spinner. That mental model is wrong for parallel backends. Toggling the WSL backend on/off doesn't bounce the Windows one, and switching distros only restarts the WSL instance. Replace with two plain rows: - "WSL backend" — a switch that enables/disables the second backend. Off by default for users who never opted in, so the normal flow looks the same as before. - "WSL distro" — a select that lists the installed distros, shown only when the toggle is on. Changing the selection writes the new wslDistro setting and lets the orchestrator restart just the WSL instance. Both controls fire the relevant new IPCs (setWslBackendEnabled, setWslDistro) without an AlertDialog confirmation. The reconcile is non-destructive: the orchestrator unregisters and re-registers the WSL pool instance, the primary stays up. Drop the confirm-then-apply state machine (pendingDesktopWslSelection, the dialog markup, the per-stage spinner copy). The error toast and disabled-while-updating spinner stay so the user gets feedback if the orchestrator's reconcile fails. BACKEND_VALUE_LOCAL is gone — there's no longer a "switch to local" option to express. BACKEND_VALUE_DEFAULT_WSL stays as the sentinel for the "track the WSL default" choice in the distro picker. --- .../settings/ConnectionsSettings.tsx | 292 +++++++----------- 1 file changed, 114 insertions(+), 178 deletions(-) diff --git a/apps/web/src/components/settings/ConnectionsSettings.tsx b/apps/web/src/components/settings/ConnectionsSettings.tsx index 38e849dbda..50b1f5d2aa 100644 --- a/apps/web/src/components/settings/ConnectionsSettings.tsx +++ b/apps/web/src/components/settings/ConnectionsSettings.tsx @@ -103,10 +103,10 @@ import { useServerConfig } from "~/rpc/serverState"; const DEFAULT_TAILSCALE_SERVE_PORT = 443; -// Select-value sentinels for the backend-runtime dropdown. The colon is -// rejected by DISTRO_NAME_PATTERN (validated by the desktop side), so these -// values can never collide with a real WSL distro name. -const BACKEND_VALUE_LOCAL = "backend:local"; +// 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. const BACKEND_VALUE_DEFAULT_WSL = "backend:default-wsl"; const accessTimestampFormatter = new Intl.DateTimeFormat(undefined, { @@ -1503,10 +1503,6 @@ export function ConnectionsSettings() { const [desktopWslState, setDesktopWslState] = useState(null); const [isUpdatingWslBackend, setIsUpdatingWslBackend] = useState(false); const [desktopWslError, setDesktopWslError] = useState(null); - const [pendingDesktopWslSelection, setPendingDesktopWslSelection] = useState<{ - readonly enabled: boolean; - readonly distro: string | null; - } | null>(null); const [pendingTailscaleServeEndpoint, setPendingTailscaleServeEndpoint] = useState(null); const [disableTailscaleServeDialogOpen, setDisableTailscaleServeDialogOpen] = useState(false); @@ -2356,192 +2352,132 @@ export function ConnectionsSettings() { ); }) : null; - const handleWslSelectionChange = useCallback( - (value: string) => { - if (!desktopWslState) return; - const target = - value === BACKEND_VALUE_LOCAL - ? { enabled: false, distro: null } - : { - enabled: true, - distro: value === BACKEND_VALUE_DEFAULT_WSL ? null : value, - }; - // The dropdown maps `state.distro: null` to the actual default distro - // name so a real option highlights — re-picking the visually-active row - // produces `target.distro = ""` while state is still - // `null`. Resolve both sides through the same null→default mapping - // before comparing so this is a true no-op. - const defaultDistroName = - desktopWslState.distros.find((distro) => distro.isDefault)?.name ?? null; - const resolvedCurrentDistro = desktopWslState.enabled - ? (desktopWslState.distro ?? defaultDistroName) - : null; - const resolvedTargetDistro = target.enabled ? (target.distro ?? defaultDistroName) : null; - if ( - target.enabled === desktopWslState.enabled && - resolvedTargetDistro === resolvedCurrentDistro - ) { - return; + // Apply a setting change immediately. The orchestrator reconciles the + // pool in the background and the primary backend is untouched, so we + // don't gate this behind a confirmation dialog. + const applyWslSettingChange = useCallback( + async (apply: () => Promise) => { + if (!desktopBridge) return; + setIsUpdatingWslBackend(true); + setDesktopWslError(null); + try { + setDesktopWslState(await apply()); + } catch (error) { + const message = error instanceof Error ? error.message : "Failed to update WSL backend."; + setDesktopWslError(message); + toastManager.add( + stackedThreadToast({ + type: "error", + title: "Could not change WSL backend", + description: message, + }), + ); + await desktopBridge + .getWslState() + .then((state) => setDesktopWslState(state)) + .catch(() => undefined); + } finally { + setIsUpdatingWslBackend(false); } - setPendingDesktopWslSelection(target); }, - [desktopWslState], + [desktopBridge], ); - const handleConfirmDesktopWslChange = useCallback(async () => { - if (!desktopBridge || !pendingDesktopWslSelection) return; - const target = pendingDesktopWslSelection; - setIsUpdatingWslBackend(true); - setDesktopWslError(null); + const handleToggleWslBackend = useCallback( + (enabled: boolean) => { + if (!desktopBridge || !desktopWslState || desktopWslState.enabled === enabled) return; + void applyWslSettingChange(() => desktopBridge.setWslBackendEnabled(enabled)); + }, + [applyWslSettingChange, desktopBridge, desktopWslState], + ); - // The new IPC is non-destructive: toggling WSL on/off or switching - // distros doesn't bounce the primary. The orchestrator picks up - // settings changes and reconciles the WSL pool instance in the - // background. No reauth dance, no welcome race, no rollback are - // needed; the primary stays up either way. - try { - // Set distro first so when we flip enabled=true the orchestrator - // immediately registers the right instance. - const afterDistro = await desktopBridge.setWslDistro(target.distro); - setDesktopWslState(afterDistro); - const afterEnabled = await desktopBridge.setWslBackendEnabled(target.enabled); - setDesktopWslState(afterEnabled); - setPendingDesktopWslSelection(null); - } catch (error) { - const message = error instanceof Error ? error.message : "Failed to update WSL backend."; - setDesktopWslError(message); - toastManager.add( - stackedThreadToast({ - type: "error", - title: "Could not change WSL backend", - description: message, - }), - ); - await desktopBridge - .getWslState() - .then((state) => setDesktopWslState(state)) - .catch(() => undefined); - } finally { - setIsUpdatingWslBackend(false); - } - }, [desktopBridge, pendingDesktopWslSelection]); + const handleSelectWslDistro = 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; + const resolvedNext = nextDistro ?? defaultDistroName; + if (resolvedCurrent === resolvedNext) return; + void applyWslSettingChange(() => desktopBridge.setWslDistro(nextDistro)); + }, + [applyWslSettingChange, desktopBridge, desktopWslState], + ); const renderWslRow = () => { if (!desktopWslState || !desktopWslState.available) return null; - // When distro is null ("track the WSL default"), map to the actual default - // distro's name if we know one so the Select highlights a real option - // instead of an orphan default sentinel with no matching item. Falls back - // to BACKEND_VALUE_DEFAULT_WSL only when no distros are listed yet — in - // that case the dropdown renders a single placeholder option that matches. + // Distro is null when the user wants the WSL default. Map it to the + // real default's name so the Select highlights a real option; fall + // back to the sentinel only when no distros are listed yet (the + // dropdown then renders a single placeholder that matches). const defaultDistroName = desktopWslState.distros.find((distro) => distro.isDefault)?.name ?? null; - const wslSelectValue = desktopWslState.distro ?? defaultDistroName ?? BACKEND_VALUE_DEFAULT_WSL; - const currentValue = desktopWslState.enabled ? wslSelectValue : BACKEND_VALUE_LOCAL; - const currentLabel = - currentValue === BACKEND_VALUE_LOCAL - ? "Local (Windows)" - : currentValue === BACKEND_VALUE_DEFAULT_WSL - ? "WSL: default distro" - : `WSL: ${currentValue}`; - const pendingTargetLabel = pendingDesktopWslSelection?.enabled - ? (pendingDesktopWslSelection.distro ?? "the default WSL distro") - : "Windows"; - const isSwitchingToWsl = pendingDesktopWslSelection?.enabled === true; + const distroSelectValue = + desktopWslState.distro ?? defaultDistroName ?? BACKEND_VALUE_DEFAULT_WSL; return ( - {desktopWslError} : null - } - control={ - { - if (isUpdatingWslBackend) return; - if (!open) setPendingDesktopWslSelection(null); - }} - > - - - - - {isSwitchingToWsl - ? desktopWslState.enabled - ? "Switch WSL distro?" - : "Enable WSL backend?" - : "Disable WSL backend?"} - - - {isSwitchingToWsl - ? `T3 Code will bring up a backend inside ${pendingTargetLabel}. The Windows backend keeps running so projects you opened against it stay where they are.` - : "T3 Code will stop the WSL backend. The Windows backend keeps running so projects you opened against it stay where they are."} - - - - } > - Cancel - - - - - - } - /> + + + } + /> + ) : null} + ); };