tt-help-cli-ycl 1.4.67 → 1.4.69
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/package.json +1 -1
- package/src/cli/auto.js +6 -1
- package/src/cli/explore.js +7 -1
- package/src/cli/refresh.js +7 -1
- package/src/watch/public/app.js +15 -1
- package/src/watchdog/process-manager.js +28 -14
package/package.json
CHANGED
package/src/cli/auto.js
CHANGED
|
@@ -5,7 +5,10 @@ import {
|
|
|
5
5
|
} from "../lib/browser/page.js";
|
|
6
6
|
import { userId as configuredUserId, saveUserId } from "../lib/constants.js";
|
|
7
7
|
import { getMacOrUuid } from "../lib/mac-or-uuid.js";
|
|
8
|
-
import {
|
|
8
|
+
import {
|
|
9
|
+
ensureBrowserReady as ensureBrowserReadyCDP,
|
|
10
|
+
killEdgeProcesses,
|
|
11
|
+
} from "../lib/browser/cdp.js";
|
|
9
12
|
import { createApiClient } from "../lib/api-client.js";
|
|
10
13
|
|
|
11
14
|
const MAX_RETRY_WAIT = 5 * 60 * 1000;
|
|
@@ -47,6 +50,8 @@ export async function handleAuto(options) {
|
|
|
47
50
|
if (shuttingDown) return;
|
|
48
51
|
shuttingDown = true;
|
|
49
52
|
console.error(`\n[Auto] 收到 ${signal},正在关闭浏览器...`);
|
|
53
|
+
// 先杀死 Edge 进程(CDP 模式下 browser.close() 只断开连接,不杀进程)
|
|
54
|
+
await killEdgeProcesses();
|
|
50
55
|
await browser?.close().catch(() => {});
|
|
51
56
|
console.error("[Auto] 已退出");
|
|
52
57
|
process.exit(0);
|
package/src/cli/explore.js
CHANGED
|
@@ -20,6 +20,7 @@ import {
|
|
|
20
20
|
import { getMacOrUuid } from "../lib/mac-or-uuid.js";
|
|
21
21
|
import {
|
|
22
22
|
ensureBrowserReady as ensureBrowserReadyCDP,
|
|
23
|
+
killEdgeProcesses,
|
|
23
24
|
switchAccount,
|
|
24
25
|
} from "../lib/browser/cdp.js";
|
|
25
26
|
import { showResourceUsage } from "../utils/index.js";
|
|
@@ -73,12 +74,17 @@ export async function handleExplore(options) {
|
|
|
73
74
|
|
|
74
75
|
let userId = exploreUserId || configuredUserId;
|
|
75
76
|
let browser = null;
|
|
77
|
+
let cdpOptions = null;
|
|
76
78
|
let shuttingDown = false;
|
|
77
79
|
|
|
78
80
|
const shutdown = async (signal) => {
|
|
79
81
|
if (shuttingDown) return;
|
|
80
82
|
shuttingDown = true;
|
|
81
83
|
console.error(`\n[Explore] 收到 ${signal},正在关闭浏览器...`);
|
|
84
|
+
// 先杀死 Edge 进程(CDP 模式下 browser.close() 只断开连接,不杀进程)
|
|
85
|
+
if (cdpOptions) {
|
|
86
|
+
await killEdgeProcesses(cdpOptions.userDataDir, cdpOptions.port);
|
|
87
|
+
}
|
|
82
88
|
await browser?.close().catch(() => {});
|
|
83
89
|
console.error("[Explore] 已退出");
|
|
84
90
|
process.exit(0);
|
|
@@ -117,7 +123,7 @@ export async function handleExplore(options) {
|
|
|
117
123
|
});
|
|
118
124
|
let currentAccount = healthChecker.getCurrentAccount();
|
|
119
125
|
|
|
120
|
-
|
|
126
|
+
cdpOptions = {};
|
|
121
127
|
if (explorePort) {
|
|
122
128
|
// 固定端口模式(调试用,关闭自动轮换)
|
|
123
129
|
cdpOptions.port = explorePort;
|
package/src/cli/refresh.js
CHANGED
|
@@ -20,6 +20,7 @@ import {
|
|
|
20
20
|
import { getMacOrUuid } from "../lib/mac-or-uuid.js";
|
|
21
21
|
import {
|
|
22
22
|
ensureBrowserReady as ensureBrowserReadyCDP,
|
|
23
|
+
killEdgeProcesses,
|
|
23
24
|
switchAccount,
|
|
24
25
|
} from "../lib/browser/cdp.js";
|
|
25
26
|
import { HealthChecker } from "../lib/browser/health-checker.js";
|
|
@@ -72,12 +73,17 @@ export async function handleRefresh(options) {
|
|
|
72
73
|
|
|
73
74
|
let userId = exploreUserId || configuredUserId;
|
|
74
75
|
let browser = null;
|
|
76
|
+
let cdpOptions = null;
|
|
75
77
|
let shuttingDown = false;
|
|
76
78
|
|
|
77
79
|
const shutdown = async (signal) => {
|
|
78
80
|
if (shuttingDown) return;
|
|
79
81
|
shuttingDown = true;
|
|
80
82
|
console.error(`\n[Refresh] 收到 ${signal},正在关闭浏览器...`);
|
|
83
|
+
// 先杀死 Edge 进程(CDP 模式下 browser.close() 只断开连接,不杀进程)
|
|
84
|
+
if (cdpOptions) {
|
|
85
|
+
await killEdgeProcesses(cdpOptions.userDataDir, cdpOptions.port);
|
|
86
|
+
}
|
|
81
87
|
await browser?.close().catch(() => {});
|
|
82
88
|
console.error("[Refresh] 已退出");
|
|
83
89
|
process.exit(0);
|
|
@@ -124,7 +130,7 @@ export async function handleRefresh(options) {
|
|
|
124
130
|
});
|
|
125
131
|
let currentAccount = healthChecker.getCurrentAccount();
|
|
126
132
|
|
|
127
|
-
|
|
133
|
+
cdpOptions = {};
|
|
128
134
|
if (explorePort) {
|
|
129
135
|
cdpOptions.port = explorePort;
|
|
130
136
|
cdpOptions.userDataDir = path.join(
|
package/src/watch/public/app.js
CHANGED
|
@@ -1344,6 +1344,11 @@ function showMainPage() {
|
|
|
1344
1344
|
document.getElementById("targetPage").classList.remove("active");
|
|
1345
1345
|
document.getElementById("tagsPage").classList.remove("active");
|
|
1346
1346
|
document.getElementById("settingsPage").classList.remove("active");
|
|
1347
|
+
document.getElementById("watchdogPage").classList.remove("active");
|
|
1348
|
+
if (_wdRefreshTimer) {
|
|
1349
|
+
clearInterval(_wdRefreshTimer);
|
|
1350
|
+
_wdRefreshTimer = null;
|
|
1351
|
+
}
|
|
1347
1352
|
}
|
|
1348
1353
|
|
|
1349
1354
|
function navigateToTarget() {
|
|
@@ -3816,7 +3821,7 @@ function renderCmdList(myCmds, userId) {
|
|
|
3816
3821
|
);
|
|
3817
3822
|
});
|
|
3818
3823
|
|
|
3819
|
-
return html
|
|
3824
|
+
return html;
|
|
3820
3825
|
}
|
|
3821
3826
|
|
|
3822
3827
|
// ── 命令管理操作 ──
|
|
@@ -3896,6 +3901,13 @@ function wdToggleClientCmd(userId, idx) {
|
|
|
3896
3901
|
} else {
|
|
3897
3902
|
cmd.enabled = !cmd.enabled;
|
|
3898
3903
|
}
|
|
3904
|
+
// 立即更新按钮为 loading 状态
|
|
3905
|
+
var btn = event.target;
|
|
3906
|
+
if (btn && btn.tagName === "BUTTON") {
|
|
3907
|
+
btn.textContent = "⏳";
|
|
3908
|
+
btn.style.pointerEvents = "none";
|
|
3909
|
+
btn.style.opacity = "0.5";
|
|
3910
|
+
}
|
|
3899
3911
|
wdSaveClientCmds(userId, myCmds);
|
|
3900
3912
|
}
|
|
3901
3913
|
|
|
@@ -3909,6 +3921,8 @@ async function wdSaveClientCmds(userId, commands) {
|
|
|
3909
3921
|
fetchWatchdogData();
|
|
3910
3922
|
} catch (e) {
|
|
3911
3923
|
alert("保存失败: " + e.message);
|
|
3924
|
+
// 失败时立即刷新恢复按钮状态
|
|
3925
|
+
fetchWatchdogData();
|
|
3912
3926
|
}
|
|
3913
3927
|
}
|
|
3914
3928
|
|
|
@@ -112,10 +112,17 @@ export class ProcessManager extends EventEmitter {
|
|
|
112
112
|
command = parts[0] || command;
|
|
113
113
|
args = parts.slice(1);
|
|
114
114
|
}
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
115
|
+
// Windows .cmd 文件必须 shell:true,macOS/Linux 直接 spawn
|
|
116
|
+
child = IS_WIN
|
|
117
|
+
? spawn(command, args, {
|
|
118
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
119
|
+
detached: false,
|
|
120
|
+
shell: true,
|
|
121
|
+
})
|
|
122
|
+
: spawn(command, args, {
|
|
123
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
124
|
+
detached: false,
|
|
125
|
+
});
|
|
119
126
|
} catch (e) {
|
|
120
127
|
console.error(`[watchdog] 启动命令 ${id} 失败: ${e.message}`);
|
|
121
128
|
this.processes.set(id, {
|
|
@@ -203,16 +210,23 @@ export class ProcessManager extends EventEmitter {
|
|
|
203
210
|
|
|
204
211
|
if (info.child) {
|
|
205
212
|
try {
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
213
|
+
if (IS_WIN) {
|
|
214
|
+
// Windows: shell:true 产生 cmd.exe 中间层,必须杀整个进程树
|
|
215
|
+
execSync(`taskkill /PID ${info.child.pid} /T /F`, {
|
|
216
|
+
stdio: ["ignore", "ignore", "ignore"],
|
|
217
|
+
timeout: 5000,
|
|
218
|
+
});
|
|
219
|
+
} else {
|
|
220
|
+
// macOS/Linux: 优雅终止,2 秒后强制 kill
|
|
221
|
+
info.child.kill("SIGTERM");
|
|
222
|
+
setTimeout(() => {
|
|
223
|
+
try {
|
|
224
|
+
if (info.child && info.child.exitCode === null) {
|
|
225
|
+
info.child.kill("SIGKILL");
|
|
226
|
+
}
|
|
227
|
+
} catch {}
|
|
228
|
+
}, 2000);
|
|
229
|
+
}
|
|
216
230
|
} catch (e) {
|
|
217
231
|
console.error(`[watchdog] 停止命令 ${cmdId} 失败: ${e.message}`);
|
|
218
232
|
}
|