Skip to content
This repository has been archived by the owner on Jan 19, 2023. It is now read-only.

Commit

Permalink
Removed the retry logic, improved messaging
Browse files Browse the repository at this point in the history
Signed-off-by: Milan Klanjsek <[email protected]>
  • Loading branch information
mklanjsek committed Feb 10, 2021
1 parent 91c4b3a commit f30f68f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 26 deletions.
41 changes: 21 additions & 20 deletions web/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ let tray = null;

const args = process.argv.slice(1);
const local = args.some(val => val === '--local');
const defaultRetries = 5;
let numberRetries= defaultRetries;

const applicationMenu = new ApplicationMenu();
Menu.setApplicationMenu(applicationMenu.menu);
Expand All @@ -48,18 +46,8 @@ function saveBoundsSoon() {
}, 1000);
}

function loadFrontend() {
numberRetries--;
if (electronStore.get('development').embedded || numberRetries < 0) {
if(numberRetries < 0) {
const alertOptions: MessageBoxOptions = {
type: 'warning',
buttons: ['OK'],
message: `Reverted to Embedded Frontend because the Frontend proxy Url is not reachable.`,
detail: 'Make sure the front end service is running on Frontend proxy Url.',
};
dialog.showMessageBoxSync(win, alertOptions);
}
function loadFrontend(embedded:boolean) {
if (embedded) {
win.loadFile(path.join(__dirname, 'dist/octant/index.html'));
} else {
win.loadURL(electronStore.get('development').frontendUrl);
Expand Down Expand Up @@ -114,12 +102,26 @@ function createWindow(): BrowserWindow {
win.webContents.openDevTools();
}

numberRetries= defaultRetries;
loadFrontend();
loadFrontend(electronStore.get('development').embedded);

win.webContents.on('did-fail-load', () => {
loadFrontend();
});
const alertOptions: MessageBoxOptions = {
type: 'warning',
buttons: ['Retry','Cancel'],
message: `Reverted to Embedded Frontend because the Frontend proxy URL is unreachable.`,
detail: `Please ensure the frontend service is running at ${electronStore.store.development.frontendUrl}.`,
};
const result = dialog.showMessageBoxSync(win, alertOptions);
switch (result) {
case 0:
loadFrontend(false);
break;
case 1:
loadFrontend(true);
break;
}
}
);

win.webContents.on('new-window', (event, url: string) => {
event.preventDefault();
Expand Down Expand Up @@ -267,8 +269,7 @@ try {

ipcMain.on('preferences', (event, args) => {
if(args === 'changed') {
numberRetries= defaultRetries;
loadFrontend();
loadFrontend(electronStore.get('development').embedded);
}
});
} catch (e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* SPDX-License-Identifier: Apache-2.0
*/

import { Injectable, isDevMode, OnDestroy } from '@angular/core';
import { Injectable, OnDestroy } from '@angular/core';
import { BehaviorSubject, Subscription } from 'rxjs';
import {
Operation,
Expand Down Expand Up @@ -159,17 +159,16 @@ export class PreferencesService implements OnDestroy {
this.verbose.next(verbose);
}

if (isDevMode() && this.isElectron() && notificationRequired) {
if (this.isElectron() && notificationRequired) {
const ipcRenderer = window.require('electron').ipcRenderer;
ipcRenderer.send('preferences', 'changed');
}
}

public getPreferences(): Preferences {
const panels: PreferencePanel[] =
isDevMode() && this.isElectron()
? [this.getGeneralPanels(), this.getDeveloperPanels()]
: [this.getGeneralPanels()];
const panels: PreferencePanel[] = this.isElectron()
? [this.getGeneralPanels(), this.getDeveloperPanels()]
: [this.getGeneralPanels()];

return {
updateName: 'generalPreferences',
Expand Down

0 comments on commit f30f68f

Please sign in to comment.