panrouter 3.2.0 → 3.3.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.
Files changed (2) hide show
  1. package/cli.mjs +21 -8
  2. package/package.json +1 -1
package/cli.mjs CHANGED
@@ -91,7 +91,6 @@ async function startTray() {
91
91
  const psPath = path.join(__dirname, "tray-daemon.ps1");
92
92
  log("..", "正在后台启动代理...", "yellow");
93
93
 
94
- // 1. 由主程序直接启动 Node 代理,彻底杜绝 PowerShell 启动慢导致的超时
95
94
  try {
96
95
  if (process.platform === "win32") {
97
96
  execSync('taskkill /f /fi "WINDOWTITLE eq Pan Router*" >nul 2>&1', { stdio: "pipe" });
@@ -106,7 +105,6 @@ async function startTray() {
106
105
  });
107
106
  srv.unref();
108
107
 
109
- // 2. 验证端口(由于是直接用 Node 启动,这步通常 1 秒内就会通过)
110
108
  let ok = false;
111
109
  for (let i = 0; i < 15; i++) {
112
110
  if (await isPortOpen()) {
@@ -122,23 +120,38 @@ async function startTray() {
122
120
  log("!!", "服务启动超时,但仍将尝试加载托盘", "red");
123
121
  }
124
122
 
125
- // 3. 独立拉起系统托盘
126
123
  log("..", "正在加载系统托盘...", "yellow");
124
+
125
+ // 【核心修复】:增加 -STA 参数防止 UI 线程崩溃,增加 shell:true 确保一定能找到 powershell
127
126
  const tray = spawn("powershell.exe", [
128
127
  "-NoProfile",
128
+ "-STA",
129
129
  "-ExecutionPolicy", "Bypass",
130
130
  "-WindowStyle", "Hidden",
131
- "-File", psPath
131
+ "-File", `"${psPath}"`
132
132
  ], {
133
133
  cwd: __dirname,
134
- stdio: "ignore",
134
+ stdio: ['ignore', 'pipe', 'pipe'],
135
135
  windowsHide: true,
136
- detached: true,
136
+ shell: true,
137
137
  env: { ...process.env, PANROUTER_NODE: process.execPath }
138
138
  });
139
- tray.unref();
140
139
 
141
- console.log(" API 代理已立即可用。托盘图标稍后将在右下角显示。");
140
+ let psOutput = "";
141
+ tray.stdout.on("data", d => psOutput += d.toString());
142
+ tray.stderr.on("data", d => psOutput += d.toString());
143
+
144
+ // 监控 2.5 秒,如果闪退,直接打印错误
145
+ await new Promise(rs => setTimeout(rs, 2500));
146
+
147
+ if (tray.exitCode !== null) {
148
+ log("!!", "托盘进程未能驻留,发生闪退!", "red");
149
+ console.log(`\n\x1b[31m=== PowerShell 启动失败原因 ===\x1b[0m\n${psOutput || "(无报错输出,可能是被杀毒软件静默拦截)"}\n\x1b[31m===============================\x1b[0m\n`);
150
+ console.log("提示:如果代理可用,你可以暂时无视此错误。");
151
+ } else {
152
+ tray.unref();
153
+ console.log(" 托盘图标应该已在右下角显示。");
154
+ }
142
155
  }
143
156
 
144
157
  async function main() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "panrouter",
3
- "version": "3.2.0",
3
+ "version": "3.3.0",
4
4
  "description": "让 Claude Code 免费使用 DeepSeek 等模型,无需 API Key",
5
5
  "type": "module",
6
6
  "bin": {