mirror of
https://github.com/YuJunZhiXue/dsh-purge.git
synced 2026-11-28 01:20:22 +08:00
pathLooksDesktop 需安装形态才判桌面;源码 apps/cli 跳过 hide-console;revertAll 无 bak 只跳过不删。 Co-authored-by: Cursor <cursoragent@cursor.com>
84 lines
2.9 KiB
JavaScript
84 lines
2.9 KiB
JavaScript
import path from "node:path";
|
|
|
|
/** 当前已接线的宿主面。gui / tui 先能识别,适配仍回退 web。 */
|
|
export const SURFACES = Object.freeze(["web", "desktop", "gui", "tui"]);
|
|
|
|
function norm(value) {
|
|
return String(value || "").trim().toLowerCase();
|
|
}
|
|
|
|
function slash(value) {
|
|
return String(value || "").replace(/\\/g, "/").toLowerCase();
|
|
}
|
|
|
|
function exeName(execPath) {
|
|
return path.basename(String(execPath || "")).toLowerCase();
|
|
}
|
|
|
|
export function pathLooksDesktop(p) {
|
|
const n = slash(p);
|
|
if (!n) return false;
|
|
// 安装目录可能叫 "DeepSeek Harness" / "deepseek-harness",但源码仓库(monorepo)也叫这个名字 ——
|
|
// 所以只凭目录名不算,还必须带桌面安装形态(resources/、exe、.app/)。与 desktop.looksLikeDesktopName 对齐。
|
|
const harnessDir = n.includes("/deepseek harness/") || n.includes("/deepseek-harness/");
|
|
return (
|
|
n.includes("/dsh desktop/") ||
|
|
n.includes("/dsh desktop.app/") ||
|
|
n.includes("dsh-desktop") ||
|
|
n.includes("dsh-plugin-desktop") ||
|
|
n.includes("/deepseek harness.app/") ||
|
|
(harnessDir && (n.includes("/resources/") || n.includes("/contents/resources/") || n.endsWith("/resources"))) ||
|
|
/\/dsh desktop\.exe$/i.test(n) ||
|
|
/\/deepseek[- ]harness\.exe$/i.test(n) ||
|
|
n.endsWith("/host-process-entry.js") ||
|
|
n.endsWith("/desktop-cli.js")
|
|
);
|
|
}
|
|
|
|
export function isDesktopSurface(input = {}) {
|
|
const env = input.env ?? process.env;
|
|
const forced = norm(env.DSH_SURFACE);
|
|
if (forced === "desktop") return true;
|
|
if (forced && SURFACES.includes(forced)) return false;
|
|
|
|
const execPath = input.execPath ?? process.execPath;
|
|
const name = exeName(execPath);
|
|
if (
|
|
name === "dsh desktop.exe" ||
|
|
name === "dsh desktop" ||
|
|
name === "deepseek harness.exe" ||
|
|
name === "deepseek-harness.exe"
|
|
) return true;
|
|
if (pathLooksDesktop(execPath)) return true;
|
|
|
|
const resourcesPath = input.resourcesPath ?? process.resourcesPath;
|
|
if (pathLooksDesktop(resourcesPath)) return true;
|
|
|
|
const argv = input.argv ?? process.argv;
|
|
if ((Array.isArray(argv) ? argv : []).some((arg) => pathLooksDesktop(arg))) return true;
|
|
|
|
const parentPort = input.parentPort !== undefined ? input.parentPort : process.parentPort;
|
|
if (parentPort && (pathLooksDesktop(execPath) || pathLooksDesktop(resourcesPath))) return true;
|
|
|
|
if (env.ELECTRON_RUN_AS_NODE && pathLooksDesktop(execPath)) return true;
|
|
return false;
|
|
}
|
|
|
|
function forcedSurface(env) {
|
|
const forced = norm(env.DSH_SURFACE);
|
|
return SURFACES.includes(forced) ? forced : "";
|
|
}
|
|
|
|
export function detectSurface(input = {}) {
|
|
const env = input.env ?? process.env;
|
|
const forced = forcedSurface(env);
|
|
if (forced) return forced;
|
|
if (isDesktopSurface(input)) return "desktop";
|
|
return "web";
|
|
}
|
|
|
|
/** gui / tui 尚未单独适配,先走 web 重启与探测。 */
|
|
export function adapterFor(kind) {
|
|
return kind === "desktop" ? "desktop" : "web";
|
|
}
|