dsh-crossterm 0.8.14 → 0.9.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/CHANGELOG.md +32 -0
- package/MAINTAINERS.md +18 -0
- package/README.md +20 -19
- package/client/client.js +38 -5
- package/cordis.patch.yml +9 -1
- package/lib/bus.js +1 -1
- package/lib/index.js +48 -1
- package/lib/restart/core.js +524 -0
- package/lib/restart/runtime.js +65 -0
- package/lib/restart/scripts/busy-check.mjs +193 -0
- package/lib/restart/scripts/countdown.html +427 -0
- package/lib/restart/scripts/dsh-restart-helper.mjs +299 -0
- package/lib/restart/scripts/get-geom.ps1 +23 -0
- package/lib/restart/scripts/rearm-watch.mjs +76 -0
- package/lib/restart/scripts/run-helper.cmd +13 -0
- package/lib/restart/scripts/topmost.ps1 +133 -0
- package/lib/restart/scripts/trigger-restart.mjs +186 -0
- package/lib/web.js +3 -1
- package/package.json +4 -2
- package/parts/restart.manifest.json +4 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,37 @@
|
|
|
1
1
|
# dsh-crossterm 变更记录
|
|
2
2
|
|
|
3
|
+
## 0.9.0 — 2026-10-20
|
|
4
|
+
|
|
5
|
+
**自动重启并进互通插件(插件页第 6 个组件)**
|
|
6
|
+
|
|
7
|
+
User said (m12143):“将自动重启插件变成组件融合到互通插件内,任命原会话继续负责自动重启模块,
|
|
8
|
+
不再单独发版也不负责发版,每次修改更新后向你汇报,由你上传插件新版本”
|
|
9
|
+
|
|
10
|
+
- 原 `dsh-restart` 插件(包名 `dsh-restart-module` 0.3.28)代码并入 `lib/restart/`:`core.js`(`dsh_restart` 全套动作)
|
|
11
|
+
+ `scripts/`(`trigger-restart.mjs` / `dsh-restart-helper.mjs` / `busy-check.mjs` / `rearm-watch.mjs` / UI 页面等 8 个)
|
|
12
|
+
+ `runtime.js`(`ensureRestartRuntime()` 按版本把脚本同步到运行目录)。
|
|
13
|
+
- 新组件 `parts/restart`(插件页显示「自动重启」):`cordis.patch.yml` 第 6 行 insert、`config.part: restart`;
|
|
14
|
+
它不参与总线,只把 `dsh_restart` 工具挂到每个会话上。
|
|
15
|
+
- 运行目录:`<busDir>/restart-module/`(默认 `C:\Users\<你>\.dsh\crossterm\restart-module`),
|
|
16
|
+
启动时按版本同步脚本;`logs/`、`request.json`、`result.json` 一律不动,重启记录不会因为升级丢失。
|
|
17
|
+
- 旧插件 `dsh-restart-module` 若还装着,会与本组件重复注册 `dsh_restart`,需在 profile 里摘掉。
|
|
18
|
+
- 负责人:自动重启模块由原 `dsh-restart` 会话(`a3e9f80e`,会话名「自动重启」)继续维护,不单独发版;
|
|
19
|
+
改动汇报给插件主维护会话,由主维护会话并入 `dsh-crossterm` 一起发版。
|
|
20
|
+
## 0.8.15 — 2026-10-20
|
|
21
|
+
|
|
22
|
+
**为什么发这版**:YOCE_C 从 0.8.13 点更新到 0.8.14 后回归发现,没重启前 `/status` 仍只有 `version=0.8.13`、
|
|
23
|
+
`/check` 也继续报有更新 —— 因为 `installed` / `needRestart` 是 0.8.14 的**服务端**代码才加的,
|
|
24
|
+
当前进程还跑着 0.8.13,升级当次天然读不到。结论:待重启的提示不能只靠服务端新字段。
|
|
25
|
+
|
|
26
|
+
- **client 自带版本号**:`client/client.js` 顶部新增 `const CLIENT_VERSION = "0.8.15"`,随包发布,等于磁盘上的版本。
|
|
27
|
+
- **点完更新立刻提示**:`onUpdate` 从 `/update` 响应取 `installed` 与 `before`(0.8.13 起响应里本来就有 `needRestart`),
|
|
28
|
+
装成了就 `setRestartPending(true)`,不依赖服务端 `status.needRestart`。
|
|
29
|
+
- **持续推导**:渲染处按「磁盘版本 > 进程版本」判断,`needRestart = status.needRestart || restartPending || onDiskNewer`,
|
|
30
|
+
旧进程也提示得出来;「待重启」行的版本号缺失时用 `CLIENT_VERSION` 兜底。
|
|
31
|
+
- **`/check` 并列返回 `running`**(= 进程版本,与 `current` 同值),旧客户端也能照常解析。
|
|
32
|
+
|
|
33
|
+
回归:`probe-0815.mjs` 19 项。
|
|
34
|
+
|
|
3
35
|
## 0.8.14 — 2026-10-20
|
|
4
36
|
|
|
5
37
|
### 修「更新按钮看起来没用」(YOCE_C 实测反馈)
|
package/MAINTAINERS.md
CHANGED
|
@@ -26,6 +26,17 @@
|
|
|
26
26
|
"since": "2026-10-18T00:00:00+08:00",
|
|
27
27
|
"scope": "按负责人派活改 lib/*.js;不得改版本号、总线状态、重启、C 盘写入、AGENTS.md"
|
|
28
28
|
},
|
|
29
|
+
"modules": {
|
|
30
|
+
"restart": {
|
|
31
|
+
"session": "session-a3e9f80e-6f28-425c-9807-0b9d8b872b5e",
|
|
32
|
+
"short": "a3e9f80e",
|
|
33
|
+
"name": "自动重启",
|
|
34
|
+
"role": "自动重启模块负责人(原 dsh-restart 插件作者会话)",
|
|
35
|
+
"since": "2026-10-20",
|
|
36
|
+
"scope": "lib/restart/ 下的 core.js、runtime.js、scripts/**",
|
|
37
|
+
"rule": "不单独发版、不自己发版;改完向主维护会话(b6aa099b)汇报,由主维护并入 dsh-crossterm 发版"
|
|
38
|
+
}
|
|
39
|
+
},
|
|
29
40
|
"previous": [
|
|
30
41
|
{
|
|
31
42
|
"session": "session-6ef6da30-a7f1-4a4e-...",
|
|
@@ -42,6 +53,13 @@
|
|
|
42
53
|
}
|
|
43
54
|
-->
|
|
44
55
|
|
|
56
|
+
## 模块负责人(大插件里的小模块,可以分工)
|
|
57
|
+
|
|
58
|
+
一份插件里可以拆给多人:模块负责人只管自己那几支文件,发版仍由插件负责人统一做。
|
|
59
|
+
|
|
60
|
+
| 模块 | 负责人 | 范围 | 规矩 |
|
|
61
|
+
|---|---|---|---|
|
|
62
|
+
| 自动重启(`lib/restart/`,插件页第 ⑥ 个组件) | `a3e9f80e`(会话名「自动重启」) | `core.js` / `runtime.js` / `scripts/**` | 不单独发版、不自己发版;改完汇报给 `b6aa099b`,由插件负责人并入 `dsh-crossterm` 一起发版 |
|
|
45
63
|
## 任期表
|
|
46
64
|
|
|
47
65
|
| 起(本地时间) | 止(本地时间) | 会话 | 终端 / nodeId | 角色 | 交接依据 |
|
package/README.md
CHANGED
|
@@ -23,37 +23,38 @@ A 终端看不到 B 终端里有哪个会话、在干什么,也没法把一条
|
|
|
23
23
|
| ③ | 跨终端 | 同一台机器上的多个 DSH 终端/进程之间互发邮件与文件 | `term_whoami` `term_list` `term_send` `term_send_files` |
|
|
24
24
|
| ④ | 跨设备 | 经云端总线,在多台机器的 DSH 之间互发邮件与文件 | `term_cloud` |
|
|
25
25
|
| ⑤ | 跨账号 | 预留位:后续用于跨账号互通,当前不挂工具 | — |
|
|
26
|
+
| ⑥ | 自动重启 | 改完插件/配置后让 DSH 自己重启一次,并自动拉起离线会话(原 `dsh-restart` 插件,0.9.0 起并入) | `dsh_restart` |
|
|
26
27
|
|
|
27
28
|
> 入口行为什么必须用裸包名:浏览器 client 半端只对裸包名行生效(`dsh-client-modules` 的
|
|
28
29
|
> `locatePkgJson()` 对子路径行返回 undefined),而插件页顶部标题与这一行共用同一份 `locale/zh.json` 的 meta,
|
|
29
30
|
> 所以它单独做入口(配置卡片 + 自动更新开关),标题带「(自更新)」;卡片头用 `shortTitle` 显示短名「跨端互通」。
|
|
30
31
|
|
|
31
|
-
**本版更新(0.
|
|
32
|
+
**本版更新(0.9.0)**
|
|
33
|
+
|
|
34
|
+
- **升级当次就能提示「待重启」**:以前这一步要等服务端换成新版才认得出来(YOCE_C 回归的第 3/4 步就是这样「看不见」)。
|
|
35
|
+
现在浏览器 client 自己带版本号(`CLIENT_VERSION`),点完更新就从 `/update` 响应的 `installed` / `before` 判断,
|
|
36
|
+
立刻把卡片切成「已装待重启」;渲染时还会按「磁盘版本 > 进程版本」持续推导,旧进程也提示得出来。
|
|
37
|
+
- `/check` 多返回一个 `running`(= 进程版本),与 `current` 并列,旧客户端也能照常解析。
|
|
38
|
+
- **自动重启并进来当第 6 个组件**:原 `dsh-restart` 插件的 `dsh_restart` 工具与 8 个 helper 脚本并入 `lib/restart/`,
|
|
39
|
+
插件页多一行「自动重启」。它不参与总线,只在每个会话上挂 `dsh_restart`;脚本首次启动时同步到
|
|
40
|
+
`<总线目录>/restart-module/`(默认 `C:\Users\<你>\.dsh\crossterm\restart-module`)。
|
|
41
|
+
- **不再单独发版**:自动重启模块由原 `dsh-restart` 会话(`a3e9f80e`,会话名「自动重启」)继续维护,
|
|
42
|
+
改动汇报给插件主维护会话,由主维护会话并入本插件一起发版。
|
|
43
|
+
- 旧的 `dsh-restart-module` 插件还装着时会重复注册 `dsh_restart`,需在 profile 里摘掉它(本机另行处理)。
|
|
44
|
+
- 本机是 `link:` 源码版,没有这层差别;以上对用 npm 安装的设备生效。
|
|
45
|
+
|
|
46
|
+
**上一版(0.8.15)**
|
|
32
47
|
|
|
33
48
|
- **「更新」按钮不再看起来没用**:装完新版但还没重启时,卡片多一行「待重启」、
|
|
34
49
|
更新按钮变成不可点的「已装待重启」,接口 `/check` 改回 `needRestart=true` 而不是继续报「有更新」。
|
|
35
50
|
- 根因是状态表达:宿主进程里还是旧版本号,而磁盘上已经装了新版 —— 现在这两个版本分开显示。
|
|
36
51
|
- 本机是 `link:` 源码版(磁盘版本永远等于源码版本),所以这行只会在 npm 安装的设备上出现。
|
|
37
52
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
- **已经是最新就不装**:点「更新」时若 npm 最新版 ≤ 当前版本,直接回「已经是最新(0.8.12),不用更新」,
|
|
41
|
-
不再跑一次 15 秒的安装、也不再重写 `node_modules`。
|
|
42
|
-
- **没写收件人的信优先投给维护者**:跨设备信封没写收件人(或写的名字本机认不出)时,原来按「最近活跃会话」投,
|
|
43
|
-
可能落进 QQ 或无关会话 —— YOCE_C 的 0.8.12 验收报告就投到了 `im:qq_39`。现在先找 `MAINTAINERS.md` 里的
|
|
44
|
-
主维护会话,命中就用它,否则仍按最近活跃投。
|
|
45
|
-
- 本机是 `link:` 源码版,点更新仍提示「改源码后重启」;以上对用 npm 安装的其他设备生效。
|
|
46
|
-
|
|
47
|
-
**上一版(0.8.12)**
|
|
48
|
-
|
|
49
|
-
- **修「点更新必定失败」**:0.8.11 给三级兜底都加了 `--prefer-online`,而这是 pnpm 11 的非法选项;
|
|
50
|
-
现在只给 pnpm 那步加它认识的 `--config.prefer-offline=false`。
|
|
51
|
-
- **新版本发布不到 24h 也能装**:撞 `minimumReleaseAge` 策略时自动用 `--config.minimumReleaseAge=0` 重试一次。
|
|
52
|
-
- **npm 最新版读得准了**:两个源都问、取最大版本(原来谁先返回用谁,镜像滞后会把版本号读旧)。
|
|
53
|
-
|
|
54
|
-
**更早(0.8.11 / 0.8.10 / 0.8.9 / 0.8.8 / 0.8.7 / 0.8.6 / 0.8.5 / 0.8.0)**
|
|
53
|
+
**更早(0.8.14 / 0.8.13 / 0.8.12 / 0.8.11 / 0.8.10 / 0.8.9 / 0.8.8 / 0.8.7 / 0.8.6 / 0.8.5 / 0.8.0)**
|
|
55
54
|
|
|
56
|
-
- 0.8.
|
|
55
|
+
- 0.8.14:装完未重启时卡片显示「待重启」、更新按钮变灰「已装待重启」,`/check` 回 `needRestart=true`。
|
|
56
|
+
- 0.8.13:已经是最新就不装;没写收件人的信优先投给 `MAINTAINERS.md` 里的维护者会话。
|
|
57
|
+
- 0.8.12 / 0.8.11:修「点更新必定失败」(pnpm 不认 `--prefer-online`)、装低自动回滚、最新版取两个源的最大值。
|
|
57
58
|
- 0.8.10 / 0.8.9 / 0.8.8 / 0.8.7:云端设备只列别人、带权限与状态、版本仅在差异时显示;插件页标题改「跨端互通(自更新)」;
|
|
58
59
|
入口组件从「总开关」改为「自更新开关」,四个业务组件互不依赖。
|
|
59
60
|
- 0.8.5:负责人留痕 `MAINTAINERS.md`、运行日志可轮转、卡片「维护者」行与「运行日志」按钮。
|
package/client/client.js
CHANGED
|
@@ -8,6 +8,21 @@ window.__ModuleLoader__.load({
|
|
|
8
8
|
const React = require("react");
|
|
9
9
|
const h = React.createElement;
|
|
10
10
|
|
|
11
|
+
// 0.8.15:这份 client 随包发布,它的版本号就是「磁盘上的版本」。
|
|
12
|
+
// 服务端进程可能还是旧版(装完没重启),拿它跟 /status.version 一比就知道该不该提示重启 ——
|
|
13
|
+
// 这样绕开了「旧进程读不到新字段」的死角(YOCE_C 的回归结论)。
|
|
14
|
+
const CLIENT_VERSION = "0.8.15";
|
|
15
|
+
|
|
16
|
+
const cmpVer = (a, b) => {
|
|
17
|
+
const pa = String(a || "").split(".").map((x) => Number(x) || 0);
|
|
18
|
+
const pb = String(b || "").split(".").map((x) => Number(x) || 0);
|
|
19
|
+
for (let i = 0; i < Math.max(pa.length, pb.length); i++) {
|
|
20
|
+
const d = (pa[i] || 0) - (pb[i] || 0);
|
|
21
|
+
if (d !== 0) return d < 0 ? -1 : 1;
|
|
22
|
+
}
|
|
23
|
+
return 0;
|
|
24
|
+
};
|
|
25
|
+
|
|
11
26
|
const S = {
|
|
12
27
|
card: {
|
|
13
28
|
border: "1px solid rgba(128,128,128,.28)",
|
|
@@ -246,6 +261,10 @@ window.__ModuleLoader__.load({
|
|
|
246
261
|
const [showLog, setShowLog] = React.useState(false);
|
|
247
262
|
const [runLog, setRunLog] = React.useState(null);
|
|
248
263
|
const [showRunLog, setShowRunLog] = React.useState(false);
|
|
264
|
+
// 0.8.15:本次页面会话里「刚装完、还没重启」的一次性标记。
|
|
265
|
+
// 旧版服务端不会返回 status.installed / needRestart,但 /update 的响应里一直带着
|
|
266
|
+
// installed 与 before(0.8.13 起还带 needRestart),所以升级当次就能立刻提示。
|
|
267
|
+
const [restartPending, setRestartPending] = React.useState(false);
|
|
249
268
|
|
|
250
269
|
const load = React.useCallback(() => {
|
|
251
270
|
call("/crossterm/api/status")
|
|
@@ -310,7 +329,8 @@ window.__ModuleLoader__.load({
|
|
|
310
329
|
try {
|
|
311
330
|
const data = await call("/crossterm/api/check", "POST");
|
|
312
331
|
if (!data || !data.ok) setMsg("检查失败:" + ((data && data.message) || "未知错误"));
|
|
313
|
-
else if (data.needRestart
|
|
332
|
+
else if (data.needRestart || (data.installed && cmpVer(data.installed, data.current) > 0))
|
|
333
|
+
setMsg(`已装 ${data.installed || "新版"},重启 DSH 后生效(当前进程还在跑 ${data.current})`);
|
|
314
334
|
else if (data.updateAvailable) setMsg(`发现新版本 ${data.latest}(当前 ${data.current})`);
|
|
315
335
|
else if (data.ahead) setMsg(`本地 ${data.current} 领先已发布版 ${data.latest}`);
|
|
316
336
|
else setMsg(`已是最新版本 ${data.current}`);
|
|
@@ -327,6 +347,14 @@ window.__ModuleLoader__.load({
|
|
|
327
347
|
try {
|
|
328
348
|
const data = await call("/crossterm/api/update", "POST");
|
|
329
349
|
const text = (data && data.message) || (data && data.ok ? "已更新" : "未能更新");
|
|
350
|
+
// 0.8.15:装完就记一笔「待重启」。旧版服务端的 /status 不返回 installed/needRestart,
|
|
351
|
+
// 但 /update 的响应里有 installed / before(0.8.13 起还有 needRestart),够判断了。
|
|
352
|
+
const after = data && (data.installed || "");
|
|
353
|
+
const beforeVer = data && (data.before || "");
|
|
354
|
+
const justInstalled = Boolean(
|
|
355
|
+
data && data.ok && (data.needRestart === true || (after && beforeVer && after !== beforeVer)),
|
|
356
|
+
);
|
|
357
|
+
if (justInstalled) setRestartPending(true);
|
|
330
358
|
const steps = (data && data.steps) || [];
|
|
331
359
|
// 失败时把每条尝试(dsh / DSH 自带 cli / pnpm)的退出码与输出带上,方便远端排查
|
|
332
360
|
const detail = data && data.ok
|
|
@@ -335,6 +363,7 @@ window.__ModuleLoader__.load({
|
|
|
335
363
|
? "\n\n" + steps.map((s) => `[${s.label}] 退出码 ${s.code} · ${Math.round((s.ms || 0) / 1000)}s` + (s.out ? `\n${String(s.out).slice(-400)}` : "")).join("\n\n")
|
|
336
364
|
: "";
|
|
337
365
|
setMsg(text + detail);
|
|
366
|
+
if (justInstalled) void load();
|
|
338
367
|
} catch (error) {
|
|
339
368
|
setMsg("更新失败:" + String((error && error.message) || error));
|
|
340
369
|
} finally {
|
|
@@ -447,9 +476,13 @@ window.__ModuleLoader__.load({
|
|
|
447
476
|
|
|
448
477
|
const version = status ? "v" + status.version : "";
|
|
449
478
|
const mode = status && status.install ? status.install.mode : "";
|
|
450
|
-
// 0.8.14:磁盘版本 > 进程版本 =
|
|
451
|
-
|
|
452
|
-
const
|
|
479
|
+
// 0.8.14/0.8.15:磁盘版本 > 进程版本 = 已装好但还没重启。
|
|
480
|
+
// 磁盘版本优先看服务端的 status.installed;旧版服务端没这个字段时用 client 自带的版本号兜底。
|
|
481
|
+
const diskVer = (status && status.installed) || (status ? CLIENT_VERSION : "");
|
|
482
|
+
const onDiskNewer = Boolean(status && status.version && diskVer && cmpVer(status.version, diskVer) < 0);
|
|
483
|
+
const installedVer = (status && status.installed) || (onDiskNewer ? CLIENT_VERSION : "");
|
|
484
|
+
const needRestart = Boolean((status && status.needRestart) || restartPending || onDiskNewer);
|
|
485
|
+
const cloud = (status && status.cloud) || {};
|
|
453
486
|
const autoUpdate = (status && status.autoUpdate) || {};
|
|
454
487
|
const home = (status && status.home) || null;
|
|
455
488
|
const subtitle = status
|
|
@@ -504,7 +537,7 @@ window.__ModuleLoader__.load({
|
|
|
504
537
|
needRestart
|
|
505
538
|
? h(FriendlyRow, {
|
|
506
539
|
label: "待重启",
|
|
507
|
-
value: `已装 v${installedVer},重启 DSH 后生效(当前进程还在跑 v${status && status.version})`,
|
|
540
|
+
value: `已装 v${installedVer || "新版"},重启 DSH 后生效(当前进程还在跑 v${status && status.version})`,
|
|
508
541
|
})
|
|
509
542
|
: null,
|
|
510
543
|
h(FriendlyRow, {
|
package/cordis.patch.yml
CHANGED
|
@@ -18,6 +18,8 @@
|
|
|
18
18
|
# ③ dsh-crossterm/parts/terminal 跨终端:term_whoami / term_list / term_send / term_send_files
|
|
19
19
|
# ④ dsh-crossterm/parts/device 跨设备:term_cloud(云端总线同步)
|
|
20
20
|
# ⑤ dsh-crossterm/parts/account 跨账号:预留占位,暂不挂工具
|
|
21
|
+
⑥ dsh-crossterm/parts/restart 自动重启:dsh_restart(原 dsh-restart 插件,0.9.0 起并入)
|
|
22
|
+
它不碰总线,只把 dsh_restart 工具挂到每个会话上。
|
|
21
23
|
#
|
|
22
24
|
# 组件名来自 package.json 的 exports 映射:
|
|
23
25
|
# "./parts/session/package.json" -> "./parts/session.manifest.json"
|
|
@@ -32,7 +34,7 @@
|
|
|
32
34
|
# 关掉入口行只失去「配置卡片 + 自动更新」,四个业务组件照常工作、各自仍可单独关。
|
|
33
35
|
# 之前(0.7.x–0.8.8)是 ui 行 provide('crossterm')、其余四行 inject 它,关入口会连坐——已废弃。
|
|
34
36
|
#
|
|
35
|
-
#
|
|
37
|
+
# 前五个组件在同一 DSH 进程里共用一份总线实例(自动重启不参与,它只挂自己的工具):心跳只起一次,云同步只在 device 组件启用
|
|
36
38
|
# 且 config.json 里 cloudEnabled=true 时才跑。安装/改动后需重启对应的 DSH 进程。
|
|
37
39
|
# ============================================================================
|
|
38
40
|
|
|
@@ -59,3 +61,9 @@
|
|
|
59
61
|
name: dsh-crossterm/parts/account
|
|
60
62
|
config:
|
|
61
63
|
part: account
|
|
64
|
+
- id: crossterm-restart
|
|
65
|
+
# 自动重启(原 dsh-restart 插件):不参与总线,只挂 dsh_restart 工具。
|
|
66
|
+
# helper 脚本随包分发在 lib/restart/scripts/,启动时复制到 <busDir>/restart-module/。
|
|
67
|
+
name: dsh-crossterm/parts/restart
|
|
68
|
+
config:
|
|
69
|
+
part: restart
|
package/lib/bus.js
CHANGED
|
@@ -23,7 +23,7 @@ import path from 'node:path'
|
|
|
23
23
|
import crypto from 'node:crypto'
|
|
24
24
|
import { rotateIfNeeded } from './logs.js'
|
|
25
25
|
|
|
26
|
-
export const VERSION = '0.
|
|
26
|
+
export const VERSION = '0.9.0'
|
|
27
27
|
|
|
28
28
|
/** DSH 的家目录:与宿主其它状态(sessions / profiles)同一个根,多终端天然共享 */
|
|
29
29
|
export function dshHome() {
|
package/lib/index.js
CHANGED
|
@@ -42,6 +42,7 @@ import { runSetup } from './cloud/setup.js'
|
|
|
42
42
|
import { deviceRow, matchDevice } from './cloud/match.js'
|
|
43
43
|
import { registerWeb, selfUpdate } from './web.js'
|
|
44
44
|
import { recordOwnership, readMaintainersDoc } from './logs.js'
|
|
45
|
+
import { ensureRestartRuntime } from './restart/runtime.js'
|
|
45
46
|
|
|
46
47
|
const PLUGIN = 'dsh-crossterm'
|
|
47
48
|
const ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..')
|
|
@@ -1511,7 +1512,7 @@ const TOOL_PART = {
|
|
|
1511
1512
|
term_cloud: 'device',
|
|
1512
1513
|
}
|
|
1513
1514
|
|
|
1514
|
-
const PARTS = ['all', 'ui', 'session', 'terminal', 'device', 'account']
|
|
1515
|
+
const PARTS = ['all', 'ui', 'session', 'terminal', 'device', 'account', 'restart']
|
|
1515
1516
|
|
|
1516
1517
|
const PART_LABEL = {
|
|
1517
1518
|
all: '全部组件',
|
|
@@ -1520,6 +1521,7 @@ const PART_LABEL = {
|
|
|
1520
1521
|
terminal: '跨终端',
|
|
1521
1522
|
device: '跨设备',
|
|
1522
1523
|
account: '跨账号(预留)',
|
|
1524
|
+
restart: '自动重启',
|
|
1523
1525
|
}
|
|
1524
1526
|
|
|
1525
1527
|
function normalizePart(raw) {
|
|
@@ -2079,10 +2081,55 @@ function releaseTerm(term) {
|
|
|
2079
2081
|
|
|
2080
2082
|
// ── 入口 ──────────────────────────────────────────────────────────────────
|
|
2081
2083
|
|
|
2084
|
+
const RESTART_SRC = path.join(ROOT, 'lib', 'restart', 'scripts')
|
|
2085
|
+
|
|
2086
|
+
/**
|
|
2087
|
+
* 「自动重启」组件(原 dsh-restart 插件,0.9.0 起并入)。
|
|
2088
|
+
*
|
|
2089
|
+
* 它不参与总线:只把 dsh_restart 工具挂到每个会话上,并把 helper 脚本复制到
|
|
2090
|
+
* 可写目录后交给 ./restart/core.js。脚本必须在 import core.js **之前**落到
|
|
2091
|
+
* DSH_RESTART_MODULE_DIR,因为 core.js 在模块顶层读这个环境变量。
|
|
2092
|
+
*/
|
|
2093
|
+
function mountRestart(root, config) {
|
|
2094
|
+
const label = 'dsh-crossterm(自动重启)'
|
|
2095
|
+
let destDir = ''
|
|
2096
|
+
const mark = (line) => {
|
|
2097
|
+
const text = `[${new Date().toISOString()}] ${label}: ${line}\n`
|
|
2098
|
+
try {
|
|
2099
|
+
if (destDir) {
|
|
2100
|
+
const dir = path.join(destDir, 'logs')
|
|
2101
|
+
fs.mkdirSync(dir, { recursive: true })
|
|
2102
|
+
fs.appendFileSync(path.join(dir, 'plugin.log'), text)
|
|
2103
|
+
}
|
|
2104
|
+
} catch { /* ignore */ }
|
|
2105
|
+
}
|
|
2106
|
+
try {
|
|
2107
|
+
const cfg = readConfig()
|
|
2108
|
+
destDir = path.join(cfg.busDir, 'restart-module')
|
|
2109
|
+
const info = ensureRestartRuntime({ srcDir: RESTART_SRC, destDir, version: VERSION })
|
|
2110
|
+
if (info.skipped.length) mark(`脚本缺失:${info.skipped.join(', ')}`)
|
|
2111
|
+
if (!process.env.DSH_RESTART_MODULE_DIR) process.env.DSH_RESTART_MODULE_DIR = destDir
|
|
2112
|
+
mark(`运行目录就绪:${destDir}(本次复制 ${info.copied.length} 个脚本)`)
|
|
2113
|
+
void import('./restart/core.js')
|
|
2114
|
+
.then((mod) => {
|
|
2115
|
+
mod.default.apply(root, { ...config, part: 'restart' })
|
|
2116
|
+
mark('已挂载 dsh_restart 工具')
|
|
2117
|
+
})
|
|
2118
|
+
.catch((e) => mark(`加载失败:${(e && e.message) || String(e)}`))
|
|
2119
|
+
} catch (e) {
|
|
2120
|
+
mark(`启动失败:${(e && e.message) || String(e)}`)
|
|
2121
|
+
}
|
|
2122
|
+
}
|
|
2123
|
+
|
|
2082
2124
|
export default {
|
|
2083
2125
|
name: PLUGIN,
|
|
2084
2126
|
apply(root, config) {
|
|
2085
2127
|
const part = normalizePart(config?.part)
|
|
2128
|
+
// 「自动重启」是独立组件:不碰总线,只挂 dsh_restart 工具。
|
|
2129
|
+
if (part === 'restart') {
|
|
2130
|
+
mountRestart(root, config)
|
|
2131
|
+
return
|
|
2132
|
+
}
|
|
2086
2133
|
// 0.8.9 起「入口」组件不再当总开关:它只负责插件卡片与「自动更新」,
|
|
2087
2134
|
// 四个业务组件(跨会话/跨终端/跨设备/跨账号)各挂各的 —— 关掉入口行不会连坐。
|
|
2088
2135
|
// 自动更新默认关(cfg.autoUpdate=false),开关在卡片里,改了落 config.json。
|