feat: auto-hide navigation bar #45

This commit is contained in:
leukipp
2025-07-10 20:54:32 +02:00
parent d3af6d397e
commit cbfd0538e7
2 changed files with 23 additions and 9 deletions
+4 -3
View File
@@ -20,6 +20,8 @@ const init = async () => {
console.error("Please provide the '--mqtt-url' parameter with mqtt(s)"); console.error("Please provide the '--mqtt-url' parameter with mqtt(s)");
return app.quit(); return app.quit();
} }
// Parse arguments
const url = new URL(ARGS.mqtt_url); const url = new URL(ARGS.mqtt_url);
const user = ARGS.mqtt_user ? ARGS.mqtt_user : null; const user = ARGS.mqtt_user ? ARGS.mqtt_user : null;
const password = ARGS.mqtt_password ? ARGS.mqtt_password : null; const password = ARGS.mqtt_password ? ARGS.mqtt_password : null;
@@ -30,14 +32,13 @@ const init = async () => {
const hostName = hardware.getHostName(); const hostName = hardware.getHostName();
const serialNumber = hardware.getSerialNumber(); const serialNumber = hardware.getSerialNumber();
const serialNumberSuffix = serialNumber.slice(-6); const serialNumberSuffix = serialNumber.slice(-6);
const deviceId = serialNumberSuffix.toUpperCase().replace(/[^A-Z0-9]/g, "");
const deviceName = hostName.charAt(0).toUpperCase() + hostName.slice(1); const deviceName = hostName.charAt(0).toUpperCase() + hostName.slice(1);
const deviceId = serialNumberSuffix.toUpperCase().replace(/[^A-Z0-9]/g, "");
// Init globals // Init globals
INTEGRATION.discovery = discovery;
INTEGRATION.node = `rpi_${deviceId}`; INTEGRATION.node = `rpi_${deviceId}`;
INTEGRATION.root = `${app.getName()}/${INTEGRATION.node}`; INTEGRATION.root = `${app.getName()}/${INTEGRATION.node}`;
INTEGRATION.discovery = discovery;
INTEGRATION.device = { INTEGRATION.device = {
name: `TouchKio ${deviceName}`, name: `TouchKio ${deviceName}`,
model: model, model: model,
+19 -6
View File
@@ -1,7 +1,7 @@
const path = require("path"); const path = require("path");
const hardware = require("./hardware"); const hardware = require("./hardware");
const integration = require("./integration"); 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 || { global.WEBVIEW = global.WEBVIEW || {
initialized: false, initialized: false,
@@ -27,6 +27,9 @@ const init = async () => {
console.error("Please provide the '--web-url' parameter with http(s)"); console.error("Please provide the '--web-url' parameter with http(s)");
return app.quit(); return app.quit();
} }
session.defaultSession.clearCache();
// Parse arguments
const fullscreen = ARGS.app_debug !== "true"; const fullscreen = ARGS.app_debug !== "true";
const widget = ARGS.web_widget ? ARGS.web_widget === "true" : true; const widget = ARGS.web_widget ? ARGS.web_widget === "true" : true;
const zoom = !isNaN(parseFloat(ARGS.web_zoom)) ? parseFloat(ARGS.web_zoom) : 1.25; 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 // Handle window touch events for activity tracking
setInterval(() => { setInterval(() => {
const posOld = WEBVIEW.pointer.position;
const posNew = screen.getCursorScreenPoint();
if (posOld.x !== posNew.x || posOld.y !== posNew.y) {
const now = new Date(); const now = new Date();
const then = WEBVIEW.pointer.time; 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) {
WEBVIEW.pointer.time = now;
// Update integration sensor // Update integration sensor
WEBVIEW.pointer.time = now; if (delta > 30) {
if (Math.abs(now - then) / 1000 > 30) {
console.log("Update Last Active"); console.log("Update Last Active");
integration.update(); integration.update();
} }
} else if (delta > 60) {
const navigation = WEBVIEW.navigation.getBounds();
// Auto-hide navigation
if (navigation.height > 0) {
toggleNavigation();
}
} }
WEBVIEW.pointer.position = posNew; WEBVIEW.pointer.position = posNew;
}, 1000); }, 1000);