Electron-217

Added a warning dialog
Updated to read method to read only from global config
This commit is contained in:
Kiran Niranjan 2017-12-21 12:53:57 +05:30 committed by Kiran Niranjan
parent d7f62a38b0
commit 919882a5b3
3 changed files with 18 additions and 8 deletions

View File

@ -425,6 +425,9 @@ module.exports = {
saveUserConfig, saveUserConfig,
clearCachedConfigs, clearCachedConfigs,
readConfigFileSync readConfigFileSync,
// use only if you specifically need to read global config fields
getGlobalConfigField,
}; };

View File

@ -1,6 +1,6 @@
'use strict'; 'use strict';
const { getConfigField } = require('./../config.js'); const { getGlobalConfigField } = require('./../config.js');
const parseDomain = require('parse-domain'); const parseDomain = require('parse-domain');
const isEqual = require('lodash.isequal'); const isEqual = require('lodash.isequal');
@ -12,7 +12,7 @@ const isEqual = require('lodash.isequal');
function isWhiteList(url) { function isWhiteList(url) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
getConfigField('whiteListURL').then((whiteList) => { getGlobalConfigField('whiteListURL').then((whiteList) => {
if (checkWhiteList(url, whiteList)) { if (checkWhiteList(url, whiteList)) {
return resolve(); return resolve();

View File

@ -463,11 +463,18 @@ function doCreateMainWindow(initialUrl, initialBounds) {
} }
}); });
mainWindow.webContents.on('will-navigate', function(event, navigatedUrl){ // whenever the main window is navigated for ex: window.location.href or url redirect
// TODO: need inputs from design to implement error dialog mainWindow.webContents.on('will-navigate', function(event, navigatedURL) {
isWhiteList(navigatedUrl).catch(() => { isWhiteList(navigatedURL)
event.preventDefault(); .catch(() => {
}); event.preventDefault();
electron.dialog.showMessageBox(mainWindow, {
type: 'warning',
buttons: [ 'Ok' ],
title: 'Not Allowed',
message: `Sorry, you are not allowed to access this website (${navigatedURL}), please contact your administrator for more details`,
});
});
}); });
} }