From 166cb323dd861fbbe68f97e2d78701f53a47a604 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jim=20Liu=20=E5=AE=9D=E7=8E=89?= Date: Mon, 2 Mar 2026 12:07:02 -0600 Subject: [PATCH] feat(baoyu-post-to-x): auto-detect WSL for Chrome profile path In WSL2, auto-resolve Windows USERPROFILE via cmd.exe/wslpath so Chrome profile is stored on Windows-native filesystem. Fixes login state persistence when using Windows Chrome from WSL. --- skills/baoyu-post-to-x/scripts/x-utils.ts | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/skills/baoyu-post-to-x/scripts/x-utils.ts b/skills/baoyu-post-to-x/scripts/x-utils.ts index fe96cc5..b86ae8b 100644 --- a/skills/baoyu-post-to-x/scripts/x-utils.ts +++ b/skills/baoyu-post-to-x/scripts/x-utils.ts @@ -1,4 +1,4 @@ -import { spawnSync } from 'node:child_process'; +import { execSync, spawnSync } from 'node:child_process'; import fs from 'node:fs'; import net from 'node:net'; import os from 'node:os'; @@ -69,10 +69,22 @@ export function findChromeExecutable(candidates: PlatformCandidates): string | u return undefined; } +let _wslHome: string | null | undefined; +function getWslWindowsHome(): string | null { + if (_wslHome !== undefined) return _wslHome; + if (!process.env.WSL_DISTRO_NAME) { _wslHome = null; return null; } + try { + const raw = execSync('cmd.exe /C "echo %USERPROFILE%"', { encoding: 'utf-8', timeout: 5000 }).trim().replace(/\r/g, ''); + _wslHome = execSync(`wslpath -u "${raw}"`, { encoding: 'utf-8', timeout: 5000 }).trim() || null; + } catch { _wslHome = null; } + return _wslHome; +} + export function getDefaultProfileDir(): string { const override = process.env.X_BROWSER_PROFILE_DIR?.trim(); if (override) return path.resolve(override); - const base = process.env.XDG_DATA_HOME || path.join(os.homedir(), '.local', 'share'); + const home = getWslWindowsHome() ?? os.homedir(); + const base = process.env.XDG_DATA_HOME || path.join(home, '.local', 'share'); return path.join(base, 'x-browser-profile'); }