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 path = require('node:path');
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const os = require('os');
|
const os = require('os');
|
||||||
const log = require('electron-log/main');
|
const log = require('electron-log/main');
|
||||||
const { linkExists } = require('link-exists');
|
const { linkExists } = require('link-exists');
|
||||||
const { setInterval } = require('node:timers/promises');
|
const { setInterval } = require('node:timers/promises');
|
||||||
const { type } = require('node:os');
|
|
||||||
|
|
||||||
const isMac = process.platform === 'darwin';
|
const isMac = process.platform === 'darwin';
|
||||||
|
|
||||||
@@ -67,7 +66,7 @@ function loadConfig() {
|
|||||||
/**
|
/**
|
||||||
* Creates the browser window
|
* Creates the browser window
|
||||||
*/
|
*/
|
||||||
async function createWindow() {
|
function createWindow() {
|
||||||
win = new BrowserWindow({
|
win = new BrowserWindow({
|
||||||
width: 1920,
|
width: 1920,
|
||||||
height: 1080,
|
height: 1080,
|
||||||
@@ -104,7 +103,7 @@ async function createWindow() {
|
|||||||
|
|
||||||
// Load page from config file
|
// Load page from config file
|
||||||
if (config != undefined && 'url' in config) {
|
if (config != undefined && 'url' in config) {
|
||||||
testAndLoadUrl(config.url);
|
loadUrlAsync(config.url);
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
// Load file from data folder if available
|
// 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.
|
* Access is tried in a 1 second interval and the url is loaded if successfull.
|
||||||
* @param {string} testurl
|
* @param {string} testurl
|
||||||
*/
|
*/
|
||||||
function testAndLoadUrl(testurl) {
|
async function loadUrlAsync(testurl) {
|
||||||
try {
|
try {
|
||||||
let url = new URL(testurl);
|
let url = new URL(testurl);
|
||||||
// If it’s an online url, test whether it’s reachable
|
// If it’s an online url, test whether it’s reachable
|
||||||
let delay = 1;
|
if (['https:', 'http:', 'https', 'http'].includes(url.protocol) &&
|
||||||
if (['https:', 'http:', 'https', 'http'].includes(url.protocol)) {
|
!['127.0.0.1', 'localhost'].includes(url.host)) {
|
||||||
(async function () {
|
reachable = await linkExists(url.href);
|
||||||
for await (const startTime of setInterval(delay)) {
|
if (reachable) {
|
||||||
let reachable = linkExists(url.hostname);
|
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) {
|
if (reachable) {
|
||||||
log.info("Successfull access to " + url.hostname)
|
log.info("Successfull access to " + url.hostname);
|
||||||
log.info("Loading " + config.url)
|
log.info("Loading " + config.url);
|
||||||
win.loadURL(config.url);
|
win.loadURL(config.url);
|
||||||
// break the interval
|
// break the interval
|
||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
log.warn("Could not reach " + url.hostname);
|
log.warn("Could not reach " + url.hostname);
|
||||||
delay = 1000;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})();
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
// Load other protocols (i. e. offline) immedately
|
// Load other protocols (i. e. offline) immedately
|
||||||
else {
|
else {
|
||||||
@@ -233,4 +239,9 @@ app.on('window-all-closed', () => {
|
|||||||
|
|
||||||
app.on('quit', () => {
|
app.on('quit', () => {
|
||||||
log.info('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