yingclaw 2.5.12 → 2.5.13
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/lib/autostart.js +24 -2
- package/lib/desktop.js +19 -3
- package/package.json +1 -1
package/lib/autostart.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
const fs = require('fs');
|
|
2
2
|
const os = require('os');
|
|
3
3
|
const path = require('path');
|
|
4
|
-
const { spawnSync } = require('child_process');
|
|
4
|
+
const { spawn, spawnSync } = require('child_process');
|
|
5
5
|
|
|
6
6
|
const GATEWAY_LAUNCH_AGENT_LABEL = 'com.yingclaw.gateway';
|
|
7
7
|
const WINDOWS_GATEWAY_STARTUP_SCRIPT = 'yingclaw-gateway.cmd';
|
|
@@ -74,6 +74,21 @@ function buildWindowsGatewayStartupScript(options = {}) {
|
|
|
74
74
|
].join('\r\n');
|
|
75
75
|
}
|
|
76
76
|
|
|
77
|
+
function startWindowsGateway(options = {}) {
|
|
78
|
+
const starter = options.starter || spawn;
|
|
79
|
+
const nodePath = options.nodePath || process.execPath;
|
|
80
|
+
const cliPath = options.cliPath || path.join(__dirname, '..', 'bin', 'cli.js');
|
|
81
|
+
const workingDirectory = options.workingDirectory || path.join(__dirname, '..');
|
|
82
|
+
const child = starter(nodePath, [cliPath, 'gateway'], {
|
|
83
|
+
cwd: workingDirectory,
|
|
84
|
+
detached: true,
|
|
85
|
+
stdio: 'ignore',
|
|
86
|
+
windowsHide: true,
|
|
87
|
+
});
|
|
88
|
+
if (child && typeof child.unref === 'function') child.unref();
|
|
89
|
+
return true;
|
|
90
|
+
}
|
|
91
|
+
|
|
77
92
|
function runLaunchctl(runner, args, options = {}) {
|
|
78
93
|
const result = runner('launchctl', args, { encoding: 'utf8', stdio: 'pipe' });
|
|
79
94
|
if (result.status !== 0 && !options.optional) {
|
|
@@ -125,9 +140,15 @@ function installGatewayAutostart(options = {}) {
|
|
|
125
140
|
const platform = options.platform || process.platform;
|
|
126
141
|
if (platform === 'win32') {
|
|
127
142
|
const file = options.file || getWindowsStartupScriptPath(options);
|
|
143
|
+
const runner = options.runner || spawnSync;
|
|
144
|
+
const port = options.port || 18080;
|
|
145
|
+
const wasRunning = isWindowsPortListening(runner, port);
|
|
128
146
|
fs.mkdirSync(path.dirname(file), { recursive: true });
|
|
129
147
|
fs.writeFileSync(file, buildWindowsGatewayStartupScript(options), 'utf8');
|
|
130
|
-
|
|
148
|
+
const started = !wasRunning && options.startNow !== false
|
|
149
|
+
? startWindowsGateway(options)
|
|
150
|
+
: false;
|
|
151
|
+
return { result: 'installed', file, started };
|
|
131
152
|
}
|
|
132
153
|
|
|
133
154
|
if (platform !== 'darwin') {
|
|
@@ -211,6 +232,7 @@ module.exports = {
|
|
|
211
232
|
GATEWAY_LAUNCH_AGENT_LABEL,
|
|
212
233
|
buildMacLaunchAgentPlist,
|
|
213
234
|
buildWindowsGatewayStartupScript,
|
|
235
|
+
startWindowsGateway,
|
|
214
236
|
getGatewayAutostartStatus,
|
|
215
237
|
getMacLaunchAgentPath,
|
|
216
238
|
getWindowsStartupScriptPath,
|
package/lib/desktop.js
CHANGED
|
@@ -363,11 +363,27 @@ function buildClaudeDesktopOpenCommands(platform = process.platform, options = {
|
|
|
363
363
|
const localAppData = options.localAppData
|
|
364
364
|
|| process.env.LOCALAPPDATA
|
|
365
365
|
|| `${options.homeDir || os.homedir()}\\AppData\\Local`;
|
|
366
|
-
const
|
|
367
|
-
|
|
366
|
+
const fileExists = options.fileExists || fs.existsSync;
|
|
367
|
+
const exeCandidates = [
|
|
368
|
+
`${localAppData}\\Programs\\Claude\\Claude.exe`,
|
|
369
|
+
`${localAppData}\\AnthropicClaude\\Claude.exe`,
|
|
370
|
+
];
|
|
371
|
+
const updateCandidates = [
|
|
372
|
+
`${localAppData}\\AnthropicClaude\\Update.exe`,
|
|
373
|
+
`${localAppData}\\Programs\\Claude\\Update.exe`,
|
|
374
|
+
];
|
|
375
|
+
const foundExe = exeCandidates.find((file) => fileExists(file));
|
|
376
|
+
const foundUpdate = foundExe ? null : updateCandidates.find((file) => fileExists(file));
|
|
377
|
+
const fallbackDir = `${localAppData}\\AnthropicClaude`;
|
|
378
|
+
const launchCommand = foundExe
|
|
379
|
+
? { command: 'cmd', args: ['/c', 'start', '', '/D', path.win32.dirname(foundExe), 'Claude.exe'], optional: true, waitAfter: 800 }
|
|
380
|
+
: foundUpdate
|
|
381
|
+
? { command: foundUpdate, args: ['--processStart', 'Claude.exe'], optional: true, waitAfter: 800 }
|
|
382
|
+
: { command: 'cmd', args: ['/c', 'start', '', '/D', fallbackDir, 'Claude.exe'], optional: true, waitAfter: 800 };
|
|
383
|
+
// taskkill /T 连带杀子进程;启动路径按实际安装位置选择,找不到时保留旧的 Squirrel 目录兜底
|
|
368
384
|
return [
|
|
369
385
|
{ command: 'taskkill', args: ['/IM', 'Claude.exe', '/F', '/T'], optional: true, waitAfter: 1500 },
|
|
370
|
-
|
|
386
|
+
launchCommand,
|
|
371
387
|
];
|
|
372
388
|
}
|
|
373
389
|
|