From 19e51e349cbc196c571d9329f1df1d3f0e032abd Mon Sep 17 00:00:00 2001 From: leukipp Date: Tue, 7 Oct 2025 09:59:48 +0200 Subject: [PATCH] fix: use mqtt last will #84 --- js/hardware.js | 2 +- js/integration.js | 12 +++++++++++- js/webview.js | 15 ++++++++++----- 3 files changed, 22 insertions(+), 7 deletions(-) diff --git a/js/hardware.js b/js/hardware.js index 1a06e12..e300118 100644 --- a/js/hardware.js +++ b/js/hardware.js @@ -147,7 +147,7 @@ const init = async () => { * Updates the shared hardware properties. */ const update = async () => { - if (!HARDWARE.initialized) { + if (!HARDWARE.initialized || APP.exiting) { return; } diff --git a/js/integration.js b/js/integration.js index b0db05c..58748b1 100644 --- a/js/integration.js +++ b/js/integration.js @@ -51,6 +51,7 @@ const init = async () => { // Init options const masked = password === null ? null : "*".repeat(password.length); const options = user === null || password === null ? {} : { username: user, password: password }; + options.will = { topic: `${INTEGRATION.root}/kiosk/state`, payload: "Terminated", qos: 1, retain: true }; options.rejectUnauthorized = !("ignore_certificate_errors" in ARGS); // Client connect @@ -109,17 +110,26 @@ const init = async () => { // Update time sensors periodically (30s) setInterval(() => { + if (APP.exiting) { + return; + } updateHeartbeat(); updateLastActive(); }, 30 * 1000); // Update system sensors periodically (1min) setInterval(() => { + if (APP.exiting) { + return; + } update(); }, 60 * 1000); // Update upgrade sensors periodically (1h) setInterval(() => { + if (APP.exiting) { + return; + } updateApp(); updatePackageUpgrades(); }, 3600 * 1000); @@ -131,7 +141,7 @@ const init = async () => { * Updates the shared integration properties. */ const update = async () => { - if (!INTEGRATION.initialized) { + if (!INTEGRATION.initialized || APP.exiting) { return; } diff --git a/js/webview.js b/js/webview.js index 57ef327..53b7198 100644 --- a/js/webview.js +++ b/js/webview.js @@ -182,7 +182,7 @@ const init = async () => { * Updates the shared webview properties. */ const update = async () => { - if (!WEBVIEW.initialized) { + if (!WEBVIEW.initialized || APP.exiting) { return; } @@ -642,12 +642,15 @@ const windowEvents = async () => { // Check for window touch events (1s) setInterval(() => { + if (APP.exiting) { + return; + } const now = new Date(); const then = WEBVIEW.tracker.pointer.time; const delta = (now - then) / 1000; // Auto-hide navigation - if (delta > 60 && WEBVIEW.tracker.status !== "Terminated") { + if (delta > 60) { toggleNavigation("OFF"); } }, 1000); @@ -997,9 +1000,8 @@ const appEvents = async () => { // Handle exit events app.on("before-quit", () => { - WEBVIEW.tracker.status = "Terminated"; - console.warn(`${APP.title} ${WEBVIEW.tracker.status}`); - integration.update(); + APP.exiting = true; + console.warn(`${APP.title} Terminated`); }); process.on("SIGINT", app.quit); @@ -1008,6 +1010,9 @@ const appEvents = async () => { // Check for latest release infos (2h) setInterval(() => { + if (APP.exiting) { + return; + } latestRelease(); }, 7200 * 1000); await latestRelease();