@@ -127,6 +127,40 @@ code = code.replace(
127127
128128writeFileSync ( 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+ / c a s e " l i n u x " : ( (?: (? ! b r e a k ; ) .) * ?) b r e a k ; d e f a u l t : t h r o w n e w E r r o r \( " P l a t f o r m n o t s u p p o r t e d " \) / ;
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
131165execSync ( `pnpm patch-commit '${ patchDir } '` , {
132166 encoding : "utf8" ,
0 commit comments