fix: use mqtt last will #84

This commit is contained in:
leukipp
2025-10-07 09:59:48 +02:00
parent 5d012bd637
commit 19e51e349c
3 changed files with 22 additions and 7 deletions
+1 -1
View File
@@ -147,7 +147,7 @@ const init = async () => {
* Updates the shared hardware properties. * Updates the shared hardware properties.
*/ */
const update = async () => { const update = async () => {
if (!HARDWARE.initialized) { if (!HARDWARE.initialized || APP.exiting) {
return; return;
} }
+11 -1
View File
@@ -51,6 +51,7 @@ const init = async () => {
// Init options // Init options
const masked = password === null ? null : "*".repeat(password.length); const masked = password === null ? null : "*".repeat(password.length);
const options = user === null || password === null ? {} : { username: user, password: password }; 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); options.rejectUnauthorized = !("ignore_certificate_errors" in ARGS);
// Client connect // Client connect
@@ -109,17 +110,26 @@ const init = async () => {
// Update time sensors periodically (30s) // Update time sensors periodically (30s)
setInterval(() => { setInterval(() => {
if (APP.exiting) {
return;
}
updateHeartbeat(); updateHeartbeat();
updateLastActive(); updateLastActive();
}, 30 * 1000); }, 30 * 1000);
// Update system sensors periodically (1min) // Update system sensors periodically (1min)
setInterval(() => { setInterval(() => {
if (APP.exiting) {
return;
}
update(); update();
}, 60 * 1000); }, 60 * 1000);
// Update upgrade sensors periodically (1h) // Update upgrade sensors periodically (1h)
setInterval(() => { setInterval(() => {
if (APP.exiting) {
return;
}
updateApp(); updateApp();
updatePackageUpgrades(); updatePackageUpgrades();
}, 3600 * 1000); }, 3600 * 1000);
@@ -131,7 +141,7 @@ const init = async () => {
* Updates the shared integration properties. * Updates the shared integration properties.
*/ */
const update = async () => { const update = async () => {
if (!INTEGRATION.initialized) { if (!INTEGRATION.initialized || APP.exiting) {
return; return;
} }
+10 -5
View File
@@ -182,7 +182,7 @@ const init = async () => {
* Updates the shared webview properties. * Updates the shared webview properties.
*/ */
const update = async () => { const update = async () => {
if (!WEBVIEW.initialized) { if (!WEBVIEW.initialized || APP.exiting) {
return; return;
} }
@@ -642,12 +642,15 @@ const windowEvents = async () => {
// Check for window touch events (1s) // Check for window touch events (1s)
setInterval(() => { setInterval(() => {
if (APP.exiting) {
return;
}
const now = new Date(); const now = new Date();
const then = WEBVIEW.tracker.pointer.time; const then = WEBVIEW.tracker.pointer.time;
const delta = (now - then) / 1000; const delta = (now - then) / 1000;
// Auto-hide navigation // Auto-hide navigation
if (delta > 60 && WEBVIEW.tracker.status !== "Terminated") { if (delta > 60) {
toggleNavigation("OFF"); toggleNavigation("OFF");
} }
}, 1000); }, 1000);
@@ -997,9 +1000,8 @@ const appEvents = async () => {
// Handle exit events // Handle exit events
app.on("before-quit", () => { app.on("before-quit", () => {
WEBVIEW.tracker.status = "Terminated"; APP.exiting = true;
console.warn(`${APP.title} ${WEBVIEW.tracker.status}`); console.warn(`${APP.title} Terminated`);
integration.update();
}); });
process.on("SIGINT", app.quit); process.on("SIGINT", app.quit);
@@ -1008,6 +1010,9 @@ const appEvents = async () => {
// Check for latest release infos (2h) // Check for latest release infos (2h)
setInterval(() => { setInterval(() => {
if (APP.exiting) {
return;
}
latestRelease(); latestRelease();
}, 7200 * 1000); }, 7200 * 1000);
await latestRelease(); await latestRelease();