Add an ipc to reset the Tooloop Control Centre watchdog.

This commit is contained in:
vollstock committed 2026-10-20 10:50:40 +02:00
1 parent 9ab66b4f12
commit 70f3e98a09
5 files changed
+246 -7

No files matched your search

+31 -6
View File
@@ -1,4 +1,4 @@
const { app, BrowserWindow, nativeTheme, Menu, MenuItem } = require('electron/main');
const { app, BrowserWindow, nativeTheme, Menu, MenuItem, ipcMain } = require('electron/main');
const path = require('node:path');
const { fileURLToPath } = require('node:url');
const fs = require('fs');
@@ -7,6 +7,7 @@ const { default: isReachable } = require('is-reachable');
const { setTimeout: delay } = require('node:timers/promises');
const config = require('./js/config.js');
const { Config } = require('./js/config.js');
const { isAuthorizedWatchdogEvent: isWatchdogEventAuthorized, registerWatchdogHandler } = require('./js/watchdog.js');
//------------------------------------------------------------------------------
@@ -163,30 +164,53 @@ function createMenu() {
* @returns `true` if the url is allowed, `false` otherwise
*/
function validateDomain(event) {
if (isUrlAllowed(event.url)) return true;
event.preventDefault();
log.info("Navigation to " + event.url + " prevented");
return false;
}
function isUrlAllowed(urlString) {
if (config == undefined || config.data == undefined) return true;
let url = new URL(event.url);
let url;
try {
url = new URL(urlString);
} catch {
return false;
}
// allow local urls
if (['file:', 'file'].includes(url.protocol)) return true;
if ('whitelist' in config.data &&
Array.isArray(config.data.whitelist) &&
config.data.whitelist.length > 0 &&
!config.data.whitelist.includes(url.hostname)) {
event.preventDefault();
log.info("Navigation to " + event.url + " prevented");
return false;
}
return true;
}
function isAuthorizedWatchdogEvent(event) {
return isWatchdogEventAuthorized(event, win, isUrlAllowed);
}
function logWatchdogError(error) {
log.warn('Watchdog reset failed: ' + (error?.message || error));
}
function registerWatchdogBridge() {
registerWatchdogHandler(ipcMain, {
isAuthorized: isAuthorizedWatchdogEvent,
onError: logWatchdogError
});
}
/**
* Tests if the host of the url is reachable.
* Access is tried in a 1 second interval and the url is loaded if successfull.
* @param {string} testurl
* @param {string} testurl
*/
async function loadUrlAsync(testurl) {
const request = ++navigationRequest;
@@ -299,6 +323,7 @@ app.whenReady().then(() => {
log.info('Starting Tooloop Kiosk Browser...');
log.info('Logging to ' + log.transports.file.resolvePathFn());
registerWatchdogBridge();
createMenu();
createMainWindow();
});