Skip to content

Commit 4537ac6

Browse files
committed
fix(android): remove hardcoded platform override from preload
1 parent 1d36d33 commit 4537ac6

5 files changed

Lines changed: 66 additions & 9 deletions

File tree

lib/android-preload.cjs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
// is not enough — we must monkey-patch child_process.spawn to re-inject it.
1010
"use strict";
1111

12-
Object.defineProperty(process, "platform", { value: "linux" });
13-
1412
// Fix process.execPath when termux-exec is unavailable
1513
const execPath = process.execPath;
1614
if (execPath.includes("linker64") || execPath.startsWith("/apex/")) {

lib/code.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { tmpdir } from "node:os";
44
import { fileURLToPath } from "node:url";
55

66
// Auto-updated by scripts/pack.ts
7-
const codeArchiveHash = "6969db4c56cd12e7";
7+
const codeArchiveHash = "665ca77ecb723171";
88

99
const archivePath = fileURLToPath(new URL("./code.tar.zst", import.meta.url));
1010

patches/code-server.patch

Lines changed: 28 additions & 3 deletions
Large diffs are not rendered by default.

pnpm-lock.yaml

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

scripts/patch.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,40 @@ code = code.replace(
127127

128128
writeFileSync(extHostPath, code);
129129

130+
// Step 2b: Fix `Platform not supported` throw in userDataPath switch.
131+
//
132+
// VS Code's `vs/platform/environment/node/userDataPath.ts` has a
133+
// `switch (process.platform)` with a `default: throw new Error("Platform not
134+
// supported")` branch. On Termux, `process.platform === "android"` hits that
135+
// branch and crashes server/pty-host/agent-host startup. The same switch gets
136+
// bundled into multiple entry files, so we patch each one.
137+
//
138+
// Fix: rewrite `case"linux":<body>;break;default:throw ...` so linux falls
139+
// through from default, giving unknown platforms the XDG/~/.config code path.
140+
const platformSwitchFiles = [
141+
"lib/vscode/out/server-main.js",
142+
"lib/vscode/out/vs/platform/terminal/node/ptyHostMain.js",
143+
"lib/vscode/out/vs/platform/agentHost/node/agentHostMain.js",
144+
];
145+
146+
// Variable names (`Ht`, `va`, etc.) differ per bundle due to minification,
147+
// so match them with a regex rather than literal strings.
148+
const platformSwitchRe =
149+
/case"linux":((?:(?!break;).)*?)break;default:throw new Error\("Platform not supported"\)/;
150+
151+
for (const rel of platformSwitchFiles) {
152+
const filePath = `${patchDir}/${rel}`;
153+
let src = readFileSync(filePath, "utf8");
154+
const match = src.match(platformSwitchRe);
155+
if (!match) {
156+
console.error(`Cannot patch ${rel} — platform switch pattern not found`);
157+
process.exit(1);
158+
}
159+
src = src.replace(platformSwitchRe, `case"linux":default:${match[1]}break`);
160+
writeFileSync(filePath, src);
161+
console.log(`Patched platform switch in ${rel}`);
162+
}
163+
130164
// Step 3: Commit the patch
131165
execSync(`pnpm patch-commit '${patchDir}'`, {
132166
encoding: "utf8",

0 commit comments

Comments
 (0)