@evandu/super-pi 0.1.266 → 0.1.268
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/desktop/application.cjs +3 -2
- package/desktop/launch.cjs +8 -1
- package/desktop/main.cjs +12 -6
- package/desktop/relaunch.cjs +34 -0
- package/desktop/update-lifecycle.cjs +4 -3
- package/dist/client/.super-pi-client-sources.json +3 -3
- package/dist/client/assets/{CodeMirrorEditor-B1roGtGI.js → CodeMirrorEditor-CtY_gf8i.js} +1 -1
- package/dist/client/assets/{GitDiffEditor-BdeOO3TB.js → GitDiffEditor-CtSWZrJJ.js} +1 -1
- package/dist/client/assets/{index-D8gR7y9w.js → index-BEIuDi2o.js} +4 -4
- package/dist/client/index.html +1 -1
- package/dist/server/http-server.js +1 -1
- package/package.json +3 -1
- package/scripts/restart-lock.mjs +23 -0
- package/scripts/restart-server.mjs +23 -2
package/dist/client/index.html
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
<link rel="alternate icon" href="/favicon.ico" />
|
|
9
9
|
<link rel="apple-touch-icon" href="/favicon.svg" />
|
|
10
10
|
<title>Super Pi</title>
|
|
11
|
-
<script type="module" crossorigin src="/assets/index-
|
|
11
|
+
<script type="module" crossorigin src="/assets/index-BEIuDi2o.js"></script>
|
|
12
12
|
<link rel="modulepreload" crossorigin href="/assets/rolldown-runtime-XKyaHtl9.js">
|
|
13
13
|
<link rel="stylesheet" crossorigin href="/assets/index-Cl8iehsn.css">
|
|
14
14
|
</head>
|
|
@@ -1626,7 +1626,7 @@ export function createHttpServer(options) {
|
|
|
1626
1626
|
console.error(`Super Pi: ${message}`);
|
|
1627
1627
|
};
|
|
1628
1628
|
const listenPort = port ?? request.socket.localPort;
|
|
1629
|
-
const restartEnv = { ...process.env, SUPER_PI_DATA_DIR: paths.dataDir, SUPER_PI_PORT: String(listenPort) };
|
|
1629
|
+
const restartEnv = { ...process.env, SUPER_PI_DATA_DIR: paths.dataDir, SUPER_PI_PORT: String(listenPort), SUPER_PI_UPDATE_OPERATION_ID: id };
|
|
1630
1630
|
if (host)
|
|
1631
1631
|
restartEnv.SUPER_PI_HOST = host;
|
|
1632
1632
|
const restartNow = () => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@evandu/super-pi",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.268",
|
|
4
4
|
"description": "Web control plane and companion for Pi",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -21,6 +21,7 @@
|
|
|
21
21
|
"bin",
|
|
22
22
|
"scripts/restart-server.mjs",
|
|
23
23
|
"scripts/restart-process.mjs",
|
|
24
|
+
"scripts/restart-lock.mjs",
|
|
24
25
|
"README.md",
|
|
25
26
|
"assets/knowledge-model",
|
|
26
27
|
"scripts/patch-brace-expansion.mjs",
|
|
@@ -49,6 +50,7 @@
|
|
|
49
50
|
"pack:server": "npm run build && node scripts/pack-server.mjs"
|
|
50
51
|
},
|
|
51
52
|
"check:logic": [
|
|
53
|
+
"scripts/desktop-relaunch.test.mjs",
|
|
52
54
|
"scripts/workbench-memory.test.mjs",
|
|
53
55
|
"scripts/desktop-application.test.mjs",
|
|
54
56
|
"scripts/desktop-notifications.test.mjs",
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { mkdirSync, readFileSync, writeFileSync, rmSync, statSync } from 'node:fs';
|
|
2
|
+
import { join, resolve } from 'node:path';
|
|
3
|
+
|
|
4
|
+
/** Serialize the service helper and native supervisor without holding a live server open. */
|
|
5
|
+
export async function acquireRestartLock(directory, timeout = 180_000) {
|
|
6
|
+
const root = resolve(directory), path = join(root, 'restart-service.lock');
|
|
7
|
+
mkdirSync(root, { recursive: true });
|
|
8
|
+
const deadline = Date.now() + timeout;
|
|
9
|
+
for (;;) {
|
|
10
|
+
try {
|
|
11
|
+
mkdirSync(path); writeFileSync(join(path, 'owner.json'), JSON.stringify({ pid: process.pid }));
|
|
12
|
+
return () => { try { if (JSON.parse(readFileSync(join(path, 'owner.json'), 'utf8')).pid === process.pid) rmSync(path, { recursive: true, force: true }); } catch { /* Another owner must not be removed. */ } };
|
|
13
|
+
} catch (error) {
|
|
14
|
+
if (error.code !== 'EEXIST') throw error;
|
|
15
|
+
try {
|
|
16
|
+
const owner = JSON.parse(readFileSync(join(path, 'owner.json'), 'utf8'));
|
|
17
|
+
try { process.kill(owner.pid, 0); } catch (failure) { if (failure.code === 'ESRCH') { rmSync(path, { recursive: true, force: true }); continue; } }
|
|
18
|
+
} catch { try { if (Date.now() - statSync(path).mtimeMs > 30_000) { rmSync(path, { recursive: true, force: true }); continue; } } catch {} }
|
|
19
|
+
if (Date.now() >= deadline) throw new Error('另一项服务重启尚未结束,请查看重启日志。');
|
|
20
|
+
await new Promise(done => setTimeout(done, 200));
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { spawn, execFile } from "node:child_process";
|
|
2
|
-
import { openSync, readFileSync } from "node:fs";
|
|
2
|
+
import { openSync, readFileSync, writeFileSync, renameSync } from "node:fs";
|
|
3
3
|
import { homedir, platform } from "node:os";
|
|
4
4
|
import { join, resolve } from "node:path";
|
|
5
5
|
import { promisify } from "node:util";
|
|
6
6
|
import { readProcessCommandLine } from "./restart-process.mjs";
|
|
7
|
+
import { acquireRestartLock } from "./restart-lock.mjs";
|
|
7
8
|
|
|
8
9
|
const execFileAsync = promisify(execFile);
|
|
9
10
|
|
|
@@ -30,6 +31,20 @@ const allowedEntries = [entry, "src/server/index.ts"];
|
|
|
30
31
|
* `cmd.includes(candidate)` never matched and the script refused to kill its own server. */
|
|
31
32
|
const normalisePath = (value) => value.replace(/[\\/]+/g, "/").toLowerCase();
|
|
32
33
|
const waitMs = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
34
|
+
const dataDirectory = process.env.SUPER_PI_DATA_DIR || join(homedir(), '.super-pi');
|
|
35
|
+
const releaseRestart = await acquireRestartLock(dataDirectory);
|
|
36
|
+
process.once('exit', releaseRestart);
|
|
37
|
+
// A second helper for this same accepted operation must not restart its healthy successor.
|
|
38
|
+
if (process.env.SUPER_PI_UPDATE_OPERATION_ID) {
|
|
39
|
+
try {
|
|
40
|
+
const operation = JSON.parse(readFileSync(join(dataDirectory, 'update-status.json'), 'utf8'));
|
|
41
|
+
const response = await fetch(`http://127.0.0.1:${port}/api/health`, { signal: AbortSignal.timeout(1500) });
|
|
42
|
+
const health = await response.json();
|
|
43
|
+
let finished;
|
|
44
|
+
try { finished = JSON.parse(readFileSync(join(dataDirectory, 'restart-service-completed.json'), 'utf8')); } catch {}
|
|
45
|
+
if (response.ok && health.service === 'super-pi' && operation.id === process.env.SUPER_PI_UPDATE_OPERATION_ID && (operation.phase === 'completed' || finished?.id === operation.id && finished.version === operation.targetVersion) && health.runningVersion === operation.targetVersion) process.exit(0);
|
|
46
|
+
} catch { /* No healthy successor yet; this helper owns recovery. */ }
|
|
47
|
+
}
|
|
33
48
|
async function pidsOnPort() {
|
|
34
49
|
if (platform() === "win32") {
|
|
35
50
|
const { stdout } = await execFileAsync("netstat", ["-ano", "-p", "TCP"]);
|
|
@@ -96,7 +111,13 @@ while (Date.now() < deadline) {
|
|
|
96
111
|
try {
|
|
97
112
|
const response = await fetch(`http://127.0.0.1:${port}/api/health`, { signal: AbortSignal.timeout(2_000) });
|
|
98
113
|
const body = await response.json();
|
|
99
|
-
if (response.ok && body.status === "ok" && body.service === "super-pi") {
|
|
114
|
+
if (response.ok && body.status === "ok" && body.service === "super-pi") {
|
|
115
|
+
if (process.env.SUPER_PI_UPDATE_OPERATION_ID) {
|
|
116
|
+
const file = join(dataDirectory, 'restart-service-completed.json'), temporary = `${file}.${process.pid}.tmp`;
|
|
117
|
+
writeFileSync(temporary, JSON.stringify({ id: process.env.SUPER_PI_UPDATE_OPERATION_ID, version: body.runningVersion })); renameSync(temporary, file);
|
|
118
|
+
}
|
|
119
|
+
console.log("Server ready: /api/health passed."); process.exit(0);
|
|
120
|
+
}
|
|
100
121
|
} catch { /* The replacement is still starting. */ }
|
|
101
122
|
await waitMs(200);
|
|
102
123
|
}
|