Skip to content

Commit

Permalink
SDA-4450 pod load failure should retry loading pod URL from config (f…
Browse files Browse the repository at this point in the history
…inos#2069)

* SDA-4450 pod load failure should retry loading pod URL from config

* Upgrade electron@28.1.3

* SDA-4450 Fix wrong regex on pod url check
  • Loading branch information
sbenmoussati authored Jan 15, 2024
1 parent b862bd5 commit bafe626
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 15 deletions.
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@
"builder-util-runtime": "^9.0.3",
"cross-env": "7.0.3",
"del": "3.0.0",
"electron": "^27.2.0",
"electron": "^28.1.3",
"electron-builder": "^24.2.1",
"electron-icon-maker": "0.0.5",
"electron-osx-sign": "^0.6.0",
Expand Down
12 changes: 5 additions & 7 deletions src/app/window-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ import {
initSysTray,
injectStyles,
isSymphonyReachable,
isValidUrl,
loadBrowserViews,
monitorNetworkInterception,
preventWindowNavigation,
Expand Down Expand Up @@ -130,8 +131,6 @@ export const IS_NODE_INTEGRATION_ENABLED: boolean = false;
export const AUX_CLICK = 'Auxclick';
// Timeout on restarting SDA in case it's stuck
const LISTEN_TIMEOUT: number = 25 * 1000;

const HOSTNAME_REGEX = /^[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/;
export class WindowHandler {
/**
* Verifies if the url is valid and
Expand Down Expand Up @@ -2193,14 +2192,14 @@ export class WindowHandler {
);
const userAgent = this.getUserAgent(this.mainWebContents);
const urlFromConfig = config.getUserConfigFields(['url']);
const isValidUrl =
HOSTNAME_REGEX.test(urlFromConfig.url || '') ||
const isPodUrlValid =
isValidUrl(urlFromConfig.url || '') ||
urlFromConfig.url.includes('https://local-dev.symphony.com');

await this.mainWebContents.loadURL(
this.cmdUrl
? this.cmdUrl
: isValidUrl
: isPodUrlValid
? urlFromConfig.url
: this.globalConfig.url,
{
Expand Down Expand Up @@ -2392,8 +2391,7 @@ export class WindowHandler {
logger.info(
`window-handler: Current main window url is ${webContentsUrl}.`,
);
const reloadUrl =
webContentsUrl || this.userConfig.url || this.globalConfig.url;
const reloadUrl = this.userConfig.url || this.globalConfig.url;
logger.info(`window-handler: Trying to reload ${reloadUrl}.`);
const userAgent = this.getUserAgent(this.mainWebContents);
await this.mainWebContents.loadURL(reloadUrl, { userAgent });
Expand Down
8 changes: 8 additions & 0 deletions src/app/window-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1458,3 +1458,11 @@ export const hideFullscreenWindow = (window: BrowserWindow) => {
});
window.setFullScreen(false);
};

export const isValidUrl = (text: string): false | URL => {
try {
return new URL(text);
} catch (err) {
return false;
}
};

0 comments on commit bafe626

Please sign in to comment.