mirror of
https://github.com/saphid/frame-control.git
synced 2026-10-06 08:00:32 +02:00
App: overlapping restarts and server starts share one (review round 32)
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
a9740ad6f2
commit
72e4ccf080
1 file changed
+16
-7
+16
-7
@@ -184,12 +184,20 @@ function serverDied(why) {
|
|||||||
if (win) win.loadURL(errorPage(`The server stopped unexpectedly (${why}). See ${LOG}.`));
|
if (win) win.loadURL(errorPage(`The server stopped unexpectedly (${why}). See ${LOG}.`));
|
||||||
}
|
}
|
||||||
|
|
||||||
async function restartServer() {
|
// Restarts that overlap share one: two could each start a server, and the one
|
||||||
const old = server;
|
// that lost the lock would leave the app pointing at nothing.
|
||||||
server = null;
|
let restarting = null;
|
||||||
url = null;
|
function restartServer() {
|
||||||
if (old) await endServer(old);
|
if (!restarting) {
|
||||||
await load();
|
restarting = (async () => {
|
||||||
|
const old = server;
|
||||||
|
server = null;
|
||||||
|
url = null;
|
||||||
|
if (old) await endServer(old);
|
||||||
|
await load();
|
||||||
|
})().finally(() => { restarting = null; });
|
||||||
|
}
|
||||||
|
return restarting;
|
||||||
}
|
}
|
||||||
|
|
||||||
// On macOS the page's sticky header becomes the title bar, clear of the traffic lights.
|
// On macOS the page's sticky header becomes the title bar, clear of the traffic lights.
|
||||||
@@ -201,10 +209,11 @@ const CHROME_CSS = IS_MAC && `
|
|||||||
// Restart Server can start a new load while an older one is still waiting for
|
// Restart Server can start a new load while an older one is still waiting for
|
||||||
// its server; only the newest load may touch the window.
|
// its server; only the newest load may touch the window.
|
||||||
let loadGen = 0;
|
let loadGen = 0;
|
||||||
|
let starting = null; // loads that overlap share one server start
|
||||||
async function load() {
|
async function load() {
|
||||||
const gen = ++loadGen;
|
const gen = ++loadGen;
|
||||||
try {
|
try {
|
||||||
if (!url) await startServer();
|
if (!url) await (starting ||= startServer().finally(() => { starting = null; }));
|
||||||
if (gen === loadGen && win) { await win.loadURL(url); firstRunCheck(); }
|
if (gen === loadGen && win) { await win.loadURL(url); firstRunCheck(); }
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (gen === loadGen && win) await win.loadURL(errorPage(e.message));
|
if (gen === loadGen && win) await win.loadURL(errorPage(e.message));
|
||||||
|
|||||||
Reference in new issue
Block a user