Skip to content

Commit b8851c3

Browse files
fix(desktop): read Windows roots and the desktop name from the live env
Windows variable names are case-insensitive only on process.env, and shell discovery can replace XDG_CURRENT_DESKTOP after startup. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent a597d20 commit b8851c3

4 files changed

Lines changed: 12 additions & 26 deletions

File tree

‎apps/desktop/src/app/DesktopCliCommand.ts‎

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import * as NodeFSP from "node:fs/promises";
33

44
import type { DesktopCliCommandState } from "@t3tools/contracts";
55
import * as HostProcess from "@t3tools/shared/HostProcess";
6-
import * as Config from "effect/Config";
76
import * as Context from "effect/Context";
87
import * as Effect from "effect/Effect";
98
import * as FileSystem from "effect/FileSystem";
@@ -63,17 +62,12 @@ export class DesktopCliCommand extends Context.Service<
6362
}
6463
>()("@t3tools/desktop/app/DesktopCliCommand") {}
6564

66-
/** @public */
67-
const WindowsRootConfig = Config.String("SystemRoot").pipe(
68-
Config.orElse(() => Config.String("WINDIR")),
69-
Config.option,
70-
);
71-
7265
export const make = Effect.gen(function* () {
7366
const environment = yield* DesktopEnvironment.DesktopEnvironment;
7467
const fs = yield* FileSystem.FileSystem;
7568
const spawner = yield* ChildProcessSpawner.ChildProcessSpawner;
76-
// Shell discovery patches PATH into the live env after startup; a Config read would be stale.
69+
// Read the live env: shell discovery patches PATH after startup, and Windows variable
70+
// names are case-insensitive only on process.env, not on Config's copy of it.
7771
const env = yield* HostProcess.Environment;
7872
const path = environment.path;
7973
const windows = environment.platform === "win32";
@@ -114,15 +108,15 @@ export const make = Effect.gen(function* () {
114108
Effect.orElseSucceed(() => false),
115109
);
116110

117-
const powershell = (env: Record<string, string>) =>
111+
const powershell = (overrides: Record<string, string>) =>
118112
Effect.scoped(
119113
Effect.gen(function* () {
120-
const root = Option.getOrUndefined(yield* WindowsRootConfig);
114+
const root = env.SystemRoot ?? env.WINDIR;
121115
const handle = yield* spawner.spawn(
122116
ChildProcess.make(
123117
root ? `${root}\\System32\\WindowsPowerShell\\v1.0\\powershell.exe` : "powershell.exe",
124118
["-NoLogo", "-NoProfile", "-NonInteractive", "-Command", WINDOWS_USER_PATH_SCRIPT],
125-
{ stdin: "ignore", stderr: "ignore", env, extendEnv: true },
119+
{ stdin: "ignore", stderr: "ignore", env: overrides, extendEnv: true },
126120
),
127121
);
128122
const [stdout, exitCode] = yield* Effect.all(

‎apps/desktop/src/snapShot/DesktopSnapShot.test.ts‎

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import {
77
type DesktopSnapShotEvent,
88
} from "@t3tools/contracts";
99
import * as SecureRandom from "effect/crypto/SecureRandom";
10-
import * as ConfigProvider from "effect/ConfigProvider";
1110
import * as Effect from "effect/Effect";
1211
import * as Fiber from "effect/Fiber";
1312
import * as FileSystem from "effect/FileSystem";
@@ -1922,13 +1921,7 @@ it.effect(
19221921
linuxBackendMock.mockResolvedValue(backend);
19231922
yield* Effect.scoped(
19241923
Effect.gen(function* () {
1925-
const service = yield* DesktopSnapShot.make.pipe(
1926-
Effect.provide(
1927-
ConfigProvider.layer(
1928-
ConfigProvider.fromEnv({ env: { XDG_CURRENT_DESKTOP: desktop } }),
1929-
),
1930-
),
1931-
);
1924+
const service = yield* DesktopSnapShot.make;
19321925
yield* service.initialize;
19331926
const state = yield* service.state;
19341927
assert.equal(state.linuxDesktop, desktop.toLowerCase());

‎apps/desktop/src/snapShot/DesktopSnapShot.ts‎

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ import * as Base64 from "effect/encoding/Base64";
3030
import * as FileSystem from "effect/FileSystem";
3131
import * as Layer from "effect/Layer";
3232
import * as Option from "effect/Option";
33-
import * as Config from "effect/Config";
3433
import * as Path from "effect/Path";
3534
import * as Predicate from "effect/Predicate";
3635
import * as Ref from "effect/Ref";
@@ -769,9 +768,8 @@ export const make = Effect.gen(function* () {
769768
const captureDirectory = path.join(environment.stateDir, "snap-shots");
770769
const linuxAppId = environment.linuxDesktopEntryName.replace(/\.desktop$/, "");
771770
const home = yield* HostProcess.HomeDirectory;
772-
const xdgCurrentDesktop = yield* Config.String("XDG_CURRENT_DESKTOP").pipe(
773-
Config.withDefault(""),
774-
);
771+
// Shell discovery can replace XDG_CURRENT_DESKTOP after startup, so read the live env per state.
772+
const hostEnv = yield* HostProcess.Environment;
775773
let shortcutVerified = false;
776774
const gnomeSetupPaths = {
777775
bundle: environment.isPackaged
@@ -1625,7 +1623,7 @@ export const make = Effect.gen(function* () {
16251623
Effect.gen(function* () {
16261624
const linuxDesktop =
16271625
state.mode === "portal"
1628-
? xdgCurrentDesktop
1626+
? (hostEnv.XDG_CURRENT_DESKTOP ?? "")
16291627
.toLowerCase()
16301628
.split(":")
16311629
.find(

‎apps/desktop/src/wsl/DesktopWslEnvironment.ts‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import * as Config from "effect/Config";
21
import * as Context from "effect/Context";
32
import * as Duration from "effect/Duration";
43
import * as Effect from "effect/Effect";
@@ -10,6 +9,7 @@ import * as Schema from "effect/Schema";
109
import * as Stream from "effect/Stream";
1110
import { ChildProcess, ChildProcessSpawner } from "effect/process";
1211

12+
import * as HostProcess from "@t3tools/shared/HostProcess";
1313
import { buildRemoteNodeEnvScript } from "@t3tools/ssh/tunnel";
1414
import { satisfiesSemverRange } from "@t3tools/shared/semver";
1515

@@ -1142,7 +1142,8 @@ export const layer = Layer.effect(
11421142
const environment = yield* DesktopEnvironment.DesktopEnvironment;
11431143
const spawner = yield* ChildProcessSpawner.ChildProcessSpawner;
11441144
const fileSystem = yield* FileSystem.FileSystem;
1145-
const windir = yield* Config.String("WINDIR").pipe(Config.withDefault("C:\\Windows"));
1145+
// Not Config: Windows variable names are case-insensitive only on the live process.env.
1146+
const windir = (yield* HostProcess.Environment).WINDIR ?? "C:\\Windows";
11461147

11471148
const provideSpawner = <A, E>(
11481149
effect: Effect.Effect<A, E, ChildProcessSpawner.ChildProcessSpawner>,

0 commit comments

Comments
 (0)