Skip to content

Commit

Permalink
Fix Issue #1 Alt not working if URL is not correct
Browse files Browse the repository at this point in the history
  • Loading branch information
jessenic committed Nov 5, 2024
1 parent 241aadd commit 375ba67
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
2 changes: 1 addition & 1 deletion electron/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "twincat-hmi-browser",
"version": "1.0.4",
"version": "1.0.5",
"description": "A fullscreen-only browser for TwinCAT HMI applications based on Electron",
"scripts": {
"start": "tsc && electron-forge start",
Expand Down
15 changes: 12 additions & 3 deletions electron/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ function createWindow(): BrowserWindow {
menu.append(new MenuItem({
label: 'Start page',
//accelerator: 'CommandOrControl+Shift+I',
click: () => mainWindow.loadURL(appSettings.startUrl)
click: () => { if (isValidUrl(appSettings.startUrl)) mainWindow.loadURL(appSettings.startUrl) }
}));


Expand All @@ -59,10 +59,10 @@ function createWindow(): BrowserWindow {
mainWindow.setMenu(menu);

// Load settings page if startUrl is empty
if (appSettings.startUrl == "") {
if (appSettings.startUrl.trim() == "" || !isValidUrl(appSettings.startUrl)) {
openSettings(mainWindow, mainWindow);
mainWindow.loadURL("about:blank");
} else {
// Load the page
mainWindow.loadURL(appSettings.startUrl);
}
ipcMain.handle('settings-get', function (event, data) {
Expand All @@ -87,6 +87,15 @@ function createWindow(): BrowserWindow {
return mainWindow;
}

function isValidUrl(url: string): boolean {
try {
new URL(url);
return true;
} catch (e) {
return false;
}
}

function openSettings(mainWindow: BrowserWindow, currentWindow: BrowserWindow) {

if (currentWindow != mainWindow) {
Expand Down

0 comments on commit 375ba67

Please sign in to comment.