From cbfd0538e7f4373d93e2096df33f3bd79401058b Mon Sep 17 00:00:00 2001 From: leukipp Date: Thu, 10 Jul 2025 20:54:32 +0200 Subject: [PATCH] feat: auto-hide navigation bar #45 --- js/integration.js | 7 ++++--- js/webview.js | 25 +++++++++++++++++++------ 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/js/integration.js b/js/integration.js index f9abd2a..4a1d383 100644 --- a/js/integration.js +++ b/js/integration.js @@ -20,6 +20,8 @@ const init = async () => { console.error("Please provide the '--mqtt-url' parameter with mqtt(s)"); return app.quit(); } + + // Parse arguments const url = new URL(ARGS.mqtt_url); const user = ARGS.mqtt_user ? ARGS.mqtt_user : null; const password = ARGS.mqtt_password ? ARGS.mqtt_password : null; @@ -30,14 +32,13 @@ const init = async () => { const hostName = hardware.getHostName(); const serialNumber = hardware.getSerialNumber(); const serialNumberSuffix = serialNumber.slice(-6); - - const deviceId = serialNumberSuffix.toUpperCase().replace(/[^A-Z0-9]/g, ""); const deviceName = hostName.charAt(0).toUpperCase() + hostName.slice(1); + const deviceId = serialNumberSuffix.toUpperCase().replace(/[^A-Z0-9]/g, ""); // Init globals + INTEGRATION.discovery = discovery; INTEGRATION.node = `rpi_${deviceId}`; INTEGRATION.root = `${app.getName()}/${INTEGRATION.node}`; - INTEGRATION.discovery = discovery; INTEGRATION.device = { name: `TouchKio ${deviceName}`, model: model, diff --git a/js/webview.js b/js/webview.js index d5ce237..05010f0 100644 --- a/js/webview.js +++ b/js/webview.js @@ -1,7 +1,7 @@ const path = require("path"); const hardware = require("./hardware"); const integration = require("./integration"); -const { app, screen, nativeTheme, ipcMain, BaseWindow, WebContentsView } = require("electron"); +const { app, screen, nativeTheme, ipcMain, session, BaseWindow, WebContentsView } = require("electron"); global.WEBVIEW = global.WEBVIEW || { initialized: false, @@ -27,6 +27,9 @@ const init = async () => { console.error("Please provide the '--web-url' parameter with http(s)"); return app.quit(); } + session.defaultSession.clearCache(); + + // Parse arguments const fullscreen = ARGS.app_debug !== "true"; const widget = ARGS.web_widget ? ARGS.web_widget === "true" : true; const zoom = !isNaN(parseFloat(ARGS.web_zoom)) ? parseFloat(ARGS.web_zoom) : 1.25; @@ -346,18 +349,28 @@ const windowEvents = () => { // Handle window touch events for activity tracking setInterval(() => { - const posOld = WEBVIEW.pointer.position; + const now = new Date(); + const then = WEBVIEW.pointer.time; + const delta = Math.abs(now - then) / 1000; const posNew = screen.getCursorScreenPoint(); + const posOld = WEBVIEW.pointer.position; + + // Cursor movement detected if (posOld.x !== posNew.x || posOld.y !== posNew.y) { - const now = new Date(); - const then = WEBVIEW.pointer.time; + WEBVIEW.pointer.time = now; // Update integration sensor - WEBVIEW.pointer.time = now; - if (Math.abs(now - then) / 1000 > 30) { + if (delta > 30) { console.log("Update Last Active"); integration.update(); } + } else if (delta > 60) { + const navigation = WEBVIEW.navigation.getBounds(); + + // Auto-hide navigation + if (navigation.height > 0) { + toggleNavigation(); + } } WEBVIEW.pointer.position = posNew; }, 1000);