fix: touch event handling for inactive screens #61
This commit is contained in:
@@ -6,9 +6,11 @@ const integration = require("./js/integration");
|
|||||||
const hardware = require("./js/hardware");
|
const hardware = require("./js/hardware");
|
||||||
const webview = require("./js/webview");
|
const webview = require("./js/webview");
|
||||||
const { app } = require("electron");
|
const { app } = require("electron");
|
||||||
|
const Events = require("events");
|
||||||
|
|
||||||
global.APP = global.APP || {};
|
global.APP = global.APP || {};
|
||||||
global.ARGS = global.ARGS || {};
|
global.ARGS = global.ARGS || {};
|
||||||
|
global.EVENTS = global.EVENTS || new Events();
|
||||||
|
|
||||||
if (!process.env.DISPLAY) {
|
if (!process.env.DISPLAY) {
|
||||||
console.error(`\n$DISPLAY variable not set to run the GUI application, are you connected via SSH?\n`);
|
console.error(`\n$DISPLAY variable not set to run the GUI application, are you connected via SSH?\n`);
|
||||||
|
|||||||
+5
-6
@@ -3,13 +3,11 @@ const fs = require("fs");
|
|||||||
const path = require("path");
|
const path = require("path");
|
||||||
const fsp = require("fs/promises");
|
const fsp = require("fs/promises");
|
||||||
const cpr = require("child_process");
|
const cpr = require("child_process");
|
||||||
const Events = require("events");
|
|
||||||
|
|
||||||
global.HARDWARE = global.HARDWARE || {
|
global.HARDWARE = global.HARDWARE || {
|
||||||
initialized: false,
|
initialized: false,
|
||||||
events: new Events(),
|
|
||||||
session: {},
|
|
||||||
support: {},
|
support: {},
|
||||||
|
session: {},
|
||||||
battery: {
|
battery: {
|
||||||
level: {
|
level: {
|
||||||
path: null,
|
path: null,
|
||||||
@@ -106,12 +104,13 @@ const init = async () => {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
HARDWARE.keyboard.visibility = property.Visible === "true";
|
HARDWARE.keyboard.visibility = property.Visible === "true";
|
||||||
HARDWARE.events.emit("updateKeyboard");
|
EVENTS.emit("updateKeyboard");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
// Check for display changes
|
// Check for display changes
|
||||||
interval(update, 1000);
|
interval(update, 1000);
|
||||||
|
setDisplayStatus("ON");
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
@@ -130,7 +129,7 @@ const update = async () => {
|
|||||||
if (status !== HARDWARE.display.status.value) {
|
if (status !== HARDWARE.display.status.value) {
|
||||||
console.log("Update Display Status:", getDisplayStatus());
|
console.log("Update Display Status:", getDisplayStatus());
|
||||||
HARDWARE.display.status.value = status;
|
HARDWARE.display.status.value = status;
|
||||||
HARDWARE.events.emit("updateDisplay");
|
EVENTS.emit("updateDisplay");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -140,7 +139,7 @@ const update = async () => {
|
|||||||
if (brightness !== HARDWARE.display.brightness.value) {
|
if (brightness !== HARDWARE.display.brightness.value) {
|
||||||
console.log("Update Display Brightness:", getDisplayBrightness());
|
console.log("Update Display Brightness:", getDisplayBrightness());
|
||||||
HARDWARE.display.brightness.value = brightness;
|
HARDWARE.display.brightness.value = brightness;
|
||||||
HARDWARE.events.emit("updateDisplay");
|
EVENTS.emit("updateDisplay");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
+14
-17
@@ -1,11 +1,9 @@
|
|||||||
const mqtt = require("mqtt");
|
const mqtt = require("mqtt");
|
||||||
const hardware = require("./hardware");
|
const hardware = require("./hardware");
|
||||||
const { app } = require("electron");
|
const { app } = require("electron");
|
||||||
const Events = require("events");
|
|
||||||
|
|
||||||
global.INTEGRATION = global.INTEGRATION || {
|
global.INTEGRATION = global.INTEGRATION || {
|
||||||
initialized: false,
|
initialized: false,
|
||||||
events: new Events(),
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -96,8 +94,8 @@ const init = async () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Update sensor states from events
|
// Update sensor states from events
|
||||||
HARDWARE.events.on("updateDisplay", updateDisplay);
|
EVENTS.on("updateDisplay", updateDisplay);
|
||||||
HARDWARE.events.on("updateKeyboard", updateKeyboard);
|
EVENTS.on("updateKeyboard", updateKeyboard);
|
||||||
|
|
||||||
// Update time sensors periodically (30s)
|
// Update time sensors periodically (30s)
|
||||||
setInterval(() => {
|
setInterval(() => {
|
||||||
@@ -307,7 +305,7 @@ const initRefresh = () => {
|
|||||||
if (topic === config.command_topic) {
|
if (topic === config.command_topic) {
|
||||||
console.log("Refreshing webview...");
|
console.log("Refreshing webview...");
|
||||||
hardware.setDisplayStatus("ON");
|
hardware.setDisplayStatus("ON");
|
||||||
WEBVIEW.events.emit("reloadView");
|
EVENTS.emit("reloadView");
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.subscribe(config.command_topic);
|
.subscribe(config.command_topic);
|
||||||
@@ -333,7 +331,6 @@ const initKiosk = () => {
|
|||||||
if (topic === config.command_topic) {
|
if (topic === config.command_topic) {
|
||||||
const status = message.toString();
|
const status = message.toString();
|
||||||
console.log("Set Kiosk Status:", status);
|
console.log("Set Kiosk Status:", status);
|
||||||
hardware.setDisplayStatus("ON");
|
|
||||||
switch (status) {
|
switch (status) {
|
||||||
case "Framed":
|
case "Framed":
|
||||||
WEBVIEW.window.restore();
|
WEBVIEW.window.restore();
|
||||||
@@ -368,7 +365,7 @@ const initKiosk = () => {
|
|||||||
* Updates the kiosk status via the mqtt connection.
|
* Updates the kiosk status via the mqtt connection.
|
||||||
*/
|
*/
|
||||||
const updateKiosk = async () => {
|
const updateKiosk = async () => {
|
||||||
const kiosk = WEBVIEW.status;
|
const kiosk = WEBVIEW.tracker.status;
|
||||||
publishState("kiosk", kiosk);
|
publishState("kiosk", kiosk);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -400,20 +397,20 @@ const initDisplay = () => {
|
|||||||
const status = message.toString();
|
const status = message.toString();
|
||||||
console.log("Set Display Status:", status);
|
console.log("Set Display Status:", status);
|
||||||
hardware.setDisplayStatus(status, (reply, error) => {
|
hardware.setDisplayStatus(status, (reply, error) => {
|
||||||
if (error) {
|
if (!error) {
|
||||||
console.warn("Failed:", error);
|
|
||||||
} else {
|
|
||||||
hardware.update();
|
hardware.update();
|
||||||
|
} else {
|
||||||
|
console.warn("Failed:", error);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else if (topic === config.brightness_command_topic) {
|
} else if (topic === config.brightness_command_topic) {
|
||||||
const brightness = parseInt(message, 10);
|
const brightness = parseInt(message, 10);
|
||||||
console.log("Set Display Brightness:", brightness);
|
console.log("Set Display Brightness:", brightness);
|
||||||
hardware.setDisplayBrightness(brightness, (reply, error) => {
|
hardware.setDisplayBrightness(brightness, (reply, error) => {
|
||||||
if (error) {
|
if (!error) {
|
||||||
console.warn("Failed:", error);
|
|
||||||
} else {
|
|
||||||
hardware.update();
|
hardware.update();
|
||||||
|
} else {
|
||||||
|
console.warn("Failed:", error);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -508,7 +505,7 @@ const initPageNumber = () => {
|
|||||||
const number = parseInt(message, 10);
|
const number = parseInt(message, 10);
|
||||||
console.log("Set Page Number:", number);
|
console.log("Set Page Number:", number);
|
||||||
WEBVIEW.viewActive = number || 1;
|
WEBVIEW.viewActive = number || 1;
|
||||||
WEBVIEW.events.emit("updateView");
|
EVENTS.emit("updateView");
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.subscribe(config.command_topic);
|
.subscribe(config.command_topic);
|
||||||
@@ -547,7 +544,7 @@ const initPageZoom = () => {
|
|||||||
const zoom = parseInt(message, 10);
|
const zoom = parseInt(message, 10);
|
||||||
console.log("Set Page Zoom:", zoom);
|
console.log("Set Page Zoom:", zoom);
|
||||||
WEBVIEW.views[WEBVIEW.viewActive || 1].webContents.setZoomFactor(zoom / 100.0);
|
WEBVIEW.views[WEBVIEW.viewActive || 1].webContents.setZoomFactor(zoom / 100.0);
|
||||||
WEBVIEW.events.emit("updateView");
|
EVENTS.emit("updateView");
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.subscribe(config.command_topic);
|
.subscribe(config.command_topic);
|
||||||
@@ -946,8 +943,8 @@ const initLastActive = () => {
|
|||||||
*/
|
*/
|
||||||
const updateLastActive = async () => {
|
const updateLastActive = async () => {
|
||||||
const now = new Date();
|
const now = new Date();
|
||||||
const then = WEBVIEW.pointer.time;
|
const then = WEBVIEW.tracker.pointer.time;
|
||||||
const lastActive = Math.abs(now - then) / (1000 * 60);
|
const lastActive = (now - then) / (1000 * 60);
|
||||||
publishState("last_active", lastActive);
|
publishState("last_active", lastActive);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
+44
-39
@@ -3,16 +3,16 @@ const axios = require("axios");
|
|||||||
const hardware = require("./hardware");
|
const hardware = require("./hardware");
|
||||||
const integration = require("./integration");
|
const integration = require("./integration");
|
||||||
const { app, nativeTheme, globalShortcut, ipcMain, session, BaseWindow, WebContentsView } = require("electron");
|
const { app, nativeTheme, globalShortcut, ipcMain, session, BaseWindow, WebContentsView } = require("electron");
|
||||||
const Events = require("events");
|
|
||||||
|
|
||||||
global.WEBVIEW = global.WEBVIEW || {
|
global.WEBVIEW = global.WEBVIEW || {
|
||||||
initialized: false,
|
initialized: false,
|
||||||
events: new Events(),
|
tracker: {
|
||||||
status: null,
|
pointer: {
|
||||||
locked: false,
|
position: {},
|
||||||
pointer: {
|
time: new Date(),
|
||||||
position: {},
|
},
|
||||||
time: new Date(),
|
display: {},
|
||||||
|
status: null,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -50,8 +50,6 @@ const init = async () => {
|
|||||||
WEBVIEW.navigationTheme = theme;
|
WEBVIEW.navigationTheme = theme;
|
||||||
WEBVIEW.navigationEnabled = widget;
|
WEBVIEW.navigationEnabled = widget;
|
||||||
nativeTheme.themeSource = WEBVIEW.viewTheme;
|
nativeTheme.themeSource = WEBVIEW.viewTheme;
|
||||||
WEBVIEW.events.on("reloadView", reloadView);
|
|
||||||
WEBVIEW.events.on("updateView", updateView);
|
|
||||||
|
|
||||||
// Init global root window
|
// Init global root window
|
||||||
WEBVIEW.window = new BaseWindow({
|
WEBVIEW.window = new BaseWindow({
|
||||||
@@ -118,7 +116,17 @@ const init = async () => {
|
|||||||
WEBVIEW.window.contentView.addChildView(WEBVIEW.navigation);
|
WEBVIEW.window.contentView.addChildView(WEBVIEW.navigation);
|
||||||
WEBVIEW.navigation.webContents.loadFile(path.join(APP.path, "html", "navigation.html"));
|
WEBVIEW.navigation.webContents.loadFile(path.join(APP.path, "html", "navigation.html"));
|
||||||
|
|
||||||
// Register events
|
// Register global events
|
||||||
|
EVENTS.on("reloadView", reloadView);
|
||||||
|
EVENTS.on("updateView", updateView);
|
||||||
|
EVENTS.on("updateDisplay", () => {
|
||||||
|
const status = hardware.getDisplayStatus();
|
||||||
|
if (status) {
|
||||||
|
WEBVIEW.tracker.display[status.toLowerCase()] = new Date();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Register local events
|
||||||
await windowEvents();
|
await windowEvents();
|
||||||
await widgetEvents();
|
await widgetEvents();
|
||||||
await navigationEvents();
|
await navigationEvents();
|
||||||
@@ -136,15 +144,15 @@ const update = async () => {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update windows status
|
// Update window status
|
||||||
if (WEBVIEW.window.isFullScreen()) {
|
if (WEBVIEW.window.isFullScreen()) {
|
||||||
WEBVIEW.status = "Fullscreen";
|
WEBVIEW.tracker.status = "Fullscreen";
|
||||||
} else if (WEBVIEW.window.isMinimized()) {
|
} else if (WEBVIEW.window.isMinimized()) {
|
||||||
WEBVIEW.status = "Minimized";
|
WEBVIEW.tracker.status = "Minimized";
|
||||||
} else if (WEBVIEW.window.isMaximized()) {
|
} else if (WEBVIEW.window.isMaximized()) {
|
||||||
WEBVIEW.status = "Maximized";
|
WEBVIEW.tracker.status = "Maximized";
|
||||||
} else {
|
} else {
|
||||||
WEBVIEW.status = "Framed";
|
WEBVIEW.tracker.status = "Framed";
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update widget status
|
// Update widget status
|
||||||
@@ -154,7 +162,7 @@ const update = async () => {
|
|||||||
updateNavigation();
|
updateNavigation();
|
||||||
|
|
||||||
// Update integration sensor
|
// Update integration sensor
|
||||||
console.log("Update Kiosk Status:", WEBVIEW.status);
|
console.log("Update Kiosk Status:", WEBVIEW.tracker.status);
|
||||||
integration.update();
|
integration.update();
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -434,21 +442,6 @@ const windowEvents = async () => {
|
|||||||
WEBVIEW.window.on("resize", resizeView);
|
WEBVIEW.window.on("resize", resizeView);
|
||||||
resizeView();
|
resizeView();
|
||||||
|
|
||||||
// Handle window focus events
|
|
||||||
WEBVIEW.window.on("focus", () => {
|
|
||||||
if (WEBVIEW.locked) {
|
|
||||||
hardware.setDisplayStatus("ON");
|
|
||||||
WEBVIEW.window.blur();
|
|
||||||
}
|
|
||||||
WEBVIEW.locked = false;
|
|
||||||
});
|
|
||||||
HARDWARE.events.on("updateDisplay", () => {
|
|
||||||
WEBVIEW.locked = hardware.getDisplayStatus() === "OFF";
|
|
||||||
if (WEBVIEW.locked) {
|
|
||||||
WEBVIEW.window.blur();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// Handle window status updates
|
// Handle window status updates
|
||||||
WEBVIEW.window.on("minimize", update);
|
WEBVIEW.window.on("minimize", update);
|
||||||
WEBVIEW.window.on("restore", update);
|
WEBVIEW.window.on("restore", update);
|
||||||
@@ -480,8 +473,8 @@ const windowEvents = async () => {
|
|||||||
// Check for window touch events (1s)
|
// Check for window touch events (1s)
|
||||||
setInterval(() => {
|
setInterval(() => {
|
||||||
const now = new Date();
|
const now = new Date();
|
||||||
const then = WEBVIEW.pointer.time;
|
const then = WEBVIEW.tracker.pointer.time;
|
||||||
const delta = Math.abs(now - then) / 1000;
|
const delta = (now - then) / 1000;
|
||||||
|
|
||||||
// Auto-hide navigation
|
// Auto-hide navigation
|
||||||
if (delta > 60) {
|
if (delta > 60) {
|
||||||
@@ -741,18 +734,19 @@ const viewEvents = async () => {
|
|||||||
// Handle webview mouse events
|
// Handle webview mouse events
|
||||||
view.webContents.on("before-mouse-event", (e, mouse) => {
|
view.webContents.on("before-mouse-event", (e, mouse) => {
|
||||||
const now = new Date();
|
const now = new Date();
|
||||||
const then = WEBVIEW.pointer.time;
|
const then = WEBVIEW.tracker.pointer.time;
|
||||||
const delta = Math.abs(now - then) / 1000;
|
const delta = (now - then) / 1000;
|
||||||
switch (mouse.type) {
|
switch (mouse.type) {
|
||||||
case "mouseMove":
|
case "mouseMove":
|
||||||
const posNew = { x: mouse.globalX, y: mouse.globalY };
|
const posNew = { x: mouse.globalX, y: mouse.globalY };
|
||||||
if (posNew.x < 0 || posNew.y < 0) {
|
if (posNew.x < 0 || posNew.y < 0) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
const posOld = WEBVIEW.pointer.position;
|
// Update last active on pointer position change
|
||||||
|
const posOld = WEBVIEW.tracker.pointer.position;
|
||||||
if (posOld.x !== posNew.x || posOld.y !== posNew.y) {
|
if (posOld.x !== posNew.x || posOld.y !== posNew.y) {
|
||||||
WEBVIEW.pointer.time = now;
|
WEBVIEW.tracker.pointer.time = now;
|
||||||
WEBVIEW.pointer.position = posNew;
|
WEBVIEW.tracker.pointer.position = posNew;
|
||||||
if (delta > 30) {
|
if (delta > 30) {
|
||||||
console.log("Update Last Active");
|
console.log("Update Last Active");
|
||||||
integration.update();
|
integration.update();
|
||||||
@@ -761,6 +755,17 @@ const viewEvents = async () => {
|
|||||||
break;
|
break;
|
||||||
case "mouseDown":
|
case "mouseDown":
|
||||||
switch (mouse.button) {
|
switch (mouse.button) {
|
||||||
|
case "left":
|
||||||
|
// Ignore touch event if display was off
|
||||||
|
if (WEBVIEW.tracker.display.off > WEBVIEW.tracker.display.on) {
|
||||||
|
console.log("Display Touch Event: Ignored");
|
||||||
|
e.preventDefault();
|
||||||
|
}
|
||||||
|
// Turn display on if it was off
|
||||||
|
if (hardware.getDisplayStatus() === "OFF") {
|
||||||
|
hardware.setDisplayStatus("ON");
|
||||||
|
}
|
||||||
|
break;
|
||||||
case "back":
|
case "back":
|
||||||
historyBackward();
|
historyBackward();
|
||||||
break;
|
break;
|
||||||
@@ -781,7 +786,7 @@ const appEvents = async () => {
|
|||||||
// Handle signal and exit events
|
// Handle signal and exit events
|
||||||
process.on("SIGINT", app.quit);
|
process.on("SIGINT", app.quit);
|
||||||
app.on("before-quit", () => {
|
app.on("before-quit", () => {
|
||||||
WEBVIEW.status = "Terminated";
|
WEBVIEW.tracker.status = "Terminated";
|
||||||
integration.update();
|
integration.update();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user