fix wrong check for url
This commit is contained in:
@@ -1,11 +1,10 @@
|
||||
const { app, BrowserWindow, nativeTheme, Menu, MenuItem, globalShortcut } = require('electron/main');
|
||||
const { app, BrowserWindow, 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 { setInterval } = require('node:timers/promises');
|
||||
const { type } = require('node:os');
|
||||
|
||||
const isMac = process.platform === 'darwin';
|
||||
|
||||
@@ -67,7 +66,7 @@ function loadConfig() {
|
||||
/**
|
||||
* Creates the browser window
|
||||
*/
|
||||
async function createWindow() {
|
||||
function createWindow() {
|
||||
win = new BrowserWindow({
|
||||
width: 1920,
|
||||
height: 1080,
|
||||
@@ -104,7 +103,7 @@ async function createWindow() {
|
||||
|
||||
// Load page from config file
|
||||
if (config != undefined && 'url' in config) {
|
||||
testAndLoadUrl(config.url);
|
||||
loadUrlAsync(config.url);
|
||||
} else {
|
||||
try {
|
||||
// Load file from data folder if available
|
||||
@@ -169,27 +168,34 @@ function validateDomain(event) {
|
||||
* Access is tried in a 1 second interval and the url is loaded if successfull.
|
||||
* @param {string} testurl
|
||||
*/
|
||||
function testAndLoadUrl(testurl) {
|
||||
async function loadUrlAsync(testurl) {
|
||||
try {
|
||||
let url = new URL(testurl);
|
||||
// If it’s an online url, test whether it’s reachable
|
||||
let delay = 1;
|
||||
if (['https:', 'http:', 'https', 'http'].includes(url.protocol)) {
|
||||
(async function () {
|
||||
for await (const startTime of setInterval(delay)) {
|
||||
let reachable = linkExists(url.hostname);
|
||||
if (['https:', 'http:', 'https', 'http'].includes(url.protocol) &&
|
||||
!['127.0.0.1', 'localhost'].includes(url.host)) {
|
||||
reachable = await linkExists(url.href);
|
||||
if (reachable) {
|
||||
log.info("Successfull access to " + url.hostname);
|
||||
log.info("Loading " + config.url);
|
||||
win.loadURL(config.url);
|
||||
} else {
|
||||
log.warn("Could not reach " + url.hostname);
|
||||
|
||||
for await (_ of setInterval(1000)) {
|
||||
reachable = await linkExists(url.href);
|
||||
if (reachable) {
|
||||
log.info("Successfull access to " + url.hostname)
|
||||
log.info("Loading " + config.url)
|
||||
log.info("Successfull access to " + url.hostname);
|
||||
log.info("Loading " + config.url);
|
||||
win.loadURL(config.url);
|
||||
// break the interval
|
||||
break;
|
||||
} else {
|
||||
log.warn("Could not reach " + url.hostname);
|
||||
delay = 1000;
|
||||
}
|
||||
}
|
||||
})();
|
||||
}
|
||||
|
||||
}
|
||||
// Load other protocols (i. e. offline) immedately
|
||||
else {
|
||||
@@ -234,3 +240,8 @@ app.on('window-all-closed', () => {
|
||||
app.on('quit', () => {
|
||||
log.info('Quit');
|
||||
});
|
||||
|
||||
// prevent error dialogs in case of exceptions
|
||||
process.on('uncaughtException', function (error) {
|
||||
log.error(error);
|
||||
});
|
||||
Reference in New Issue
Block a user