mirror of
https://github.com/JimLiu/baoyu-skills.git
synced 2026-07-13 22:29:48 +08:00
feat(baoyu-danger-x-to-markdown): WSL auto-detection and debug port env var
Add X_DEBUG_PORT env var for fixed port in WSL. Auto-detect WSL and resolve Chrome profile to Windows-native path.
This commit is contained in:
@@ -117,6 +117,8 @@ class CdpConnection {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function getFreePort(): Promise<number> {
|
async function getFreePort(): Promise<number> {
|
||||||
|
const fixed = parseInt(process.env.X_DEBUG_PORT || "", 10);
|
||||||
|
if (fixed > 0) return fixed;
|
||||||
return await new Promise((resolve, reject) => {
|
return await new Promise((resolve, reject) => {
|
||||||
const srv = net.createServer();
|
const srv = net.createServer();
|
||||||
srv.unref();
|
srv.unref();
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import { execSync } from "node:child_process";
|
||||||
import os from "node:os";
|
import os from "node:os";
|
||||||
import path from "node:path";
|
import path from "node:path";
|
||||||
import process from "node:process";
|
import process from "node:process";
|
||||||
@@ -30,9 +31,22 @@ export function resolveXToMarkdownCookiePath(): string {
|
|||||||
return path.join(resolveXToMarkdownDataDir(), COOKIE_FILE_NAME);
|
return path.join(resolveXToMarkdownDataDir(), COOKIE_FILE_NAME);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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 resolveXToMarkdownChromeProfileDir(): string {
|
export function resolveXToMarkdownChromeProfileDir(): string {
|
||||||
const override = process.env.X_CHROME_PROFILE_DIR?.trim();
|
const override = process.env.X_CHROME_PROFILE_DIR?.trim();
|
||||||
if (override) return path.resolve(override);
|
if (override) return path.resolve(override);
|
||||||
|
const wslHome = getWslWindowsHome();
|
||||||
|
if (wslHome) return path.join(wslHome, ".local", "share", APP_DATA_DIR, X_TO_MARKDOWN_DATA_DIR, PROFILE_DIR_NAME);
|
||||||
return path.join(resolveXToMarkdownDataDir(), PROFILE_DIR_NAME);
|
return path.join(resolveXToMarkdownDataDir(), PROFILE_DIR_NAME);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user