diff --git a/apps/server/src/environment/ServerEnvironmentLabel.test.ts b/apps/server/src/environment/ServerEnvironmentLabel.test.ts index 7e0cf0a99607e..b34dd75c3cbc0 100644 --- a/apps/server/src/environment/ServerEnvironmentLabel.test.ts +++ b/apps/server/src/environment/ServerEnvironmentLabel.test.ts @@ -30,12 +30,13 @@ const neverExits = ChildProcessSpawner.make(() => ), ); -it.effect("falls back to the hostname when hostnamectl never answers", () => +// Without /etc/machine-info the label comes from hostnamectl, which waits on D-Bus. +const linuxLabelWithoutPrettyHostname = (environment: NodeJS.ProcessEnv) => Effect.gen(function* () { - // Without /etc/machine-info the label comes from hostnamectl, which waits on D-Bus. const label = yield* resolveServerEnvironmentLabel({ cwdBaseName: "project" }).pipe( Effect.provideService(HostProcess.Platform, "linux"), Effect.provideService(HostProcess.Hostname, "devbox"), + Effect.provideService(HostProcess.Environment, environment), Effect.provide( Layer.mergeAll( FileSystem.layerNoop({ exists: () => Effect.succeed(false) }), @@ -47,6 +48,24 @@ it.effect("falls back to the hostname when hostnamectl never answers", () => Effect.forkChild, ); yield* TestClock.adjust("5 seconds"); - assert.equal(yield* Fiber.join(label), "devbox"); + return yield* Fiber.join(label); + }); + +it.effect("falls back to the hostname when hostnamectl never answers", () => + Effect.gen(function* () { + assert.equal(yield* linuxLabelWithoutPrettyHostname({}), "devbox"); + }), +); + +it.effect("names a WSL backend apart from the Windows hostname it inherits", () => + Effect.gen(function* () { + assert.equal( + yield* linuxLabelWithoutPrettyHostname({ WSL_DISTRO_NAME: "Ubuntu-24.04" }), + "WSL (Ubuntu-24.04)", + ); + assert.equal( + yield* linuxLabelWithoutPrettyHostname({ WSL_INTEROP: "/run/WSL/8_interop" }), + "WSL", + ); }), ); diff --git a/apps/server/src/environment/ServerEnvironmentLabel.ts b/apps/server/src/environment/ServerEnvironmentLabel.ts index fc59928cc5bc6..5cac687495bff 100644 --- a/apps/server/src/environment/ServerEnvironmentLabel.ts +++ b/apps/server/src/environment/ServerEnvironmentLabel.ts @@ -152,6 +152,14 @@ const runFriendlyLabelCommand = Effect.fn("runFriendlyLabelCommand")(function* ( return normalizeLabel(result.value.stdout); }); +// WSL inherits the Windows hostname, so without this a Windows host and its WSL backend share one name. +function resolveWslLabel(platform: NodeJS.Platform, environment: NodeJS.ProcessEnv): string | null { + if (platform !== "linux") return null; + const distro = normalizeLabel(environment.WSL_DISTRO_NAME); + if (distro) return `WSL (${distro})`; + return normalizeLabel(environment.WSL_INTEROP) ? "WSL" : null; +} + const resolveFriendlyHostLabel = Effect.fn("resolveFriendlyHostLabel")(function* () { const platform = yield* HostProcess.Platform; if (platform === "darwin") { @@ -189,6 +197,11 @@ export const resolveServerEnvironmentLabel = Effect.fn("resolveServerEnvironment return friendlyHostLabel; } + const wslLabel = resolveWslLabel(yield* HostProcess.Platform, yield* HostProcess.Environment); + if (wslLabel) { + return wslLabel; + } + const hostname = normalizeLabel(yield* HostProcess.Hostname); if (hostname) { return hostname; diff --git a/apps/web/src/components/settings/ConnectionsSettings.tsx b/apps/web/src/components/settings/ConnectionsSettings.tsx index da46823292cad..25dbe59f51a44 100644 --- a/apps/web/src/components/settings/ConnectionsSettings.tsx +++ b/apps/web/src/components/settings/ConnectionsSettings.tsx @@ -84,6 +84,8 @@ import { supportsDesktopAppUpdate, } from "~/versionSkew"; import { hasCloudPublicConfig } from "~/cloud/publicConfig"; +import { useCloudLinkState } from "~/cloud/cloudLinkState"; +import { isManagedTunnelActive } from "~/cloud/t3ConnectState"; import { RemoveT3ConnectEnvironmentDialog } from "../clerk/RemoveT3ConnectEnvironmentDialog"; import { authEnvironment } from "~/state/auth"; import { environmentCatalog } from "~/connection/catalog"; @@ -135,6 +137,7 @@ import { ITEM_ROW_CLASSNAME } from "./itemRows"; import { CloudLinkRow, CloudRemoteEnvironmentRows, + LocalBackendConnectRow, SavedBackendListRow, } from "./SavedEnvironmentRows"; import { AddEnvironmentDialog } from "./AddEnvironmentDialog"; @@ -230,6 +233,7 @@ function AccessSettings() { view="access" accessEnvironmentId={accessEnvironmentId} accessEnvironmentPicker={picker} + onSelectAccessEnvironment={setSelectedEnvironmentId} /> ); } @@ -238,10 +242,12 @@ function ConnectionsSettingsContent({ view, accessEnvironmentId, accessEnvironmentPicker = null, + onSelectAccessEnvironment, }: { readonly view: "environments" | "access"; readonly accessEnvironmentId: EnvironmentId | null; readonly accessEnvironmentPicker?: ReactNode; + readonly onSelectAccessEnvironment?: (environmentId: EnvironmentId) => void; }) { const desktopBridge = window.desktopBridge; const { environments } = useEnvironments(); @@ -267,6 +273,18 @@ function ConnectionsSettingsContent({ const listedEnvironments = savedEnvironments.filter( (environment) => !isDesktopLocalConnectionTarget(environment.entry.target), ); + // A WSL backend runs its own server and needs its own T3 Connect link; point to it from the host. + const accessLinkState = useCloudLinkState(accessEnvironmentId).data; + const desktopLocalBackends = + isPrimaryAccess && + desktopBridge !== undefined && + accessLinkState !== null && + isManagedTunnelActive(accessLinkState, undefined) + ? savedEnvironments.filter( + (environment) => + environment.entry.enabled && isDesktopLocalConnectionTarget(environment.entry.target), + ) + : []; const savedUpdateStates = useAtomValue( environmentUpdateStatesAtom( environmentIdsKey(savedEnvironments.map(({ environmentId }) => environmentId)), @@ -1239,6 +1257,16 @@ function ConnectionsSettingsContent({ canManageRelay={canManageRelay} /> ) : null} + {onSelectAccessEnvironment + ? desktopLocalBackends.map((environment) => ( + + )) + : null} {accessEnvironment ? (
diff --git a/apps/web/src/components/settings/SavedEnvironmentRows.tsx b/apps/web/src/components/settings/SavedEnvironmentRows.tsx index 866841b4bc6b7..eebe66046c9c1 100644 --- a/apps/web/src/components/settings/SavedEnvironmentRows.tsx +++ b/apps/web/src/components/settings/SavedEnvironmentRows.tsx @@ -51,6 +51,8 @@ import { hasCloudPublicConfig } from "~/cloud/publicConfig"; import { isElectron } from "~/env"; import { useT3ConnectTurnOn } from "~/cloud/useT3ConnectTurnOn"; import { useCloudLinkController } from "~/cloud/useCloudLinkController"; +import { useCloudLinkState } from "~/cloud/cloudLinkState"; +import { isManagedTunnelActive } from "~/cloud/t3ConnectState"; import { useManagedTunnelUsage } from "~/cloud/managedRelayState"; import { useT3ConnectAccountPage } from "../clerk/T3ConnectAccountPages"; import { TunnelLimitAlert, TunnelUsageMeter } from "../cloud/TunnelUsage"; @@ -768,6 +770,30 @@ export function CloudLinkRow({ return ; } +export function LocalBackendConnectRow({ + environmentId, + label, + onSelect, +}: { + readonly environmentId: EnvironmentId; + readonly label: string; + readonly onSelect: (environmentId: EnvironmentId) => void; +}) { + const linkState = useCloudLinkState(environmentId).data; + if (linkState === null || isManagedTunnelActive(linkState, undefined)) return null; + return ( + onSelect(environmentId)}> + Set up + + } + /> + ); +} + function EmptyRemoteEnvironments({ cloudEnabled = true }: { readonly cloudEnabled?: boolean }) { return ( diff --git a/apps/web/src/components/settings/useAccessEnvironment.ts b/apps/web/src/components/settings/useAccessEnvironment.ts index 6e94e2365ca7d..737570e5e3466 100644 --- a/apps/web/src/components/settings/useAccessEnvironment.ts +++ b/apps/web/src/components/settings/useAccessEnvironment.ts @@ -1,14 +1,13 @@ import type { EnvironmentId } from "@t3tools/contracts"; -import { isDesktopLocalConnectionTarget } from "../../connection/desktopLocal"; import { useEnvironments, usePrimaryEnvironmentId } from "../../state/environments"; import { resolveAccessEnvironmentId } from "./ConnectionsSettings.logic"; import { settingsScopeEnvironmentLabel } from "./settingsScopeAxis"; /** * The environments Sharing & access manages, the one `requested` resolves to, and its name. - * The MCP wizard uses the same, so both name an environment alike. A requested environment - * always counts, so a thread on a second WSL backend opens on that backend. + * The MCP wizard uses the same, so both name an environment alike. A desktop-local WSL backend + * is its own environment with its own access, so it is listed too. */ export function useAccessEnvironment(requested: EnvironmentId | null) { const { environments } = useEnvironments(); @@ -17,7 +16,7 @@ export function useAccessEnvironment(requested: EnvironmentId | null) { (environment) => environment.environmentId === primaryEnvironmentId || environment.environmentId === requested || - (environment.entry.enabled && !isDesktopLocalConnectionTarget(environment.entry.target)), + environment.entry.enabled, ); const environmentId = resolveAccessEnvironmentId({ primaryEnvironmentId, diff --git a/docs/user/install.md b/docs/user/install.md index ac0913f18d119..068cb5cf53872 100644 --- a/docs/user/install.md +++ b/docs/user/install.md @@ -146,6 +146,12 @@ there. Install the provider CLIs inside that distro. T3 Code installs its own server runtime there automatically; the first launch after an app update can take longer. +The WSL environment is separate from the Windows one and has its own access +settings. To reach it from your phone or another device, open **Settings → +Sharing & access**, choose **WSL (distro)** under **Showing access for**, and +turn on **T3 Connect** there. Once Windows is on T3 Connect, its page also +points to a WSL environment that is not. + ### Open a project from a terminal With the desktop app already running on the same machine: