feat(hardening): completar fase 3 con validación, navegación segura y shutdown

This commit is contained in:
Pandipipas
2026-02-21 18:46:32 +01:00
parent 50b145a320
commit 5c4ab5bed4
6 changed files with 172 additions and 14 deletions
+27 -6
View File
@@ -24,9 +24,11 @@ const nodecgManager = createNodecgProcessManager({
log,
});
type AppShutdownState = "running" | "stopping" | "stopped";
let mainWindow: BrowserWindow | null = null;
let loadingWindow: BrowserWindow | null = null;
let isQuitting = false;
let shutdownState: AppShutdownState = "running";
async function launch(): Promise<void> {
mainWindow = createMainWindow({ runtimeConfig, rootPath, dashboardUrl });
@@ -75,6 +77,22 @@ function closeLoadingWindow(): void {
loadingWindow = null;
}
function stopNodecgGracefully(): Promise<void> {
if (shutdownState === "stopped") {
return Promise.resolve();
}
if (shutdownState === "stopping") {
return nodecgManager.stopNodeCG();
}
shutdownState = "stopping";
return nodecgManager.stopNodeCG().finally(() => {
shutdownState = "stopped";
});
}
app.on("ready", () => {
app.setName(runtimeConfig.title);
@@ -104,24 +122,27 @@ app.on("window-all-closed", () => {
});
app.on("before-quit", (event) => {
if (isQuitting) {
if (shutdownState !== "running") {
return;
}
event.preventDefault();
isQuitting = true;
nodecgManager.stopNodeCG().finally(() => {
stopNodecgGracefully().finally(() => {
app.quit();
});
});
app.on("will-quit", () => {
void nodecgManager.stopNodeCG();
if (shutdownState === "running") {
void stopNodecgGracefully();
}
});
process.on("exit", () => {
void nodecgManager.stopNodeCG();
if (shutdownState === "running") {
void stopNodecgGracefully();
}
});
process.on("uncaughtException", (error) => {