2024-05-28 16:43:25 +02:00
|
|
|
const { app, BrowserWindow } = require('electron/main');
|
|
|
|
|
const path = require('node:path');
|
|
|
|
|
const fs = require('fs');
|
|
|
|
|
// const http = require('http');
|
2024-05-28 14:25:32 +02:00
|
|
|
|
|
|
|
|
let config;
|
2024-05-28 16:43:25 +02:00
|
|
|
let win;
|
2024-05-28 14:25:32 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
function loadConfig() {
|
2024-05-28 16:43:25 +02:00
|
|
|
try {
|
|
|
|
|
const data = fs.readFileSync(path.join(__dirname, "config.json"), { encoding: 'utf8' });
|
2024-05-28 14:25:32 +02:00
|
|
|
config = JSON.parse(data);
|
2024-05-28 16:43:25 +02:00
|
|
|
} catch (err) {
|
|
|
|
|
console.log(err);
|
|
|
|
|
}
|
2024-05-28 14:25:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2024-05-28 16:43:25 +02:00
|
|
|
async function createWindow() {
|
|
|
|
|
win = new BrowserWindow({
|
2024-05-28 14:25:32 +02:00
|
|
|
width: 1920,
|
|
|
|
|
height: 1080,
|
2024-05-28 16:43:25 +02:00
|
|
|
backgroundColor: '#000000',
|
2024-05-28 14:25:32 +02:00
|
|
|
webPreferences: {
|
|
|
|
|
preload: path.join(__dirname, 'preload.js'),
|
|
|
|
|
nodeIntegration: true,
|
|
|
|
|
webSecurity: false,
|
|
|
|
|
},
|
|
|
|
|
show: false,
|
|
|
|
|
autoHideMenuBar: true
|
|
|
|
|
});
|
|
|
|
|
|
2024-05-28 16:43:25 +02:00
|
|
|
win.on("closed", function () {
|
|
|
|
|
win = null;
|
2024-05-28 14:25:32 +02:00
|
|
|
});
|
|
|
|
|
|
2024-05-28 16:43:25 +02:00
|
|
|
win.once("ready-to-show", () => {
|
|
|
|
|
win.setKiosk(true);
|
|
|
|
|
win.show();
|
2024-05-28 14:25:32 +02:00
|
|
|
});
|
|
|
|
|
|
2024-05-28 16:43:25 +02:00
|
|
|
win.loadFile('index.html');
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
let url = new URL(config.url);
|
|
|
|
|
// let options = {
|
|
|
|
|
// method: 'HEAD',
|
|
|
|
|
// host: url.hostname,
|
|
|
|
|
// port: url.port ? url.port : 80,
|
|
|
|
|
// path: '/'
|
|
|
|
|
// };
|
|
|
|
|
// let req = http.request(options, function (r) {
|
|
|
|
|
// console.log(r.headers);
|
|
|
|
|
// });
|
|
|
|
|
// req.end();
|
|
|
|
|
|
|
|
|
|
win.loadURL(config.url);
|
|
|
|
|
|
|
|
|
|
} catch (err) {
|
|
|
|
|
console.log(err);
|
|
|
|
|
} finally {
|
|
|
|
|
}
|
2024-05-28 14:25:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
app.whenReady().then(() => {
|
|
|
|
|
loadConfig();
|
|
|
|
|
createWindow();
|
|
|
|
|
|
|
|
|
|
app.on('activate', () => {
|
|
|
|
|
if (BrowserWindow.getAllWindows().length === 0) {
|
|
|
|
|
createWindow();
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
app.on('window-all-closed', () => {
|
2024-05-28 16:43:25 +02:00
|
|
|
app.quit()
|
2024-05-28 14:25:32 +02:00
|
|
|
});
|