返回提交历史
Modified
scripts/dev.js
+9
-3
Modified
src/controllers/custom/webuiFileChangeDetectedController.ts
+1
-2
Modified
src/services/webService.ts
+1
-0
Modified
static/webui/script.js
+14
-5
XFEstudio/SpaceNinjaServer
chore(dev): improve bulk change handling (#2234)
Fixed abandoned build processes sometimes still triggering a start (causing double-starts) made it more robust in regards to webui changes being intermixed: making the fetch a fire-and-forget to avoid errors, and waiting for the websocket connection to be re-established to avoid the browser attempting to reload when the server may not be up for a few seconds. Reviewed-on: https://onlyg.it/OpenWF/SpaceNinjaServer/pulls/2234 Co-authored-by: Sainan <63328889+Sainan@users.noreply.github.com> Co-committed-by: Sainan <63328889+Sainan@users.noreply.github.com>
6cdd103c
代码差异
4 个文件
+25
-10
@@ -28,8 +28,12 @@ function run(changedFile) {
28
28
runproc = undefined;
29
29
}
30
30
31
buildproc = spawn("npm", ["run", "build:dev"], { stdio: "inherit", shell: true });
31
const thisbuildproc = spawn("npm", ["run", "build:dev"], { stdio: "inherit", shell: true });
32
buildproc = thisbuildproc;
32
33
buildproc.on("exit", code => {
34
if (buildproc !== thisbuildproc) {
35
return;
36
}
33
37
buildproc = undefined;
34
38
if (code === 0) {
35
39
runproc = spawn("npm", ["run", "start", "--", ...args], { stdio: "inherit", shell: true });
@@ -44,6 +48,8 @@ run();
44
48
chokidar.watch("src").on("change", run);
45
49
chokidar.watch("static/fixed_responses").on("change", run);
46
50
47
chokidar.watch("static/webui").on("change", () => {
48
fetch("http://localhost/custom/webuiFileChangeDetected?secret=" + secret);
51
chokidar.watch("static/webui").on("change", async () => {
52
try {
53
await fetch("http://localhost/custom/webuiFileChangeDetected?secret=" + secret);
54
} catch (e) {}
49
55
});
@@ -1,11 +1,10 @@
1
1
import { args } from "@/src/helpers/commandLineArguments";
2
import { config } from "@/src/services/configService";
3
2
import { sendWsBroadcast } from "@/src/services/webService";
4
3
import { RequestHandler } from "express";
5
4
6
5
export const webuiFileChangeDetectedController: RequestHandler = (req, res) => {
7
6
if (args.dev && args.secret && req.query.secret == args.secret) {
8
sendWsBroadcast({ ports: { http: config.httpPort, https: config.httpsPort } });
7
sendWsBroadcast({ reload: true });
9
8
}
10
9
res.end();
11
10
};
@@ -110,6 +110,7 @@ interface IWsMsgFromClient {
110
110
}
111
111
112
112
interface IWsMsgToClient {
113
reload?: boolean;
113
114
ports?: {
114
115
http: number | undefined;
115
116
https: number | undefined;
@@ -9,9 +9,10 @@
9
9
/* eslint-disable @typescript-eslint/explicit-function-return-type */
10
10
11
11
let auth_pending = false,
12
did_initial_auth = false;
12
did_initial_auth = false,
13
ws_is_open = false;
13
14
const sendAuth = isRegister => {
14
if (localStorage.getItem("email") && localStorage.getItem("password")) {
15
if (ws_is_open && localStorage.getItem("email") && localStorage.getItem("password")) {
15
16
auth_pending = true;
16
17
window.ws.send(
17
18
JSON.stringify({
@@ -28,10 +29,18 @@ const sendAuth = isRegister => {
28
29
function openWebSocket() {
29
30
window.ws = new WebSocket("/custom/ws");
30
31
window.ws.onopen = () => {
32
ws_is_open = true;
31
33
sendAuth(false);
32
34
};
33
35
window.ws.onmessage = e => {
34
36
const msg = JSON.parse(e.data);
37
if ("reload" in msg) {
38
setTimeout(() => {
39
getWebSocket().then(() => {
40
location.reload();
41
});
42
}, 100);
43
}
35
44
if ("ports" in msg) {
36
45
location.port = location.protocol == "https:" ? msg.ports.https : msg.ports.http;
37
46
}
@@ -72,7 +81,7 @@ function openWebSocket() {
72
81
}
73
82
};
74
83
window.ws.onclose = function () {
75
window.ws = undefined;
84
ws_is_open = false;
76
85
setTimeout(openWebSocket, 3000);
77
86
};
78
87
}
@@ -82,7 +91,7 @@ function getWebSocket() {
82
91
return new Promise(resolve => {
83
92
let interval;
84
93
interval = setInterval(() => {
85
if (window.ws) {
94
if (ws_is_open) {
86
95
clearInterval(interval);
87
96
resolve(window.ws);
88
97
}
@@ -117,7 +126,7 @@ function logout() {
117
126
118
127
function doLogout() {
119
128
logout();
120
if (window.ws) {
129
if (ws_is_open) {
121
130
// Unsubscribe from notifications about nonce invalidation
122
131
window.ws.send(JSON.stringify({ logout: true }));
123
132
}