Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

ConnectionsSettings.logic.ts

21 lines888 Bytes

1import type { DesktopBridge, DesktopWslState } from "@t3tools/contracts";
2​
3type WslEnableBridge = Pick<DesktopBridge, "setWslBackendEnabled" | "setWslDistro" | "setWslOnly">;
4​
5export async function applyWslEnableSelection(input: {
6 readonly bridge: WslEnableBridge;
7 readonly mode: "both" | "wsl-only";
8 readonly nextDistro: string | null;
9 readonly persistedDistro: string | null;
10}): Promise<DesktopWslState> {
11 const { bridge, mode, nextDistro, persistedDistro } = input;
12​
13 // Stage every preference before enabling. The desktop only relaunches for
14 // mode/distro changes while WSL is active, so the final enable observes the
15 // complete selection and is the only call that may relaunch.
16 await bridge.setWslOnly(mode === "wsl-only");
17 if (persistedDistro !== nextDistro) {
18 await bridge.setWslDistro(nextDistro);
19 }
20 return await bridge.setWslBackendEnabled(true);