panrouter 3.3.0 → 3.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cli.mjs +14 -3
- package/package.json +1 -1
package/cli.mjs
CHANGED
|
@@ -91,6 +91,19 @@ async function startTray() {
|
|
|
91
91
|
const psPath = path.join(__dirname, "tray-daemon.ps1");
|
|
92
92
|
log("..", "正在后台启动代理...", "yellow");
|
|
93
93
|
|
|
94
|
+
// 【终极编码修复】:PowerShell 在中文系统下默认以 GBK 解析无 BOM 的 UTF-8 文件,导致中文吞掉相邻的引号。
|
|
95
|
+
// 方案:将脚本内容强制加上 UTF-8 BOM 头 (EF BB BF),存入临时文件后再让 PowerShell 执行。
|
|
96
|
+
let runPsPath = psPath;
|
|
97
|
+
try {
|
|
98
|
+
const tempDir = process.env.TEMP || process.env.TMP || __dirname;
|
|
99
|
+
runPsPath = path.join(tempDir, "panrouter_tray_run.ps1");
|
|
100
|
+
const psContent = fs.readFileSync(psPath, "utf8");
|
|
101
|
+
const bom = Buffer.from([0xEF, 0xBB, 0xBF]);
|
|
102
|
+
fs.writeFileSync(runPsPath, Buffer.concat([bom, Buffer.from(psContent, "utf8")]));
|
|
103
|
+
} catch (e) {
|
|
104
|
+
runPsPath = psPath;
|
|
105
|
+
}
|
|
106
|
+
|
|
94
107
|
try {
|
|
95
108
|
if (process.platform === "win32") {
|
|
96
109
|
execSync('taskkill /f /fi "WINDOWTITLE eq Pan Router*" >nul 2>&1', { stdio: "pipe" });
|
|
@@ -122,13 +135,12 @@ async function startTray() {
|
|
|
122
135
|
|
|
123
136
|
log("..", "正在加载系统托盘...", "yellow");
|
|
124
137
|
|
|
125
|
-
// 【核心修复】:增加 -STA 参数防止 UI 线程崩溃,增加 shell:true 确保一定能找到 powershell
|
|
126
138
|
const tray = spawn("powershell.exe", [
|
|
127
139
|
"-NoProfile",
|
|
128
140
|
"-STA",
|
|
129
141
|
"-ExecutionPolicy", "Bypass",
|
|
130
142
|
"-WindowStyle", "Hidden",
|
|
131
|
-
"-File", `"${
|
|
143
|
+
"-File", `"${runPsPath}"`
|
|
132
144
|
], {
|
|
133
145
|
cwd: __dirname,
|
|
134
146
|
stdio: ['ignore', 'pipe', 'pipe'],
|
|
@@ -141,7 +153,6 @@ async function startTray() {
|
|
|
141
153
|
tray.stdout.on("data", d => psOutput += d.toString());
|
|
142
154
|
tray.stderr.on("data", d => psOutput += d.toString());
|
|
143
155
|
|
|
144
|
-
// 监控 2.5 秒,如果闪退,直接打印错误
|
|
145
156
|
await new Promise(rs => setTimeout(rs, 2500));
|
|
146
157
|
|
|
147
158
|
if (tray.exitCode !== null) {
|