feat: auto-restart on wsl-only toggle

Persisting the wsl-only setting and waiting for the next launch was
clunky: the user had to confirm a dialog and then close + reopen the
app for the toggle to take effect. The pool captures the primary
choice once at layer init, so the relaunch is unavoidable, but we can
do it for them. Same pattern the network-access toggle already uses.
This commit is contained in:
Josh Gratton committed 2026-05-18 11:01:55 -04:00
1 parent e00ad61e45
commit 3c82c95b31
2 files changed
+18 -12

No files matched your search

+13 -7
View File
@@ -2,6 +2,7 @@ import { DesktopWslStateSchema, type DesktopWslState } from "@t3tools/contracts"
import * as Effect from "effect/Effect";
import * as Schema from "effect/Schema";
import * as DesktopLifecycle from "../../app/DesktopLifecycle.ts";
import * as DesktopAppSettings from "../../settings/DesktopAppSettings.ts";
import * as DesktopWslBackend from "../../wsl/DesktopWslBackend.ts";
import * as DesktopWslEnvironment from "../../wsl/DesktopWslEnvironment.ts";
@@ -73,13 +74,18 @@ export const setWslOnly = makeIpcMethod({
payload: Schema.Boolean,
result: DesktopWslStateSchema,
handler: Effect.fn("desktop.ipc.wsl.setOnly")(function* (enabled) {
// wsl-only changes the pool's primary spec, which is captured
// once at layer init. Persist the new setting here; the actual
// mode flip lands on the next desktop launch. The renderer
// surfaces "T3 Code will restart" in the confirmation dialog so
// the user knows what to expect.
// wsl-only decides which backend the pool spins up as "primary",
// and that decision is captured once at layer init. After
// persisting the new value we relaunch so the user lands in the
// mode they just picked instead of having to close + reopen
// themselves. Same pattern as the server-exposure-mode change.
const appSettings = yield* DesktopAppSettings.DesktopAppSettings;
yield* appSettings.setWslOnly(enabled);
return yield* readWslState;
const lifecycle = yield* DesktopLifecycle.DesktopLifecycle;
const change = yield* appSettings.setWslOnly(enabled);
const state = yield* readWslState;
if (change.changed) {
yield* lifecycle.relaunch(`wslOnly=${enabled}`);
}
return state;
}),
});
@@ -2563,7 +2563,7 @@ export function ConnectionsSettings() {
{desktopWslState.enabled ? (
<SettingsRow
title="Run WSL only"
description="Stop the Windows backend and run only the WSL backend. Useful if you develop entirely inside WSL and don't want a second backend process. Requires an app restart."
description="Stop the Windows backend and run only the WSL backend. Useful if you develop entirely inside WSL and don't want a second backend process. T3 Code restarts when you change this."
control={
<Switch
checked={desktopWslState.wslOnly}
@@ -2811,8 +2811,8 @@ export function ConnectionsSettings() {
: pendingWslChange?.kind === "distro"
? "T3 Code will restart the WSL backend on the new distro. Sessions still running on the current distro will be interrupted."
: pendingWslChange?.nextValue
? "T3 Code will save this preference and switch to running only the WSL backend on the next app launch. Your Windows-side projects won't be accessible until you turn this off again."
: "T3 Code will save this preference and bring the Windows backend back up alongside WSL on the next app launch."}
? "T3 Code will restart and start only the WSL backend. Your Windows-side projects won't be accessible until you turn this off again."
: "T3 Code will restart and bring the Windows backend back up alongside WSL."}
</AlertDialogDescription>
</AlertDialogHeader>
<AlertDialogFooter>
@@ -2842,9 +2842,9 @@ export function ConnectionsSettings() {
) : pendingWslChange?.kind === "distro" ? (
"Switch distro"
) : pendingWslChange?.nextValue ? (
"Save and restart later"
"Restart and enable"
) : (
"Save and restart later"
"Restart and disable"
)}
</Button>
</AlertDialogFooter>