dsh-napcat-keeper 2.8.1 → 2.8.2
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/CHANGELOG.md +9 -0
- package/README.md +15 -3
- package/lib/client.js +51 -7
- package/lib/index.js +68 -17
- package/package.json +4 -2
- package/scripts/selftest-layout.mjs +93 -0
- package/scripts/smoke-client.mjs +21 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 2.8.2 — 「进程」那行按安装形态说人话 + 清一处重复模板
|
|
4
|
+
- **修**:`进程 NapCatWinBootMain 0 | QQ 2 | 链 1` 这句在 node 型(无头 Shell)安装上等于在骗人 —— 那种装法里 QQ 本体跑在 `node.exe` 里,机器上既没有 `QQ.exe` 也没有快登壳,`procs.boot` 恒为 0。现在设置页按形态换词:node 型写 `主/工作进程 2(node) | 链 1`,boot 型写 `快登壳 1 | QQ 4 | 链 1`,老服务端没给 `layout` 时退回原来那三项。
|
|
5
|
+
- 新增 `procsLayout()`,判形态的顺序是「**先看谁在跑**(`boot>0` → boot 型,`qq>0` → node 型),都没在跑才看 Shell 目录」。目录那步只认**顶层** `node.exe` + `index.js`/`napcat.mjs` 或顶层 `NapCatWinBootMain.exe`,不再拿「目录里某处有这个 exe」当判据 —— OneKey 那套会把壳模板留在 `napcat/` 子目录里,node 型目录里也常带一份。
|
|
6
|
+
- 目录判形按目录名缓存 60 秒:面板轻量档 1.5 秒来问一次,不该每次都去 `readdir`。
|
|
7
|
+
- 「进程」那行加了悬浮解释(`title`),写清楚 0 不等于没进程;前端另外挡一道 —— 服务端还说 boot、可壳是 0 个而 node 进程 > 0 时,仍按 node 说,省得等 host 侧热重载。
|
|
8
|
+
- **清**:`taskCommandLine` 与 `taskCommandLinePure` 原先各自抄了一遍 `cmd.exe /c chcp 65001 … call … >> log` 的模板,现在共用 `taskCmdLineOf()`,两边不会再改一处漏一处(一条会落盘中间层 bat、一条不落盘的区别照旧)。
|
|
9
|
+
- `procsLayout(cfg, p)` 补上 `cfg` 为空时的兜底,不再 `Cannot read properties of null`。
|
|
10
|
+
- 测试:新增 `selftest:layout`(18 项:三种形态、进程优先于目录、只有子目录模板时仍判 unknown、目录不存在 / shellDir 未填 / cfg 为 null 不抛、60 秒缓存、任务命令行两条路一字不差);`smoke-client` 加 7 项「进程」行渲染断言(含「服务端还说是 boot 但壳是 0 个」那条);新增 `npm test` 一把跑完清单体检 + 隐私体检 + 全部自测。
|
|
11
|
+
|
|
3
12
|
## 2.8.1 — 认得出两个共存插件(dsh-onebot-qq 跟它的端口,dsh-qq-bridge 替它对端口)
|
|
4
13
|
- 2.8.0 解决了「反向 WS 下不再误判离线、不再无限重启」,但端口还是得你自己抄:`dsh-onebot-qq` 默认监听 `8643`,你 `onebotPort` 里填的却是 `3000`,那就一直「没客户端连进来」。
|
|
5
14
|
- 现在会读 `dsh-onebot-qq` 自己的配置:扫 `~/.dsh/profiles/*` 的 `package.json`(`dependencies` + `dsh.profile.bundles`)和 `cordis.patch.yml` / `cordis.yml` 里它那一段,得出「装没装 / 挂没挂 / 反向还是正向 / 监听哪个端口 / 有没有配令牌」。不认识 `!!js` 这类表达式,认不出的宁可当没配。
|
package/README.md
CHANGED
|
@@ -340,7 +340,7 @@ npm run check:privacy # 只查隐私(发版前必跑)
|
|
|
340
340
|
|
|
341
341
|
**隐私体检**是发版前那道闸:把包里所有文本文件过一遍,找 Windows / Unix 家目录路径、邮箱、`ghp_` / `npm_` / `sk-` / `AKIA` 这类凭证、`Bearer` 后面的真串、DSH 会话 id,以及自测里那种 `launchAccount: '1234567890'` 的真实 QQ 号。命中就按 `文件:行` 列出来并返回非 0;确实是文档里必须留的示例,在那行末尾写 `check-privacy:ignore` 放过。占位写法(`C:/Users/你/…`、`C:/Users/x/…`)本来就放行。
|
|
342
342
|
|
|
343
|
-
另外几个自测,都不依赖本机路径,clone 下来就能跑:`npm run smoke:client`(把 `lib/client.js` 塞进假 React 渲染一遍)、`npm run selftest:scan`(造假树验扫盘判定)、`npm run selftest:save`(保存真的落到插件目录、误写的那份被认领回来)、`npm run selftest:probe`(本地起假服务器,验普通 HTTP / 反向 WS / 需要鉴权 / 端口没开四种判定)、`npm run selftest:companion`(造假 profile 与桥接配置,验 `dsh-onebot-qq` 的端口跟随和 `dsh-qq-bridge` 的交叉结论)、`npm run selftest:setup`(临时目录里真跑一遍 apply / 重跑 / undo
|
|
343
|
+
另外几个自测,都不依赖本机路径,clone 下来就能跑:`npm run smoke:client`(把 `lib/client.js` 塞进假 React 渲染一遍)、`npm run selftest:scan`(造假树验扫盘判定)、`npm run selftest:save`(保存真的落到插件目录、误写的那份被认领回来)、`npm run selftest:probe`(本地起假服务器,验普通 HTTP / 反向 WS / 需要鉴权 / 端口没开四种判定)、`npm run selftest:companion`(造假 profile 与桥接配置,验 `dsh-onebot-qq` 的端口跟随和 `dsh-qq-bridge` 的交叉结论)、`npm run selftest:setup`(临时目录里真跑一遍 apply / 重跑 / undo)、`npm run selftest:layout`(验「进程」那行按安装形态换词、目录判形的 60 秒缓存,以及任务命令行两条路是否同一套模板)。懒得一个个点就 `npm test`:清单体检 + 隐私体检 + 上面全部自测,一串跑完,红的就停。
|
|
344
344
|
|
|
345
345
|
> **改这个插件的文件的规矩**:别用 `Get-Content` 读、`Set-Content -Encoding utf8` 写 —— PowerShell 5.1 会按 ANSI 读、再按 UTF-8 写,一趟往返中文全变乱码,BOM 还照写。用编辑器另存为「UTF-8 无 BOM」;非要脚本写,就走
|
|
346
346
|
> `[IO.File]::WriteAllText($path, $text, (New-Object System.Text.UTF8Encoding($false)))`。
|
|
@@ -350,6 +350,18 @@ npm run check:privacy # 只查隐私(发版前必跑)
|
|
|
350
350
|
**「离线」但进程明明还在?**
|
|
351
351
|
端口没通。看 `~/.dsh/dsh-napcat-keeper/launch.log`,多半是卡在扫码,或者 QQ 弹了验证窗。
|
|
352
352
|
|
|
353
|
+
**设置页「进程」那行写着 `快登壳 0`,是不是一个进程都没有?**
|
|
354
|
+
不是。那行按你的安装形态换词,鼠标停上去有解释:
|
|
355
|
+
|
|
356
|
+
| 形态 | 面板怎么写 | 意思 |
|
|
357
|
+
| --- | --- | --- |
|
|
358
|
+
| node 型(无头 Shell,目录顶层是 `node.exe` + `index.js` / `napcat.mjs`) | `主/工作进程 2(node) | 链 1` | QQ 本体跑在 node 进程里,机器上**没有** `QQ.exe`、也没有快登壳 |
|
|
359
|
+
| 注入 / 快登壳型(目录顶层有 `NapCatWinBootMain.exe`) | `快登壳 1 | QQ 4 | 链 1` | 快登壳进程数 + QQ 进程数 |
|
|
360
|
+
|
|
361
|
+
所以 node 型安装下快登壳恒为 0 是正常的,不等于没进程 —— 真进程数看「主/工作进程」后面那个数字。
|
|
362
|
+
判形态的顺序是:**先看谁在跑**(有快登壳进程算 boot 型,只有 node 进程算 node 型),
|
|
363
|
+
都没在跑才去看目录(这一步按目录名缓存 60 秒,不会每 1.5 秒去 `readdir` 一次)。
|
|
364
|
+
|
|
353
365
|
**刚关掉 DSH,QQ 就跟着退了?**
|
|
354
366
|
正常,默认就是这样:QQ 挂在 DSH 下面,DSH 一走它就走。下次开 DSH 会重新拉一条。
|
|
355
367
|
想反过来(DSH 关了 NapCat 还活着)去填「计划任务名」+ 勾「自动创建计划任务」。
|
|
@@ -403,13 +415,13 @@ DSH 自带的 pnpm 不捎带 git,Windows 上又默认没装,于是就卡在
|
|
|
403
415
|
| 填进去的 | 结果 |
|
|
404
416
|
| --- | --- |
|
|
405
417
|
| `dsh-napcat-keeper` | ✅ |
|
|
406
|
-
| `dsh-napcat-keeper@2.8.
|
|
418
|
+
| `dsh-napcat-keeper@2.8.2` | ✅(指定版本) |
|
|
407
419
|
| `dsh plugin --profile desktop add dsh-napcat-keeper` | ❌ 整条命令 |
|
|
408
420
|
| `add dsh-napcat-keeper` | ❌ 多了 `add` |
|
|
409
421
|
| `Dsh-napcat-keeper` | ❌ 大写 |
|
|
410
422
|
| `dsh-napcat-keeper。`、`dsh-napcat-keeper;` | ❌ 全角标点 |
|
|
411
423
|
|
|
412
|
-
改法就一句:**那一栏只填 `dsh-napcat-keeper`**(要指定版本就 `dsh-napcat-keeper@2.8.
|
|
424
|
+
改法就一句:**那一栏只填 `dsh-napcat-keeper`**(要指定版本就 `dsh-napcat-keeper@2.8.2`)。想跑命令行的话,得在终端里跑,
|
|
413
425
|
不是在输入框里跑。
|
|
414
426
|
|
|
415
427
|
## License
|
package/lib/client.js
CHANGED
|
@@ -206,6 +206,56 @@ window.__ModuleLoader__.load({
|
|
|
206
206
|
return 'dsh-qq-bridge ' + String(b.version) + ' · ' + 状态 + ' · ' + 开关 + ' · 连 ' + String(b.napcatUrl || '') + 问题
|
|
207
207
|
}
|
|
208
208
|
|
|
209
|
+
/**
|
|
210
|
+
* 实际在跑的形态优先于服务端声明的 layout:
|
|
211
|
+
* 声明是 boot、可快登壳进程 0 个而 node 进程 > 0 —— 那实际跑的就是 node 型,别按壳的说法写。
|
|
212
|
+
*/
|
|
213
|
+
function 实际形态(runtime) {
|
|
214
|
+
const p = runtime.procs || {}
|
|
215
|
+
if (runtime.layout === 'boot' && !Number(p.boot || 0) && Number(p.qq || 0) > 0) return 'node'
|
|
216
|
+
return runtime.layout
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
/**
|
|
220
|
+
* 「进程」那行的文案。按安装形态换词:
|
|
221
|
+
* - node 型(无头 Shell,napcat.mjs)没有快登壳,写「NapCatWinBootMain 0」会被当成没进程;
|
|
222
|
+
* - boot 型:快登壳 + QQ 个数都要看;
|
|
223
|
+
* - 老服务端没给 layout:退回原来的三项,别把面板搞宕。
|
|
224
|
+
*/
|
|
225
|
+
function 进程文案(runtime) {
|
|
226
|
+
const p = runtime.procs
|
|
227
|
+
if (!p || p.known === false) return '(还没探测)'
|
|
228
|
+
const 形态 = 实际形态(runtime)
|
|
229
|
+
const 链 = '链 ' + String(p.chains || 0) + (p.dup ? ' ⚠ 有重复链' : '')
|
|
230
|
+
if (形态 === 'node') {
|
|
231
|
+
return '主/工作进程 ' + String(p.qq || 0) + '(node)| ' + 链
|
|
232
|
+
}
|
|
233
|
+
if (形态 === 'boot') {
|
|
234
|
+
return '快登壳 ' + String(p.boot || 0) + ' | QQ ' + String(p.qq || 0) + ' | ' + 链
|
|
235
|
+
}
|
|
236
|
+
return 'NapCatWinBootMain ' + String(p.boot || 0) + ' | QQ ' + String(p.qq || 0) + ' | ' + 链
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
/** 上面那行的悬浮解释:为什么 0 不等于没进程 */
|
|
240
|
+
function 进程说明(runtime) {
|
|
241
|
+
const p = runtime.procs || {}
|
|
242
|
+
const 数 = String(p.qq || 0) + ' 个进程、' + String(p.chains || 0) + ' 条链'
|
|
243
|
+
const 形态 = 实际形态(runtime)
|
|
244
|
+
if (形态 === 'node') {
|
|
245
|
+
return (
|
|
246
|
+
'当前跑的是 node 型(无头 Shell):QQ 本体在 node.exe 里,机器上没有 QQ.exe、也没有快登壳进程。' +
|
|
247
|
+
'当前 ' + 数 + ';Shell 目录里就算躺着 NapCatWinBootMain.exe 也没在用,所以那一项恒为 0,属正常。'
|
|
248
|
+
)
|
|
249
|
+
}
|
|
250
|
+
if (形态 === 'boot') {
|
|
251
|
+
return (
|
|
252
|
+
'Shell 目录里有 NapCatWinBootMain.exe:快登壳 ' + String(p.boot || 0) +
|
|
253
|
+
' 个、QQ/node 进程 ' + String(p.qq || 0) + ' 个、' + String(p.chains || 0) + ' 条链。'
|
|
254
|
+
)
|
|
255
|
+
}
|
|
256
|
+
return '快登壳 ' + String(p.boot || 0) + ' 个、QQ/node 进程 ' + String(p.qq || 0) + ' 个、' + String(p.chains || 0) + ' 条链。'
|
|
257
|
+
}
|
|
258
|
+
|
|
209
259
|
function 状态条(runtime) {
|
|
210
260
|
if (!runtime) return null
|
|
211
261
|
const 在 = runtime.online
|
|
@@ -254,13 +304,7 @@ window.__ModuleLoader__.load({
|
|
|
254
304
|
),
|
|
255
305
|
h('div', { style: { ...S.kv, marginTop: 8 } },
|
|
256
306
|
h('span', { style: S.dim }, '进程'),
|
|
257
|
-
h('span',
|
|
258
|
-
runtime.procs && runtime.procs.known === false
|
|
259
|
-
? '(还没探测)'
|
|
260
|
-
: 'NapCatWinBootMain ' + String((runtime.procs && runtime.procs.boot) || 0) +
|
|
261
|
-
' | QQ ' + String((runtime.procs && runtime.procs.qq) || 0) +
|
|
262
|
-
' | 链 ' + String((runtime.procs && runtime.procs.chains) || 0) +
|
|
263
|
-
(runtime.procs && runtime.procs.dup ? ' ⚠ 有重复链' : '')),
|
|
307
|
+
h('span', { title: 进程说明(runtime) }, 进程文案(runtime)),
|
|
264
308
|
h('span', { style: S.dim }, '路径前缀'),
|
|
265
309
|
h('span', { style: { wordBreak: 'break-all' } }, String(runtime.procRoot || '(空)')),
|
|
266
310
|
h('span', { style: S.dim }, '启动脚本'),
|
package/lib/index.js
CHANGED
|
@@ -1,9 +1,18 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* dsh-napcat-keeper —— NapCat 看门狗 v2.8.
|
|
2
|
+
* dsh-napcat-keeper —— NapCat 看门狗 v2.8.2(可发布通用版)
|
|
3
3
|
*
|
|
4
4
|
* 解决的问题:DSH 是桌面应用,重启 DSH 时 NapCat(QQ 协议端) 不会跟着起来,
|
|
5
5
|
* 于是 dsh-qq-bridge 一直轮询一个死端口,你在 QQ 里说的话就石沉大海。
|
|
6
6
|
*
|
|
7
|
+
* v2.8.2:「进程」那行按安装形态说人话 + 清一处重复模板
|
|
8
|
+
* - node 型(无头 Shell)装法里 QQ 本体跑在 node.exe 里,机器上没有 QQ.exe 也没有快登壳,
|
|
9
|
+
* procs.boot 恒为 0 —— 老版设置页还照旧写「NapCatWinBootMain 0」等于骗人。新增
|
|
10
|
+
* procsLayout():先看谁在跑(boot>0 → boot 型,qq>0 → node 型),都没在跑才看 Shell
|
|
11
|
+
* 目录顶层(node.exe + index.js/napcat.mjs,或顶层 NapCatWinBootMain.exe);目录判形
|
|
12
|
+
* 按目录名缓存 60 秒,面板 1.5 秒问一次也不必每次 readdir;「进程」那行补 title 解释 0 的含义;
|
|
13
|
+
* - taskCommandLine 与 taskCommandLinePure 共用 taskCmdLineOf(),不再各抄一份模板;
|
|
14
|
+
* - 新增 selftest:layout(18 项)与 npm test(清单体检 + 隐私体检 + 全部自测一把跑完)。
|
|
15
|
+
*
|
|
7
16
|
* v2.8.1:认得出两个共存插件,端口不用自己抄
|
|
8
17
|
* - 读 dsh-onebot-qq 的配置(profile 的 package.json、cordis.patch.yml / cordis.yml),
|
|
9
18
|
* 得出「装没装 / 挂没挂 / 反向还是正向 / 监听哪个端口 / 令牌配没配」;
|
|
@@ -162,7 +171,7 @@ import { homedir, tmpdir } from 'node:os'
|
|
|
162
171
|
import path from 'node:path'
|
|
163
172
|
|
|
164
173
|
export const name = 'napcat-keeper'
|
|
165
|
-
export const version = '2.8.
|
|
174
|
+
export const version = '2.8.2'
|
|
166
175
|
|
|
167
176
|
/** tools 用来注册 napcat_* 工具;webServer 用来挂设置界面接口。拿不到也不至于把 DSH 拖崩。 */
|
|
168
177
|
export const inject = ['tools', 'webServer']
|
|
@@ -780,6 +789,12 @@ function psPath(value) {
|
|
|
780
789
|
return String(value || '').replace(/\//g, '\\')
|
|
781
790
|
}
|
|
782
791
|
|
|
792
|
+
/**
|
|
793
|
+
* 所有内联 PowerShell 脚本的公共前缀:把「不需要的错误」压成静默。
|
|
794
|
+
* 三处脚本(数端口客户端 / 进程快照 / 杀晚出现的链)都要它,别再各抄一遍。
|
|
795
|
+
*/
|
|
796
|
+
const PS_QUIET = "$ErrorActionPreference='SilentlyContinue';"
|
|
797
|
+
|
|
783
798
|
/** 进程路径前缀(原样,给 PowerShell 的 -like 用) */
|
|
784
799
|
function procRootRaw(cfg) {
|
|
785
800
|
const explicit = String(cfg.procPathMatch || '').trim()
|
|
@@ -1417,7 +1432,7 @@ async function portClients(cfg, port = 0, maxAgeMs = 5000) {
|
|
|
1417
1432
|
// 按 LocalPort 找会命中服务端那条 socket,而它的所有者是跑反向 WS 服务的进程(就是 DSH 自己),
|
|
1418
1433
|
// 把它排除掉就一条都数不到了 —— 这个坑第一版就踩了。
|
|
1419
1434
|
const script =
|
|
1420
|
-
|
|
1435
|
+
PS_QUIET +
|
|
1421
1436
|
`$c=@(Get-NetTCPConnection -State Established -RemotePort ${p} -ErrorAction SilentlyContinue | ` +
|
|
1422
1437
|
`Where-Object { [string]$_.OwningProcess -ne '${self}' });` +
|
|
1423
1438
|
`'CLIENTS=' + $c.Count + ' PIDS=' + (($c | Select-Object -ExpandProperty OwningProcess -Unique) -join ',')`
|
|
@@ -1624,7 +1639,7 @@ async function probe(cfg, options = {}) {
|
|
|
1624
1639
|
/* ------------------------------------------------------------------ */
|
|
1625
1640
|
|
|
1626
1641
|
const PS_PROCS =
|
|
1627
|
-
|
|
1642
|
+
PS_QUIET +
|
|
1628
1643
|
// node 也要算:无头版(Node 包)只有 node.exe 一条进程,没有 QQ.exe
|
|
1629
1644
|
"Get-Process QQ,NapCatWinBootMain,node | " +
|
|
1630
1645
|
'ForEach-Object { $p=$null; try { $p=$_.Path } catch {}; ' +
|
|
@@ -2141,17 +2156,21 @@ function removeEnvBat(cfg) {
|
|
|
2141
2156
|
} catch {}
|
|
2142
2157
|
}
|
|
2143
2158
|
|
|
2144
|
-
/**
|
|
2145
|
-
function
|
|
2146
|
-
// 记住密码时改走中间层(set 环境变量 → call 原脚本),其余情况原样直跑
|
|
2147
|
-
const viaEnv = passwordActive(cfg) ? writeEnvBat(cfg, bat) : ''
|
|
2148
|
-
const target = viaEnv || bat
|
|
2159
|
+
/** 命令行的公共模板:chcp 65001 + 切到 Shell 目录 + call 启动脚本,输出进 launcherLog */
|
|
2160
|
+
function taskCmdLineOf(cfg, target) {
|
|
2149
2161
|
return (
|
|
2150
2162
|
`cmd.exe /c chcp 65001 >nul & cd /d "${cfg.shellDir}" & call "${target}" ` +
|
|
2151
2163
|
`>> "${cfg.launcherLog}" 2>&1`
|
|
2152
2164
|
)
|
|
2153
2165
|
}
|
|
2154
2166
|
|
|
2167
|
+
/** 真正要跑的那条 cmd 命令 */
|
|
2168
|
+
function taskCommandLine(cfg, bat) {
|
|
2169
|
+
// 记住密码时改走中间层(set 环境变量 → call 原脚本),其余情况原样直跑
|
|
2170
|
+
const viaEnv = passwordActive(cfg) ? writeEnvBat(cfg, bat) : ''
|
|
2171
|
+
return taskCmdLineOf(cfg, viaEnv || bat)
|
|
2172
|
+
}
|
|
2173
|
+
|
|
2155
2174
|
/**
|
|
2156
2175
|
* 写一个 WScript 壳:sh.Run cmd, 0, False → 子进程以“隐藏窗口”启动,
|
|
2157
2176
|
* 桌面不会多出那个黑框(原来计划任务直接跑 cmd.exe 就会挂一个控制台窗口)。
|
|
@@ -2224,7 +2243,7 @@ function ensureTask(cfg) {
|
|
|
2224
2243
|
)
|
|
2225
2244
|
}
|
|
2226
2245
|
const ps =
|
|
2227
|
-
|
|
2246
|
+
PS_QUIET +
|
|
2228
2247
|
`$t=Get-ScheduledTask -TaskName '${cfg.taskName.replace(/'/g, "''")}';` +
|
|
2229
2248
|
`if($t){$s=$t.Settings;$s.ExecutionTimeLimit='PT0S';$s.DisallowStartIfOnBatteries=$false;` +
|
|
2230
2249
|
`$s.StopIfGoingOnBatteries=$false;Set-ScheduledTask -TaskName '${cfg.taskName.replace(/'/g, "''")}' -Settings $s | Out-Null}`
|
|
@@ -2374,6 +2393,37 @@ function cachedBootMain(cfg, maxAgeMs = 60000) {
|
|
|
2374
2393
|
return found
|
|
2375
2394
|
}
|
|
2376
2395
|
|
|
2396
|
+
/**
|
|
2397
|
+
* 「进程」那行该按哪种安装形态措辞:
|
|
2398
|
+
* - `boot`:目录里有 NapCatWinBootMain.exe(注入/快登壳型),进程表里有快登壳计数可看;
|
|
2399
|
+
* - `node`:无头 Shell(Node 包)安装,QQ 本体跑在 node.exe 里,既没有 QQ.exe 也没有快登壳,
|
|
2400
|
+
* `procs.boot` 恒为 0 —— 这时候还写「NapCatWinBootMain 0」只会让人以为没进程。
|
|
2401
|
+
*/
|
|
2402
|
+
function procsLayout(cfg, p) {
|
|
2403
|
+
const boot = Number(p && p.boot) || 0
|
|
2404
|
+
const qq = Number(p && p.qq) || 0
|
|
2405
|
+
// ① 谁在跑就按谁说话:有快登壳进程 → boot 型;只有 node 进程 → node 型
|
|
2406
|
+
if (boot > 0) return 'boot'
|
|
2407
|
+
if (qq > 0) return 'node'
|
|
2408
|
+
// ② 都没在跑(离线 / 待拉起):只能看 Shell 目录是哪种安装形态。
|
|
2409
|
+
// 注意:node 型目录里也常带一个 napcat/NapCatWinBootMain.exe 模板,不能拿「有这文件」当判据。
|
|
2410
|
+
// 这一步要 readdir,而面板每轮都来问一次(轻量档 1.5 秒一轮),所以按目录名缓存 60 秒。
|
|
2411
|
+
const dir = String((cfg && cfg.shellDir) || '')
|
|
2412
|
+
const now = Date.now()
|
|
2413
|
+
if (uiCache.layoutKey === dir && now - (uiCache.layoutAt || 0) < 60000) return uiCache.layout
|
|
2414
|
+
let value = 'unknown'
|
|
2415
|
+
try {
|
|
2416
|
+
const names = readdirSync(dir).map((n) => String(n).toLowerCase())
|
|
2417
|
+
const 有node壳 = names.includes('node.exe') && (names.includes('index.js') || names.includes('napcat.mjs'))
|
|
2418
|
+
if (有node壳) value = 'node'
|
|
2419
|
+
else if (names.includes('napcatwinbootmain.exe')) value = 'boot'
|
|
2420
|
+
} catch {}
|
|
2421
|
+
uiCache.layout = value
|
|
2422
|
+
uiCache.layoutKey = dir
|
|
2423
|
+
uiCache.layoutAt = now
|
|
2424
|
+
return value
|
|
2425
|
+
}
|
|
2426
|
+
|
|
2377
2427
|
/** 没有别的启动脚本时用的那个 bat:直接调 NapCatWinBootMain.exe */
|
|
2378
2428
|
function launcherBatLines(cfg, boot) {
|
|
2379
2429
|
const account = batValue(cfg.launchAccount)
|
|
@@ -2391,11 +2441,7 @@ function launcherBatLines(cfg, boot) {
|
|
|
2391
2441
|
|
|
2392
2442
|
/** 任务里那条命令(纯字符串版本:不写盘,供「脚本」复用 taskCommandLine 的规则) */
|
|
2393
2443
|
function taskCommandLinePure(cfg, bat) {
|
|
2394
|
-
|
|
2395
|
-
return (
|
|
2396
|
-
`cmd.exe /c chcp 65001 >nul & cd /d "${cfg.shellDir}" & call "${target}" ` +
|
|
2397
|
-
`>> "${cfg.launcherLog}" 2>&1`
|
|
2398
|
-
)
|
|
2444
|
+
return taskCmdLineOf(cfg, passwordActive(cfg) && bat ? envBatPath(cfg) : bat)
|
|
2399
2445
|
}
|
|
2400
2446
|
|
|
2401
2447
|
/** 给设置页看的清单:每个需要能不能做、要不要管理员 */
|
|
@@ -2907,7 +2953,7 @@ function openSetupFolder() {
|
|
|
2907
2953
|
/** 把已经在跑的 NapCat 控制台窗口藏起来(老链条留下的黑框也能收掉,不用重启 QQ) */
|
|
2908
2954
|
function hideConsoleWindows(cfg) {
|
|
2909
2955
|
const ps = [
|
|
2910
|
-
|
|
2956
|
+
PS_QUIET,
|
|
2911
2957
|
"Add-Type -Namespace K -Name U -MemberDefinition '",
|
|
2912
2958
|
'[DllImport("user32.dll")] public static extern bool ShowWindow(IntPtr h, int n);',
|
|
2913
2959
|
'[DllImport("user32.dll")] public static extern bool IsWindowVisible(IntPtr h);',
|
|
@@ -3042,7 +3088,7 @@ async function killNewerChains(cfg, oldestLastMs) {
|
|
|
3042
3088
|
}
|
|
3043
3089
|
const root = psPath(base).replace(/'/g, "''")
|
|
3044
3090
|
const script =
|
|
3045
|
-
|
|
3091
|
+
PS_QUIET +
|
|
3046
3092
|
`$cut=([datetime]'1970-01-01').AddMilliseconds(${Math.round(oldestLastMs)});` +
|
|
3047
3093
|
'Get-Process QQ,NapCatWinBootMain,node | ' +
|
|
3048
3094
|
`Where-Object { $_.Path -like '${root}*' -and $_.StartTime -gt $cut } | ` +
|
|
@@ -3963,6 +4009,8 @@ async function uiState(cfg, options = {}) {
|
|
|
3963
4009
|
lastOnlineAt: state.lastOnlineAt ? new Date(state.lastOnlineAt).toISOString() : '',
|
|
3964
4010
|
lastProbeAt: state.lastProbeAt || '',
|
|
3965
4011
|
procs: { boot: p.boot, qq: p.qq, chains: p.chains, dup: p.dup, known },
|
|
4012
|
+
/** node / boot / unknown —— 设置页「进程」那行的措辞跟着它变(boot 恒 0 不代表没进程) */
|
|
4013
|
+
layout: procsLayout(cfg, p),
|
|
3966
4014
|
qr: qr,
|
|
3967
4015
|
bridge: bridge,
|
|
3968
4016
|
procRoot: light ? '' : procRootRaw(cfg),
|
|
@@ -4407,5 +4455,8 @@ export const __internals = {
|
|
|
4407
4455
|
applyPs1Source,
|
|
4408
4456
|
dirWritable,
|
|
4409
4457
|
cachedBootMain,
|
|
4458
|
+
procsLayout,
|
|
4459
|
+
taskCommandLine,
|
|
4460
|
+
taskCommandLinePure,
|
|
4410
4461
|
state,
|
|
4411
4462
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-napcat-keeper",
|
|
3
|
-
"version": "2.8.
|
|
3
|
+
"version": "2.8.2",
|
|
4
4
|
"description": "发现没有能够随着dsh打开自动启动napcat的插件,遂使用大肥鱼制作此插件,建议搭配Yuuyuko-uu的dsh-qq-bridge使用~",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "lib/index.js",
|
|
@@ -27,7 +27,9 @@
|
|
|
27
27
|
"selftest:save": "node scripts/selftest-save.mjs",
|
|
28
28
|
"selftest:probe": "node scripts/selftest-probe.mjs",
|
|
29
29
|
"selftest:companion": "node scripts/selftest-companion.mjs",
|
|
30
|
-
"selftest:setup": "node scripts/selftest-setup.mjs"
|
|
30
|
+
"selftest:setup": "node scripts/selftest-setup.mjs",
|
|
31
|
+
"selftest:layout": "node scripts/selftest-layout.mjs",
|
|
32
|
+
"test": "node scripts/check-manifest.mjs && node scripts/check-privacy.mjs && node scripts/smoke-client.mjs && node scripts/selftest-scan.mjs && node scripts/selftest-save.mjs && node scripts/selftest-probe.mjs && node scripts/selftest-companion.mjs && node scripts/selftest-setup.mjs && node scripts/selftest-layout.mjs"
|
|
31
33
|
},
|
|
32
34
|
"keywords": [
|
|
33
35
|
"deepseek-harness",
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 「进程」那行按安装形态换词的回归自检。
|
|
3
|
+
*
|
|
4
|
+
* 守的坑:node 型(无头 Shell / napcat.mjs 包)安装下根本没有快登壳进程,
|
|
5
|
+
* `procs.boot` 恒为 0,老版本一律写「NapCatWinBootMain 0 | QQ 2 | 链 1」——
|
|
6
|
+
* 看着像「一个进程都没有」,其实 QQ 好好跑在 node.exe 里。
|
|
7
|
+
* 现在 procsLayout() 分三种:node / boot / unknown,设置页照它换词。
|
|
8
|
+
*
|
|
9
|
+
* 顺带守两件事:
|
|
10
|
+
* - 判形态先看「谁在跑」,进程表说话优先于目录形态;目录形态只作兜底;
|
|
11
|
+
* - 目录判形有 60 秒缓存(面板 1.5 秒一轮,别每次都 readdir);
|
|
12
|
+
* - taskCommandLine / taskCommandLinePure 共用同一条模板(改一处两边一起对)。
|
|
13
|
+
*
|
|
14
|
+
* 全程只用临时目录,不碰真配置、不碰真 NapCat。
|
|
15
|
+
* node scripts/selftest-layout.mjs
|
|
16
|
+
*/
|
|
17
|
+
import { mkdtempSync, mkdirSync, writeFileSync, existsSync, rmSync } from 'node:fs'
|
|
18
|
+
import { tmpdir } from 'node:os'
|
|
19
|
+
import path from 'node:path'
|
|
20
|
+
|
|
21
|
+
let pass = 0
|
|
22
|
+
let fail = 0
|
|
23
|
+
const ok = (cond, name, extra = '') => {
|
|
24
|
+
if (cond) {
|
|
25
|
+
pass += 1
|
|
26
|
+
console.log(` ✓ ${name}`)
|
|
27
|
+
} else {
|
|
28
|
+
fail += 1
|
|
29
|
+
console.log(` ✗ ${name}${extra ? ' — ' + extra : ''}`)
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const root = mkdtempSync(path.join(tmpdir(), 'npk-layout-'))
|
|
34
|
+
// 插件自己的家也跟着搬到临时目录:免得自检往真 keeper 目录里写 env.bat
|
|
35
|
+
process.env.DSH_HOME = root
|
|
36
|
+
|
|
37
|
+
const mk = (name, files) => {
|
|
38
|
+
const dir = path.join(root, name)
|
|
39
|
+
mkdirSync(dir, { recursive: true })
|
|
40
|
+
for (const f of files) {
|
|
41
|
+
const full = path.join(dir, f)
|
|
42
|
+
mkdirSync(path.dirname(full), { recursive: true })
|
|
43
|
+
writeFileSync(full, '')
|
|
44
|
+
}
|
|
45
|
+
return dir
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const nodeDir = mk('node-shell', ['node.exe', 'index.js', 'napcat.bat', 'napcat/napcat.mjs'])
|
|
49
|
+
const bootDir = mk('boot-shell', ['NapCatWinBootMain.exe', 'napcat.quick.bat'])
|
|
50
|
+
const emptyDir = mk('empty', [])
|
|
51
|
+
// 真机上的坑:node 型目录里也躺着这个模板,但它没被调用
|
|
52
|
+
const nestedDir = mk('nested-template', ['napcat/NapCatWinBootMain.exe', 'index.js'])
|
|
53
|
+
const missingDir = path.join(root, 'does-not-exist')
|
|
54
|
+
|
|
55
|
+
const { procsLayout, taskCommandLine, taskCommandLinePure } = (await import('../lib/index.js?t=' + Date.now())).__internals
|
|
56
|
+
|
|
57
|
+
console.log('1) 有进程在跑:按「谁在跑」说话')
|
|
58
|
+
ok(procsLayout({ shellDir: nodeDir }, { boot: 1, qq: 4 }) === 'boot', 'boot=1 → boot(壳在跑)')
|
|
59
|
+
ok(procsLayout({ shellDir: bootDir }, { boot: 0, qq: 3 }) === 'node', 'boot=0、qq=3 → node(node 在跑)')
|
|
60
|
+
ok(procsLayout({ shellDir: missingDir }, { boot: 0, qq: 2 }) === 'node', '进程在跑时目录不存在也照样判 node')
|
|
61
|
+
|
|
62
|
+
console.log('2) 都没在跑:只能看 Shell 目录形态')
|
|
63
|
+
ok(procsLayout({ shellDir: nodeDir }, { boot: 0, qq: 0 }) === 'node', 'node.exe + index.js → node')
|
|
64
|
+
ok(procsLayout({ shellDir: bootDir }, { boot: 0, qq: 0 }) === 'boot', '顶层有 NapCatWinBootMain.exe → boot')
|
|
65
|
+
ok(procsLayout({ shellDir: emptyDir }, { boot: 0, qq: 0 }) === 'unknown', '空目录 → unknown')
|
|
66
|
+
ok(procsLayout({ shellDir: nestedDir }, { boot: 0, qq: 0 }) === 'unknown', '只有 napcat/ 子目录里的模板 → unknown(不当判据)')
|
|
67
|
+
ok(procsLayout({}, { boot: 0, qq: 0 }) === 'unknown', 'shellDir 没填 → unknown')
|
|
68
|
+
ok(procsLayout({ shellDir: missingDir }, { boot: 0, qq: 0 }) === 'unknown', '目录不存在 → unknown(不抛)')
|
|
69
|
+
ok(procsLayout(null, { boot: 0, qq: 0 }) === 'unknown', 'cfg 为 null 也不抛')
|
|
70
|
+
|
|
71
|
+
console.log('3) 目录判形有 60 秒缓存')
|
|
72
|
+
const cacheDir = mk('cache', [])
|
|
73
|
+
ok(procsLayout({ shellDir: cacheDir }, { boot: 0, qq: 0 }) === 'unknown', '第一次:空目录 → unknown')
|
|
74
|
+
writeFileSync(path.join(cacheDir, 'node.exe'), '')
|
|
75
|
+
writeFileSync(path.join(cacheDir, 'napcat.mjs'), '')
|
|
76
|
+
ok(procsLayout({ shellDir: cacheDir }, { boot: 0, qq: 0 }) === 'unknown', '刚放进去的 node.exe 还没到 60 秒 → 仍返回缓存里的 unknown')
|
|
77
|
+
ok(procsLayout({ shellDir: cacheDir + path.sep }, { boot: 0, qq: 0 }) === 'node', '目录名变了(换个 key)→ 立刻重新判成 node')
|
|
78
|
+
|
|
79
|
+
console.log('4) 任务命令行:两条路共用一条模板')
|
|
80
|
+
const plain = { shellDir: 'C:\\napcat', launcherLog: path.join(root, 'launch.log'), launchArgs: '' }
|
|
81
|
+
ok(taskCommandLine(plain, 'C:\\napcat\\napcat.quick.bat') === taskCommandLinePure(plain, 'C:\\napcat\\napcat.quick.bat'), '没开记住密码时两者一字不差')
|
|
82
|
+
ok(taskCommandLine(plain, 'b.bat').includes('chcp 65001') && taskCommandLine(plain, 'b.bat').includes('cd /d "C:\\napcat"'), '模板含 chcp 与切目录')
|
|
83
|
+
const secret = { ...plain, rememberPassword: true, quickPassword: 'p@ss', launchAccount: '10001' }
|
|
84
|
+
const viaEnv = taskCommandLinePure(secret, 'C:\\napcat\\napcat.quick.bat')
|
|
85
|
+
ok(viaEnv.includes('env.bat'), '开了记住密码 → 走中间层 env.bat')
|
|
86
|
+
const withWrite = taskCommandLine(secret, 'C:\\napcat\\napcat.quick.bat')
|
|
87
|
+
ok(withWrite === viaEnv, 'writeEnvBat 那版落盘后与纯字符串版一致')
|
|
88
|
+
ok(existsSync(path.join(root, 'env.bat')), '中间层 bat 真写到 launcherLog 旁边了')
|
|
89
|
+
|
|
90
|
+
rmSync(root, { recursive: true, force: true })
|
|
91
|
+
console.log('')
|
|
92
|
+
console.log(`结果:${pass} 通过,${fail} 失败`)
|
|
93
|
+
process.exit(fail ? 1 : 0)
|
package/scripts/smoke-client.mjs
CHANGED
|
@@ -288,4 +288,25 @@ const noSetup = collect(render());
|
|
|
288
288
|
check('缺 setup 字段时降级提示', noSetup.text.includes('读不到脚本状态'));
|
|
289
289
|
states[0].setup = keepSetup;
|
|
290
290
|
|
|
291
|
+
// 「进程」那行:按安装形态换词(boot 恒 0 不代表没进程)
|
|
292
|
+
const keepRuntime = states[0].runtime;
|
|
293
|
+
const 进程行 = (runtimePatch) => {
|
|
294
|
+
states[0].runtime = { ...keepRuntime, ...runtimePatch };
|
|
295
|
+
return collect(render()).text;
|
|
296
|
+
};
|
|
297
|
+
const nodeText = 进程行({ layout: 'node', procs: { boot: 0, qq: 2, chains: 1, dup: false, known: true } });
|
|
298
|
+
check('node 型写「主/工作进程 2(node)」而不是 NapCatWinBootMain 0', nodeText.includes('主/工作进程 2(node)'), nodeText.slice(0, 80));
|
|
299
|
+
check('node 型不再出现「NapCatWinBootMain 0」这种说法', !nodeText.includes('NapCatWinBootMain 0'), nodeText.slice(0, 80));
|
|
300
|
+
const bootText = 进程行({ layout: 'boot', procs: { boot: 1, qq: 4, chains: 1, dup: false, known: true } });
|
|
301
|
+
check('boot 型写「快登壳 1 | QQ 4」', bootText.includes('快登壳 1 | QQ 4 | 链 1'), bootText.slice(0, 80));
|
|
302
|
+
const legacyText = 进程行({ layout: undefined, procs: { boot: 0, qq: 2, chains: 1, dup: false, known: true } });
|
|
303
|
+
check('老服务端没给 layout → 退回原来三项', legacyText.includes('NapCatWinBootMain 0 | QQ 2 | 链 1'), legacyText.slice(0, 80));
|
|
304
|
+
const lyingText = 进程行({ layout: 'boot', procs: { boot: 0, qq: 2, chains: 1, dup: false, known: true } });
|
|
305
|
+
check('服务端还说是 boot、可壳是 0 个 → 按实际在跑的 node 说', lyingText.includes('主/工作进程 2(node)'), lyingText.slice(0, 80));
|
|
306
|
+
const unknownText = 进程行({ layout: 'node', procs: { boot: 0, qq: 0, chains: 0, dup: false, known: false } });
|
|
307
|
+
check('还没探测时说「(还没探测)」', unknownText.includes('(还没探测)'), unknownText.slice(0, 80));
|
|
308
|
+
const dupText = 进程行({ layout: 'node', procs: { boot: 0, qq: 2, chains: 2, dup: true, known: true } });
|
|
309
|
+
check('有重复链要标出来', dupText.includes('⚠ 有重复链'), dupText.slice(0, 80));
|
|
310
|
+
states[0].runtime = keepRuntime;
|
|
311
|
+
|
|
291
312
|
process.exit(bad ? 1 : 0);
|