@leiyi-works/dsh-auto-restart 0.3.3 → 0.3.4
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/index.js +34 -2
- package/lib/install-watchdog.ps1 +1 -1
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -307,13 +307,45 @@ function ensureWatchdogFiles() {
|
|
|
307
307
|
const target = join(dataDir(), file)
|
|
308
308
|
try {
|
|
309
309
|
if (!existsSync(source)) continue
|
|
310
|
-
|
|
310
|
+
const bytes = readFileSync(source)
|
|
311
|
+
// Windows PowerShell 5.1 decodes a BOM-less .ps1 as ANSI, which turns the
|
|
312
|
+
// Chinese messages in the installer into mojibake and a parse error. Always
|
|
313
|
+
// write the runtime copy with a UTF-8 BOM, whatever the package shipped.
|
|
314
|
+
const needsBom = /\.ps1$/i.test(file)
|
|
315
|
+
&& !(bytes.length >= 3 && bytes[0] === 0xEF && bytes[1] === 0xBB && bytes[2] === 0xBF)
|
|
316
|
+
if (needsBom) writeFileSync(target, Buffer.concat([Buffer.from([0xEF, 0xBB, 0xBF]), bytes]))
|
|
317
|
+
else writeFileSync(target, bytes)
|
|
311
318
|
} catch (error) {
|
|
312
319
|
logLine('warn', `同步看门狗文件失败 ${file}: ${String(error?.message ?? error)}`)
|
|
313
320
|
}
|
|
314
321
|
}
|
|
315
322
|
}
|
|
316
323
|
|
|
324
|
+
/**
|
|
325
|
+
* Runs the boot resume once `sessionController` is available. Cordis may not have
|
|
326
|
+
* provided it yet when this plugin applies, so the optional service is looked up
|
|
327
|
+
* immediately and waited for through `inject` otherwise.
|
|
328
|
+
*/
|
|
329
|
+
function resumeWithController(ctx, cfg) {
|
|
330
|
+
let started = false
|
|
331
|
+
const run = (scoped) => {
|
|
332
|
+
if (started) return
|
|
333
|
+
started = true
|
|
334
|
+
void resumeInterrupted(scoped, cfg)
|
|
335
|
+
}
|
|
336
|
+
try {
|
|
337
|
+
if (typeof ctx.get === 'function' && ctx.get('sessionController')) {
|
|
338
|
+
run(ctx)
|
|
339
|
+
return
|
|
340
|
+
}
|
|
341
|
+
} catch {}
|
|
342
|
+
try {
|
|
343
|
+
ctx.inject(['sessionController'], (scoped) => run(scoped))
|
|
344
|
+
} catch (error) {
|
|
345
|
+
logLine('warn', `等待 sessionController 失败:${String(error?.message ?? error)}`)
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
|
|
317
349
|
/** SHA1 of the watchdog script shipped with this plugin version. */
|
|
318
350
|
function watchdogScriptHash() {
|
|
319
351
|
try {
|
|
@@ -1238,7 +1270,7 @@ export function apply(ctx, config) {
|
|
|
1238
1270
|
cleanForeignRequests()
|
|
1239
1271
|
bootWatchdogCheck(state)
|
|
1240
1272
|
// Sessions that a previous restart interrupted get one "继续" after boot.
|
|
1241
|
-
|
|
1273
|
+
resumeWithController(ctx, cfg)
|
|
1242
1274
|
|
|
1243
1275
|
// Track busy sessions so a restart never cuts an answer.
|
|
1244
1276
|
ctx.effect(() => ctx.on('api-session/status', (sessionId, running) => {
|
package/lib/install-watchdog.ps1
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@leiyi-works/dsh-auto-restart",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.4",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"title": "自动重启",
|
|
6
6
|
"description": "装/更插件后自动重启 DSH 并回到原会话:检测 profile 插件文件变化,一直等所有会话空闲且最近活动安静,由常驻后台看门狗(登录自启、不碰 WMI)或 WMI 守护先杀主进程再拉起(可最大化窗口),带冷却、试运行、日志和右侧原生侧边栏面板。",
|