dsh-pocket 1.0.21 → 1.0.23
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/lib/index.js +14 -3
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -13,7 +13,7 @@ import { fileURLToPath } from 'node:url';
|
|
|
13
13
|
import { spawn } from 'node:child_process';
|
|
14
14
|
import { createRequire } from 'node:module';
|
|
15
15
|
import { readFileSync } from 'node:fs';
|
|
16
|
-
import { writeFile, readFile, mkdir } from 'node:fs/promises';
|
|
16
|
+
import { writeFile, readFile, mkdir, rm } from 'node:fs/promises';
|
|
17
17
|
import { join, dirname } from 'node:path';
|
|
18
18
|
import { homedir } from 'node:os';
|
|
19
19
|
|
|
@@ -58,6 +58,17 @@ function writeRestartNotice() {
|
|
|
58
58
|
return mkdir(dirname(restartNoticePath()), { recursive: true })
|
|
59
59
|
.then(() => writeFile(restartNoticePath(), JSON.stringify({ at: Date.now(), pid: process.pid }), 'utf8'));
|
|
60
60
|
}
|
|
61
|
+
/**
|
|
62
|
+
* 读重启标记并**删除**(一次性消费):重启后首次打开设置页显示一次「已重启」横幅,
|
|
63
|
+
* 之后不再出现——否则残留文件会让「已重启」一直显示(用户没点重启也误报)。
|
|
64
|
+
*/
|
|
65
|
+
async function consumeRestartNotice() {
|
|
66
|
+
const notice = await readRestartNotice();
|
|
67
|
+
if (notice) {
|
|
68
|
+
await rm(restartNoticePath(), { force: true }).catch(() => {});
|
|
69
|
+
}
|
|
70
|
+
return notice;
|
|
71
|
+
}
|
|
61
72
|
/** 自重启(先落 notice,让重启后的页面提示停止方法)。 */
|
|
62
73
|
function pocketRestart() {
|
|
63
74
|
writeRestartNotice().catch(() => {});
|
|
@@ -106,7 +117,7 @@ export function apply(ctx, config = {}, internals = {}) {
|
|
|
106
117
|
service,
|
|
107
118
|
runUpdate: internals.runUpdate ?? { currentVersion, perform: performUpdate, loadedVersion: () => loadedVersion },
|
|
108
119
|
restart: internals.restart ?? pocketRestart,
|
|
109
|
-
restartNotice: internals.restartNotice ??
|
|
120
|
+
restartNotice: internals.restartNotice ?? consumeRestartNotice,
|
|
110
121
|
log: logger,
|
|
111
122
|
});
|
|
112
123
|
disposers.push(disposeRpc);
|
|
@@ -124,4 +135,4 @@ export function apply(ctx, config = {}, internals = {}) {
|
|
|
124
135
|
}, 'dsh-pocket: stop proxy and tunnel');
|
|
125
136
|
}
|
|
126
137
|
|
|
127
|
-
export { name, inject, readRestartNotice };
|
|
138
|
+
export { name, inject, readRestartNotice, consumeRestartNotice };
|
package/package.json
CHANGED