mirror of
https://github.com/Pandipipas/scoreko-electron-dev.git
synced 2026-06-06 05:32:06 +00:00
feat(hardening): completar fase 3 con validación, navegación segura y shutdown
This commit is contained in:
+27
-6
@@ -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) => {
|
||||
|
||||
Reference in New Issue
Block a user