arg, forgotten files…

This commit is contained in:
2024-06-03 12:16:11 +02:00
parent 0b76d1a624
commit 0a7f5407d8
7 changed files with 1283 additions and 2747 deletions
+47 -15
View File
@@ -1,10 +1,12 @@
const { app, BrowserWindow, nativeTheme, Menu, MenuItem } = require('electron/main');
const { app, BrowserWindow, BaseWindow, nativeTheme, Menu, MenuItem } = require('electron/main');
const path = require('node:path');
const fs = require('fs');
const os = require('os');
const log = require('electron-log/main');
const { linkExists } = require('link-exists');
const isReachable = require('is-reachable');
const { setInterval } = require('node:timers/promises');
const configModule = require('./js/config.js');
const isMac = process.platform === 'darwin';
@@ -13,6 +15,7 @@ const isMac = process.platform === 'darwin';
//------------------------------------------------------------------------------
let config;
let configWindow;
let win;
let menu;
@@ -66,7 +69,7 @@ function loadConfig() {
/**
* Creates the browser window
*/
function createWindow() {
function createMainWindow() {
win = new BrowserWindow({
width: 1920,
height: 1080,
@@ -74,7 +77,7 @@ function createWindow() {
icon: 'images/icon-512.png',
autoHideMenuBar: true,
webPreferences: {
preload: path.join(__dirname, 'preload.js'),
preload: path.join(__dirname, './js/preload.js'),
webSecurity: false,
disableDialogs: true
},
@@ -95,12 +98,13 @@ function createWindow() {
}
return { action: 'deny' };
});
win.on("page-title-updated", (event) => event.preventDefault());
// show black window
win.setKiosk(true);
// show initial black window
// win.setKiosk(true);
win.show();
// Load page from config file
if (config != undefined && 'url' in config) {
loadUrlAsync(config.url);
@@ -111,11 +115,27 @@ function createWindow() {
win.loadFile('/assets/data/index.html');
} catch {
// Load fallback page
win.loadFile('index.html');
win.loadFile('./html/onboarding.html');
}
}
}
/**
* Creates a modal config view and attaches as to the main window
*/
function createConfigWindow() {
configWindow = new BrowserWindow({
parent: win,
modal: true,
width: 640,
height: 460,
show: false,
backgroundColor: '#1f1f1f'
});
configWindow.loadFile('./html/config.html');
}
/**
* Creates all available keyboard shortcuts
@@ -131,8 +151,13 @@ function createMenu() {
accelerator: isMac ? 'Cmd+F' : 'Ctrl+F',
click: () => { win.setKiosk(!win.kiosk); }
},
{ role: 'reload', },
{ role: 'quit', }
{ role: 'reload' },
{ role: 'quit' },
{
label: 'Config',
accelerator: isMac ? 'Cmd+,' : 'Ctrl+,',
click: () => { configWindow.isVisible() ? configWindow.hide() : configWindow.show(); }
}
]
}));
@@ -172,9 +197,9 @@ async function loadUrlAsync(testurl) {
try {
let url = new URL(testurl);
// If its an online url, test whether its reachable
if (['https:', 'http:', 'https', 'http'].includes(url.protocol) &&
!['127.0.0.1', 'localhost'].includes(url.host)) {
reachable = await linkExists(url.href);
if (['https:', 'http:', 'https', 'http'].includes(url.protocol)) {
reachable = await isReachable(url.href);
if (reachable) {
log.info("Successfull access to " + url.hostname);
log.info("Loading " + config.url);
@@ -183,7 +208,7 @@ async function loadUrlAsync(testurl) {
log.warn("Could not reach " + url.hostname);
for await (_ of setInterval(1000)) {
reachable = await linkExists(url.href);
reachable = await isReachable(url.href);
if (reachable) {
log.info("Successfull access to " + url.hostname);
log.info("Loading " + config.url);
@@ -194,6 +219,7 @@ async function loadUrlAsync(testurl) {
log.warn("Could not reach " + url.hostname);
}
}
}
}
@@ -212,7 +238,12 @@ async function loadUrlAsync(testurl) {
// Init electron app
//------------------------------------------------------------------------------
// https://github.com/electron/electron/issues/17972
app.commandLine.appendSwitch('--no-sandbox');
app.whenReady().then(() => {
// configModule.load();
console.log(configModule.config);
loadConfig();
log.initialize();
@@ -224,12 +255,13 @@ app.whenReady().then(() => {
log.info('Starting Tooloop Kiosk Browser...');
createMenu();
createWindow();
createMainWindow();
createConfigWindow()
});
app.on('activate', () => {
if (BrowserWindow.getAllWindows().length === 0) {
createWindow();
createMainWindow();
}
})