Skip to content

Commit b213574

Browse files
authored
Merge branch 'main' into fix/windows-claude-sdk-executable-path
2 parents 220017b + 1735e27 commit b213574

75 files changed

Lines changed: 2838 additions & 447 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎apps/desktop/scripts/electron-launcher.mjs‎

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export const APP_BUNDLE_ID = isDevelopment
2020
? `com.t3tools.t3code.dev.${devBundleIdSuffix || "local"}`
2121
: "com.t3tools.t3code";
2222
const APP_PROTOCOL_SCHEMES = isDevelopment ? ["t3code-dev"] : ["t3code"];
23-
const LAUNCHER_VERSION = 12;
23+
const LAUNCHER_VERSION = 14;
2424
const defaultIconPath = NodePath.join(desktopDir, "resources", "icon.icns");
2525
const developmentMacIconPngPath = NodePath.join(
2626
repoRoot,
@@ -220,11 +220,12 @@ function ensureDevelopmentIconIcns(runtimeDir) {
220220
}
221221
}
222222

223-
function patchMainBundleInfoPlist(appBundlePath, iconPath) {
223+
function patchMainBundleInfoPlist(appBundlePath, iconPath, executableName) {
224224
const infoPlistPath = NodePath.join(appBundlePath, "Contents", "Info.plist");
225225
setPlistString(infoPlistPath, "CFBundleDisplayName", APP_DISPLAY_NAME);
226226
setPlistString(infoPlistPath, "CFBundleName", APP_DISPLAY_NAME);
227227
setPlistString(infoPlistPath, "CFBundleIdentifier", APP_BUNDLE_ID);
228+
setPlistString(infoPlistPath, "CFBundleExecutable", executableName);
228229
setPlistString(infoPlistPath, "CFBundleIconFile", "icon.icns");
229230
setPlistJson(infoPlistPath, "CFBundleURLTypes", [
230231
{
@@ -277,11 +278,25 @@ function readJson(path) {
277278
}
278279
}
279280

281+
export function resolveMacLauncherPaths(appBundlePath, displayName = APP_DISPLAY_NAME) {
282+
const executableDir = NodePath.join(appBundlePath, "Contents", "MacOS");
283+
const launcherExecutableName = `${displayName} Launcher`;
284+
return {
285+
launcherExecutableName,
286+
launcherBinaryPath: NodePath.join(executableDir, launcherExecutableName),
287+
runtimeElectronBinaryPath: NodePath.join(executableDir, "Electron"),
288+
};
289+
}
290+
280291
function buildMacLauncher(electronBinaryPath) {
281292
const sourceAppBundlePath = NodePath.resolve(NodePath.dirname(electronBinaryPath), "../..");
282293
const runtimeDir = NodePath.join(desktopDir, ".electron-runtime");
283294
const targetAppBundlePath = NodePath.join(runtimeDir, `${APP_DISPLAY_NAME}.app`);
284-
const targetBinaryPath = NodePath.join(targetAppBundlePath, "Contents", "MacOS", "Electron");
295+
const developmentPaths = resolveMacLauncherPaths(targetAppBundlePath);
296+
const runtimeElectronBinaryPath = developmentPaths.runtimeElectronBinaryPath;
297+
const launcherBinaryPath = isDevelopment
298+
? developmentPaths.launcherBinaryPath
299+
: runtimeElectronBinaryPath;
285300
const iconPath = isDevelopment ? ensureDevelopmentIconIcns(runtimeDir) : defaultIconPath;
286301
const metadataPath = NodePath.join(runtimeDir, "metadata.json");
287302

@@ -298,18 +313,19 @@ function buildMacLauncher(electronBinaryPath) {
298313

299314
const currentMetadata = readJson(metadataPath);
300315
if (
301-
NodeFS.existsSync(targetBinaryPath) &&
316+
NodeFS.existsSync(launcherBinaryPath) &&
317+
(!isDevelopment || NodeFS.existsSync(runtimeElectronBinaryPath)) &&
302318
currentMetadata &&
303319
JSON.stringify(currentMetadata) === JSON.stringify(expectedMetadata)
304320
) {
305321
if (isDevelopment) {
306322
// The launcher also handles protocol activations outside the dev runner,
307323
// so refresh its fallback environment on every launch. Never let a value
308324
// captured by an older parent app override the live dev-runner environment.
309-
writeDevelopmentLauncherScript(targetBinaryPath, electronBinaryPath);
325+
writeDevelopmentLauncherScript(launcherBinaryPath, runtimeElectronBinaryPath);
310326
}
311327
registerMacLauncherBundle(targetAppBundlePath);
312-
return targetBinaryPath;
328+
return launcherBinaryPath;
313329
}
314330

315331
NodeFS.rmSync(targetAppBundlePath, { recursive: true, force: true });
@@ -321,15 +337,24 @@ function buildMacLauncher(electronBinaryPath) {
321337
recursive: true,
322338
verbatimSymlinks: true,
323339
});
324-
patchMainBundleInfoPlist(targetAppBundlePath, iconPath);
340+
patchMainBundleInfoPlist(
341+
targetAppBundlePath,
342+
iconPath,
343+
isDevelopment ? developmentPaths.launcherExecutableName : "Electron",
344+
);
325345
patchHelperBundleInfoPlists(targetAppBundlePath);
326346
if (isDevelopment) {
327-
writeDevelopmentLauncherScript(targetBinaryPath, electronBinaryPath);
347+
// Keep Electron's native executable inside the branded bundle. Launching the
348+
// node_modules copy makes macOS associate the process (and Dock label) with
349+
// Electron.app even though this bundle's Info.plist has the T3 Code name.
350+
// Its conventional executable name also keeps Electron's default-app runtime
351+
// in development mode instead of making app.isPackaged report true.
352+
writeDevelopmentLauncherScript(launcherBinaryPath, runtimeElectronBinaryPath);
328353
}
329354
NodeFS.writeFileSync(metadataPath, `${JSON.stringify(expectedMetadata, null, 2)}\n`);
330355
registerMacLauncherBundle(targetAppBundlePath);
331356

332-
return targetBinaryPath;
357+
return launcherBinaryPath;
333358
}
334359

335360
function isLinuxSetuidSandboxConfigured(electronBinaryPath) {

‎apps/desktop/scripts/electron-launcher.test.mjs‎

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
import { assert, describe, it } from "vite-plus/test";
22

3-
import { makeDevelopmentLauncherScript, resolveElectronBinaryPath } from "./electron-launcher.mjs";
3+
import {
4+
makeDevelopmentLauncherScript,
5+
resolveElectronBinaryPath,
6+
resolveMacLauncherPaths,
7+
} from "./electron-launcher.mjs";
48

59
describe("electron development launcher", () => {
610
it("uses captured values only as fallbacks for a live runner environment", () => {
@@ -45,4 +49,33 @@ describe("electron development launcher", () => {
4549
);
4650
assert.deepEqual(calls, ["ensure", "require:electron"]);
4751
});
52+
53+
it("keeps the native Electron executable name inside the branded macOS bundle", () => {
54+
const paths = resolveMacLauncherPaths(
55+
"/repo/apps/desktop/.electron-runtime/T3 Code (Dev).app",
56+
"T3 Code (Dev)",
57+
);
58+
59+
assert.equal(paths.launcherExecutableName, "T3 Code (Dev) Launcher");
60+
assert.equal(
61+
paths.launcherBinaryPath,
62+
"/repo/apps/desktop/.electron-runtime/T3 Code (Dev).app/Contents/MacOS/T3 Code (Dev) Launcher",
63+
);
64+
assert.equal(
65+
paths.runtimeElectronBinaryPath,
66+
"/repo/apps/desktop/.electron-runtime/T3 Code (Dev).app/Contents/MacOS/Electron",
67+
);
68+
69+
const script = makeDevelopmentLauncherScript({
70+
electronBinaryPath: paths.runtimeElectronBinaryPath,
71+
mainEntryPath: "/repo/apps/desktop/dist-electron/main.cjs",
72+
desktopRoot: "/repo/apps/desktop",
73+
environment: {},
74+
});
75+
assert.include(
76+
script,
77+
"exec '/repo/apps/desktop/.electron-runtime/T3 Code (Dev).app/Contents/MacOS/Electron'",
78+
);
79+
assert.notInclude(script, "node_modules/electron");
80+
});
4881
});

‎apps/desktop/src/electron/ElectronMenu.test.ts‎

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@ const TestLayer = ElectronMenu.layer.pipe(
3131
Layer.provide(Layer.succeed(HostProcessPlatform, "linux")),
3232
);
3333

34+
const makeWindow = (zoomFactor = 1): Electron.BrowserWindow =>
35+
({
36+
id: 7,
37+
webContents: { getZoomFactor: () => zoomFactor },
38+
}) as unknown as Electron.BrowserWindow;
39+
3440
describe("ElectronMenu", () => {
3541
beforeEach(() => {
3642
buildFromTemplateMock.mockReset();
@@ -70,7 +76,7 @@ describe("ElectronMenu", () => {
7076

7177
const electronMenu = yield* ElectronMenu.ElectronMenu;
7278
const selectedItemId = yield* electronMenu.showContextMenu({
73-
window: {} as Electron.BrowserWindow,
79+
window: makeWindow(),
7480
items: [{ id: "copy", label: "Copy" }],
7581
position: Option.none(),
7682
});
@@ -81,20 +87,24 @@ describe("ElectronMenu", () => {
8187

8288
it.effect("resolves with none when the menu closes without a click", () =>
8389
Effect.gen(function* () {
90+
let popupOptions: Electron.PopupOptions | undefined;
8491
buildFromTemplateMock.mockImplementation(() => ({
8592
popup: (options: Electron.PopupOptions) => {
93+
popupOptions = options;
8694
options.callback?.();
8795
},
8896
}));
8997

9098
const electronMenu = yield* ElectronMenu.ElectronMenu;
9199
const selectedItemId = yield* electronMenu.showContextMenu({
92-
window: {} as Electron.BrowserWindow,
100+
window: makeWindow(2),
93101
items: [{ id: "copy", label: "Copy" }],
94102
position: Option.some({ x: 10.8, y: 20.2 }),
95103
});
96104

97105
assert.isTrue(Option.isNone(selectedItemId));
106+
assert.equal(popupOptions?.x, 21);
107+
assert.equal(popupOptions?.y, 40);
98108
assert.deepEqual(buildFromTemplateMock.mock.calls[0]?.[0][0], {
99109
label: "Copy",
100110
enabled: true,

‎apps/desktop/src/electron/ElectronMenu.ts‎

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,13 +94,20 @@ function normalizeContextMenuItems(source: readonly ContextMenuItem[]): ContextM
9494
return normalizedItems;
9595
}
9696

97+
// Renderer positions arrive in CSS pixels; popup() expects window points, so
98+
// page zoom must be factored in or menus drift proportionally to their
99+
// distance from the window origin.
97100
const normalizePosition = (
98101
position: Option.Option<ElectronMenuPosition>,
102+
zoomFactor: number,
99103
): Option.Option<ElectronMenuPosition> =>
100104
Option.filter(
101105
position,
102-
({ x, y }) => Number.isFinite(x) && Number.isFinite(y) && x >= 0 && y >= 0,
103-
).pipe(Option.map(({ x, y }) => ({ x: Math.floor(x), y: Math.floor(y) })));
106+
({ x, y }) =>
107+
Number.isFinite(x) && Number.isFinite(y) && x >= 0 && y >= 0 && Number.isFinite(zoomFactor),
108+
).pipe(
109+
Option.map(({ x, y }) => ({ x: Math.floor(x * zoomFactor), y: Math.floor(y * zoomFactor) })),
110+
);
104111

105112
export const make = Effect.gen(function* () {
106113
const platform = yield* HostProcessPlatform;
@@ -214,7 +221,10 @@ export const make = Effect.gen(function* () {
214221

215222
try {
216223
const menu = Electron.Menu.buildFromTemplate(buildTemplate(normalizedItems, complete));
217-
const popupPosition = normalizePosition(input.position);
224+
const popupPosition = normalizePosition(
225+
input.position,
226+
input.window.webContents.getZoomFactor(),
227+
);
218228
const popupOptions = Option.match(popupPosition, {
219229
onNone: (): Electron.PopupOptions => ({
220230
window: input.window,

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import {
1616
formatNodePtyProbeFailureReason,
1717
formatWslShellTransportFailureReason,
1818
parseNodePath,
19+
parseNodeVersion,
1920
parseResolvedPath,
2021
parseToolchainReport,
2122
probeWslDistros,
@@ -173,6 +174,29 @@ describe("parseNodePath", () => {
173174
});
174175
});
175176

177+
describe("parseNodeVersion", () => {
178+
it("extracts the node version from a nodeVersion: line", () => {
179+
expect(parseNodeVersion("nodeVersion:24.10.0")).toBe("24.10.0");
180+
});
181+
182+
it("returns null when the version value is empty", () => {
183+
expect(parseNodeVersion("nodeVersion:")).toBeNull();
184+
});
185+
186+
it("returns null when there is no nodeVersion line at all", () => {
187+
expect(parseNodeVersion("nodePath:/usr/bin/node\nresolvedPath:/usr/bin")).toBeNull();
188+
});
189+
190+
it("ignores surrounding noise and trims whitespace", () => {
191+
const stdout = [
192+
"some preamble noise",
193+
" nodeVersion:22.16.0 ",
194+
"nodePath:/usr/bin/node",
195+
].join("\n");
196+
expect(parseNodeVersion(stdout)).toBe("22.16.0");
197+
});
198+
});
199+
176200
describe("parseResolvedPath", () => {
177201
it("preserves spaces and apostrophes in the resolved login-shell PATH", () => {
178202
const resolvedPath = "/home/test user/bin:/opt/test's tools/bin:/usr/bin:/bin";

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

Lines changed: 42 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,11 @@ export interface EnsureWslNodePtyOptions {
3232
}
3333

3434
export type EnsureWslNodePtyResult =
35-
| { readonly ok: true; readonly nodePath: string; readonly resolvedPath: string }
35+
| {
36+
readonly ok: true;
37+
readonly nodePath: string;
38+
readonly resolvedPath: string;
39+
}
3640
| {
3741
readonly ok: false;
3842
readonly reason: string;
@@ -222,6 +226,7 @@ export const formatNodePtyProbeFailureReason = (exitCode: number): string | null
222226
const NODE_PTY_PROBE_SCRIPT = (
223227
linuxServerDir: string,
224228
) => `printf 'nodePath:%s\\n' "$(command -v node 2>/dev/null)"
229+
printf 'nodeVersion:%s\\n' "$(node -p 'process.versions.node' 2>/dev/null)"
225230
printf 'resolvedPath:%s\\n' "$PATH"
226231
cd ${shellQuote(linuxServerDir)} && node <<'NODE' >/dev/null 2>&1
227232
// The server bundle externalizes its deps to node_modules, and the WSL Node
@@ -318,6 +323,16 @@ export const parseNodePath = (stdout: string): string | null => {
318323
return path ?? null;
319324
};
320325

326+
export const parseNodeVersion = (stdout: string): string | null => {
327+
const version = stdout
328+
.split("\n")
329+
.map((line) => line.trim())
330+
.filter((line) => line.startsWith("nodeVersion:"))
331+
.map((line) => line.slice("nodeVersion:".length).trim())
332+
.find((value) => value.length > 0);
333+
return version ?? null;
334+
};
335+
321336
// Captures the login-shell PATH after the shared resolver has loaded version
322337
// managers. Preserve the value byte-for-byte apart from a Windows-style CR so
323338
// paths containing spaces or apostrophes can be forwarded as one env argv.
@@ -404,7 +419,11 @@ const ensureNodePtyImpl = (
404419

405420
const transportFailureReason = formatWslShellTransportFailureReason(probe.transportFailure);
406421
if (transportFailureReason !== null) {
407-
return { ok: false, reason: transportFailureReason, fatal: false } as const;
422+
return {
423+
ok: false,
424+
reason: transportFailureReason,
425+
fatal: false,
426+
} as const;
408427
}
409428

410429
// No node at all, even after the shared resolver repaired PATH. Surface
@@ -457,12 +476,31 @@ const ensureNodePtyImpl = (
457476
} as const;
458477
}
459478

460-
if (probe.exitCode === 0) return { ok: true, nodePath, resolvedPath } as const;
479+
if (probe.exitCode === 0) {
480+
const rawVersion = parseNodeVersion(probe.stdout);
481+
if (
482+
rawVersion !== null &&
483+
options.nodeEngineRange &&
484+
!satisfiesSemverRange(rawVersion, options.nodeEngineRange.trim())
485+
) {
486+
const range = options.nodeEngineRange.trim();
487+
return {
488+
ok: false,
489+
reason: `WSL Node.js ${rawVersion} does not satisfy the server's required engine range (${range}). Install a compatible version, and restart the desktop app.`,
490+
fatal: true,
491+
} as const;
492+
}
493+
return { ok: true, nodePath, resolvedPath } as const;
494+
}
461495

462496
if (options.allowBuild !== true) {
463497
const packagedProbeFailure = formatNodePtyProbeFailureReason(probe.exitCode);
464498
if (packagedProbeFailure !== null) {
465-
return { ok: false, reason: packagedProbeFailure, fatal: true } as const;
499+
return {
500+
ok: false,
501+
reason: packagedProbeFailure,
502+
fatal: true,
503+
} as const;
466504
}
467505
}
468506

Lines changed: 4 additions & 0 deletions
Loading

0 commit comments

Comments
 (0)