feat(desktop): route pickFolder by target environment id
PickFolderOptions gains an optional targetEnvironmentId so callers that know which local backend they're targeting (a project opened in WSL, for example) can ask for that backend's filesystem picker. The default behavior is unchanged: when targetEnvironmentId is undefined, the dialog opens against the Windows-native primary, which is what every existing caller gets. This is deliberate — most users never enable the WSL backend and shouldn't see a different picker showing up. Only callers that explicitly opt in route to WSL. When targetEnvironmentId starts with "wsl:", the handler uses the WSL helpers in wslPathParsing.ts. The id encodes the distro selection (e.g. "wsl:ubuntu") and falls back to the persisted wslDistro setting when the id is the "wsl:default" sentinel, matching how DesktopWslBackend.reconcile resolves the same input. The legacy "if wslBackendEnabled then always use WSL picker" branch is gone — that was the swap-mode mental model.
This commit is contained in:
1 parent
bad66041a6
commit
5d80468d7e
2 files changed
+46
-4
No files matched your search
@@ -4,6 +4,7 @@ import {
|
||||
DesktopEnvironmentBootstrapSchema,
|
||||
DesktopThemeSchema,
|
||||
PickFolderOptionsSchema,
|
||||
PRIMARY_LOCAL_ENVIRONMENT_ID,
|
||||
type DesktopEnvironmentBootstrap,
|
||||
} from "@t3tools/contracts";
|
||||
import * as Effect from "effect/Effect";
|
||||
@@ -76,6 +77,20 @@ export const getLocalEnvironmentBootstraps = makeSyncIpcMethod({
|
||||
}),
|
||||
});
|
||||
|
||||
const WSL_INSTANCE_ID_PREFIX = "wsl:";
|
||||
|
||||
// Pull the distro selection out of a backend instance id like
|
||||
// "wsl:ubuntu". Returns null for "wsl:default", which is the sentinel
|
||||
// for "track the user's WSL default distro" and maps to the
|
||||
// wslEnv-derived default at picker time.
|
||||
function extractWslDistroFromEnvironmentId(envId: string): string | null {
|
||||
if (!envId.startsWith(WSL_INSTANCE_ID_PREFIX)) {
|
||||
return null;
|
||||
}
|
||||
const suffix = envId.slice(WSL_INSTANCE_ID_PREFIX.length);
|
||||
return suffix === "default" || suffix.length === 0 ? null : suffix;
|
||||
}
|
||||
|
||||
export const pickFolder = makeIpcMethod({
|
||||
channel: IpcChannels.PICK_FOLDER_CHANNEL,
|
||||
payload: Schema.UndefinedOr(PickFolderOptionsSchema),
|
||||
@@ -86,16 +101,36 @@ export const pickFolder = makeIpcMethod({
|
||||
const environment = yield* DesktopEnvironment.DesktopEnvironment;
|
||||
const appSettings = yield* DesktopAppSettings.DesktopAppSettings;
|
||||
const wslEnvironment = yield* DesktopWslEnvironment.DesktopWslEnvironment;
|
||||
// Three picker modes:
|
||||
// - targetEnvironmentId omitted: default to the primary picker. Keeps
|
||||
// the historical behavior unchanged for users who never enabled the
|
||||
// WSL backend, and is what unfamiliar callers should get out of the
|
||||
// box.
|
||||
// - targetEnvironmentId starts with "wsl:": route to the WSL picker
|
||||
// using the distro encoded in the id (or the user's selected
|
||||
// wslDistro when the id is the "wsl:default" sentinel).
|
||||
// - anything else (incl. PRIMARY_LOCAL_ENVIRONMENT_ID): primary picker.
|
||||
const targetId = options?.targetEnvironmentId;
|
||||
const wslDistroFromTarget =
|
||||
targetId !== undefined && targetId.startsWith(WSL_INSTANCE_ID_PREFIX)
|
||||
? extractWslDistroFromEnvironmentId(targetId)
|
||||
: null;
|
||||
const useWsl =
|
||||
targetId !== undefined &&
|
||||
targetId !== PRIMARY_LOCAL_ENVIRONMENT_ID &&
|
||||
targetId.startsWith(WSL_INSTANCE_ID_PREFIX);
|
||||
const settings = yield* appSettings.get;
|
||||
const wslAvailable = yield* wslEnvironment.isAvailable;
|
||||
const useWsl = settings.wslBackendEnabled && wslAvailable;
|
||||
// Fall back to the persisted wslDistro when the id is the
|
||||
// "wsl:default" sentinel; the orchestrator uses the same fallback
|
||||
// for the actual backend.
|
||||
const wslDistro = useWsl ? (wslDistroFromTarget ?? settings.wslDistro) : null;
|
||||
const defaultPath = useWsl
|
||||
? Option.fromNullishOr(
|
||||
resolveWslPickFolderDefaultPath(
|
||||
options,
|
||||
{ distro: settings.wslDistro },
|
||||
{ distro: wslDistro },
|
||||
yield* wslEnvironment.listDistros,
|
||||
Option.getOrNull(yield* wslEnvironment.getUserHome(settings.wslDistro)),
|
||||
Option.getOrNull(yield* wslEnvironment.getUserHome(wslDistro)),
|
||||
),
|
||||
)
|
||||
: environment.resolvePickFolderDefaultPath(options);
|
||||
|
||||
@@ -374,10 +374,17 @@ export const DesktopServerExposureStateSchema = Schema.Struct({
|
||||
|
||||
export interface PickFolderOptions {
|
||||
initialPath?: string | null;
|
||||
// When set, the desktop dialog opens against the named backend's
|
||||
// filesystem instead of the primary's. Used by callers that already
|
||||
// know which local environment they're targeting (e.g. opening a
|
||||
// project that lives inside WSL). Omitting it keeps the historical
|
||||
// behavior so non-WSL users never see a different picker.
|
||||
targetEnvironmentId?: string;
|
||||
}
|
||||
|
||||
export const PickFolderOptionsSchema = Schema.Struct({
|
||||
initialPath: Schema.optionalKey(Schema.NullOr(Schema.String)),
|
||||
targetEnvironmentId: Schema.optionalKey(Schema.String),
|
||||
});
|
||||
|
||||
export interface DesktopWslDistro {
|
||||
|
||||
Reference in new issue
Block a user