@leiyi-works/dsh-auto-restart 0.2.4 → 0.2.5
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/README.md +2 -3
- package/client.js +1 -1
- package/index.js +20 -44
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -29,8 +29,9 @@
|
|
|
29
29
|
首次启动时插件会检测:没装就自动弹一个**中文控制台窗口**,说明用途并等你按回车安装。安装做三件事:把脚本拷到 `~/.dsh/dsh-auto-restart/`、在启动文件夹写一个隐藏引线、立刻启动看门狗。之后每次登录 Windows 它自动起来,所有自动重启都不再经过 WMI。
|
|
30
30
|
|
|
31
31
|
- 面板里只显示看门狗状态(运行中/未安装/已安装无心跳/脚本已更新待重装),**没有安装/卸载按钮**;
|
|
32
|
-
-
|
|
32
|
+
- **每次 DSH 启动(含自动重启后)体检一次**:看门狗没在回答(进程没了/心跳过期)就自动打开安装窗口;不再做周期检查(避免工作中反复弹窗);这期间自动重启会退回 WMI 兜底;
|
|
33
33
|
- **脚本更新检测**:心跳里带脚本哈希;插件升级后如果后台还跑着旧脚本,会再弹一次安装窗口把看门狗重启到新脚本(安装器会先停掉旧进程);
|
|
34
|
+
- 急停(可选):在 `~/.dsh/dsh-auto-restart/` 里新建空文件 `disabled`,插件就不再动手(这和直接在插件列表里停用插件基本等价,留着只是应急用);删掉即恢复;
|
|
34
35
|
- 卸载:在 `~/.dsh/dsh-auto-restart/` 里执行 `powershell -File install-watchdog.ps1 -Uninstall`;
|
|
35
36
|
- 看门狗日志:`~/.dsh/dsh-auto-restart/watchdog.log`。
|
|
36
37
|
|
|
@@ -78,8 +79,6 @@
|
|
|
78
79
|
| `maxPerHour` | `0` | 每小时上限;`0` = 不限制 |
|
|
79
80
|
| `waitForIdle` | `true` | 等会话空闲再重启 |
|
|
80
81
|
| `idleSettleMs` | `10000` | 最后一次会话活动后安静多久再重启;防止刚发出、回合还没起来的消息被吞掉 |
|
|
81
|
-
| `watchdogCheckMs` | `60000` | 多久体检一次后台看门狗 |
|
|
82
|
-
| `watchdogReinstallCooldownMs` | `300000` | 看门狗不在时,重新打开安装窗口的最小间隔 |
|
|
83
82
|
| `restartDelayMs` | `2000` | 守护进程收到请求后等多久动手 |
|
|
84
83
|
| `maximizeOnRestart` | `true` | 重启后最大化主窗口 |
|
|
85
84
|
| `exePath` | `''` | 应用可执行文件,留空自动推导 |
|
package/client.js
CHANGED
|
@@ -352,7 +352,7 @@ window.__ModuleLoader__.load({
|
|
|
352
352
|
save.busy ? h('p', { style: styles.note }, '正在保存…') : null,
|
|
353
353
|
statusCard,
|
|
354
354
|
settingsCard,
|
|
355
|
-
h('p', { style: styles.note }, '配置文件:' + (status?.configPath ?? '—')
|
|
355
|
+
h('p', { style: styles.note }, '配置文件:' + (status?.configPath ?? '—')),
|
|
356
356
|
),
|
|
357
357
|
)
|
|
358
358
|
}
|
package/index.js
CHANGED
|
@@ -79,10 +79,6 @@ const DEFAULTS = Object.freeze({
|
|
|
79
79
|
* 防止「刚按发送、回合还没起来」的瞬间被重启吞掉,导致输入框回填已发出的文字。
|
|
80
80
|
*/
|
|
81
81
|
idleSettleMs: 10000,
|
|
82
|
-
/** 多久检查一次后台看门狗是否活着(毫秒)。 */
|
|
83
|
-
watchdogCheckMs: 60000,
|
|
84
|
-
/** 看门狗不在时,重新打开安装窗口的最小间隔(毫秒)。 */
|
|
85
|
-
watchdogReinstallCooldownMs: 300000,
|
|
86
82
|
/** 守护进程收到请求后等多久动手(毫秒),留时间给当前回合收尾。 */
|
|
87
83
|
restartDelayMs: 2000,
|
|
88
84
|
/** 重启后把主窗口最大化(开关在左侧「自动重启」面板里)。 */
|
|
@@ -308,34 +304,27 @@ function cleanForeignRequests() {
|
|
|
308
304
|
}
|
|
309
305
|
|
|
310
306
|
/**
|
|
311
|
-
*
|
|
312
|
-
*
|
|
313
|
-
*
|
|
307
|
+
* Boot-time watchdog check: once per DSH start (and therefore once after every
|
|
308
|
+
* automatic restart) the plugin verifies the resident watchdog. Missing or running
|
|
309
|
+
* older code means a restart would fall back to WMI, so the console installer is
|
|
310
|
+
* opened. Deliberately not periodic: one check per boot is enough and keeps
|
|
311
|
+
* console windows from popping up while the user works.
|
|
314
312
|
*/
|
|
315
|
-
function
|
|
313
|
+
function bootWatchdogCheck(state) {
|
|
316
314
|
if (!isDesktopHost() || !isRealUserHome()) return
|
|
317
|
-
if (
|
|
318
|
-
state.
|
|
315
|
+
if (state.bootWatchdogChecked === true) return
|
|
316
|
+
state.bootWatchdogChecked = true
|
|
319
317
|
const heartbeat = readWatchdogHeartbeat()
|
|
320
|
-
if (heartbeat !== null) {
|
|
321
|
-
|
|
322
|
-
if (!watchdogScriptStale(heartbeat)) return
|
|
323
|
-
// Running code is older than the plugin on disk: the installer stops the old
|
|
324
|
-
// process and starts the new script.
|
|
325
|
-
if (now - state.lastWatchdogOfferAt < cfg.watchdogReinstallCooldownMs) return
|
|
326
|
-
state.lastWatchdogOfferAt = now
|
|
327
|
-
state.watchdogStaleLogged = true
|
|
328
|
-
logLine('warn', `后台看门狗运行的脚本已过期(${heartbeat.script.slice(0, 8)} ≠ ${watchdogScriptHash().slice(0, 8)}),重新打开安装窗口以更新`)
|
|
329
|
-
offerWatchdogInstall()
|
|
318
|
+
if (heartbeat !== null && !watchdogScriptStale(heartbeat)) {
|
|
319
|
+
logLine('info', `后台看门狗运行中:pid=${heartbeat.pid} 心跳=${heartbeat.at}`)
|
|
330
320
|
return
|
|
331
321
|
}
|
|
332
|
-
if (
|
|
333
|
-
|
|
334
|
-
if (
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
: '后台看门狗未安装,重新打开安装窗口')
|
|
322
|
+
if (heartbeat !== null) {
|
|
323
|
+
logLine('warn', `后台看门狗运行的脚本已过期(${heartbeat.script.slice(0, 8)} ≠ ${watchdogScriptHash().slice(0, 8)}),打开安装窗口更新`)
|
|
324
|
+
} else if (watchdogInstalled()) {
|
|
325
|
+
logLine('warn', '后台看门狗已安装但当前没有心跳,打开安装窗口重新启动')
|
|
326
|
+
} else {
|
|
327
|
+
logLine('info', '后台看门狗未安装:打开安装窗口')
|
|
339
328
|
}
|
|
340
329
|
offerWatchdogInstall()
|
|
341
330
|
}
|
|
@@ -447,8 +436,6 @@ function sanitizeConfig(raw) {
|
|
|
447
436
|
cfg.cooldownMs = num(raw.cooldownMs, cfg.cooldownMs, 0, 3600000)
|
|
448
437
|
cfg.maxPerHour = num(raw.maxPerHour, cfg.maxPerHour, 0, 100)
|
|
449
438
|
cfg.idleSettleMs = num(raw.idleSettleMs, cfg.idleSettleMs, 0, 600000)
|
|
450
|
-
cfg.watchdogCheckMs = num(raw.watchdogCheckMs, cfg.watchdogCheckMs, 10000, 3600000)
|
|
451
|
-
cfg.watchdogReinstallCooldownMs = num(raw.watchdogReinstallCooldownMs, cfg.watchdogReinstallCooldownMs, 60000, 86400000)
|
|
452
439
|
cfg.restartDelayMs = num(raw.restartDelayMs, cfg.restartDelayMs, 0, 600000)
|
|
453
440
|
cfg.logMaxBytes = num(raw.logMaxBytes, cfg.logMaxBytes, 4096, 64 * 1024 * 1024)
|
|
454
441
|
for (const key of ['exePath', 'supervisorScript', 'powershellPath', 'profileDir']) {
|
|
@@ -766,8 +753,7 @@ function createState(profileDir) {
|
|
|
766
753
|
lastReason: '',
|
|
767
754
|
lastSkipLog: 0,
|
|
768
755
|
watchdogMissingLogged: false,
|
|
769
|
-
|
|
770
|
-
lastWatchdogOfferAt: 0,
|
|
756
|
+
bootWatchdogChecked: false,
|
|
771
757
|
}
|
|
772
758
|
}
|
|
773
759
|
|
|
@@ -781,8 +767,6 @@ function tick(baseConfig) {
|
|
|
781
767
|
const now = Date.now()
|
|
782
768
|
state.restarts = state.restarts.filter((t) => now - t < 3600000)
|
|
783
769
|
|
|
784
|
-
watchdogHealthCheck(state, cfg, now)
|
|
785
|
-
|
|
786
770
|
// A restart is already on its way; the process will disappear shortly.
|
|
787
771
|
if (state.dispatchedAt > 0 && now - state.dispatchedAt < 60000) return
|
|
788
772
|
|
|
@@ -1051,19 +1035,11 @@ export function apply(ctx, config) {
|
|
|
1051
1035
|
|
|
1052
1036
|
logLine('info', `${MARK} ${VERSION} 已加载:profile=${profileDir} dryRun=${cfg.dryRun} cooldown=${cfg.cooldownMs}ms cap=${cfg.maxPerHour === 0 ? '无' : cfg.maxPerHour + '/h'} maximize=${cfg.maximizeOnRestart} desktop=${isDesktopHost()}`)
|
|
1053
1037
|
|
|
1054
|
-
// Resident watchdog: keep its files current,
|
|
1055
|
-
//
|
|
1038
|
+
// Resident watchdog: keep its files current, drop requests synced from another
|
|
1039
|
+
// machine, then check the watchdog once for this boot (no periodic checks).
|
|
1056
1040
|
ensureWatchdogFiles()
|
|
1057
1041
|
cleanForeignRequests()
|
|
1058
|
-
|
|
1059
|
-
if (heartbeat !== null) {
|
|
1060
|
-
logLine('info', `后台看门狗运行中:pid=${heartbeat.pid} 心跳=${heartbeat.at}`)
|
|
1061
|
-
} else if (watchdogInstalled()) {
|
|
1062
|
-
logLine('warn', '后台看门狗已安装但当前没有心跳(可能刚登录还没起来),本次重启会用 WMI 兜底')
|
|
1063
|
-
} else {
|
|
1064
|
-
logLine('info', '后台看门狗未安装:会自动打开安装窗口')
|
|
1065
|
-
}
|
|
1066
|
-
watchdogHealthCheck(state, cfg)
|
|
1042
|
+
bootWatchdogCheck(state)
|
|
1067
1043
|
|
|
1068
1044
|
// Track busy sessions so a restart never cuts an answer.
|
|
1069
1045
|
ctx.effect(() => ctx.on('api-session/status', (sessionId, running) => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@leiyi-works/dsh-auto-restart",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.5",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"title": "自动重启",
|
|
6
6
|
"description": "装/更插件后自动重启 DSH 并回到原会话:检测 profile 插件文件变化,一直等所有会话空闲且最近活动安静,由常驻后台看门狗(登录自启、不碰 WMI)或 WMI 守护先杀主进程再拉起(可最大化窗口),带冷却、试运行、日志和右侧原生侧边栏面板。",
|