mirror of
https://github.com/finos/SymphonyElectron.git
synced 2025-01-20 21:43:11 -06:00
Merge pull request #279 from VishwasShashidhar/electron-205
electron-205: fixes the already fixed issue post merge conflict regression
This commit is contained in:
commit
ed4672d0bc
@ -56,7 +56,7 @@ function showInFinder(id) {
|
|||||||
function createDOM(arg) {
|
function createDOM(arg) {
|
||||||
|
|
||||||
if (arg && arg._id) {
|
if (arg && arg._id) {
|
||||||
|
|
||||||
let fileDisplayName = arg.fileName;
|
let fileDisplayName = arg.fileName;
|
||||||
let downloadItemKey = arg._id;
|
let downloadItemKey = arg._id;
|
||||||
|
|
||||||
|
132
js/windowMgr.js
132
js/windowMgr.js
@ -145,7 +145,7 @@ function doCreateMainWindow(initialUrl, initialBounds) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// will set the main window on top as per the user prefs
|
// will set the main window on top as per the user prefs
|
||||||
if (alwaysOnTop){
|
if (alwaysOnTop) {
|
||||||
newWinOpts.alwaysOnTop = alwaysOnTop;
|
newWinOpts.alwaysOnTop = alwaysOnTop;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -179,7 +179,7 @@ function doCreateMainWindow(initialUrl, initialBounds) {
|
|||||||
loadErrors.showNetworkConnectivityError(mainWindow, url, retry);
|
loadErrors.showNetworkConnectivityError(mainWindow, url, retry);
|
||||||
} else {
|
} else {
|
||||||
// updates the notify config with user preference
|
// updates the notify config with user preference
|
||||||
notify.updateConfig({position: position, display: display});
|
notify.updateConfig({ position: position, display: display });
|
||||||
// removes all existing notifications when main window reloads
|
// removes all existing notifications when main window reloads
|
||||||
notify.reset();
|
notify.reset();
|
||||||
log.send(logLevels.INFO, 'loaded main window url: ' + url);
|
log.send(logLevels.INFO, 'loaded main window url: ' + url);
|
||||||
@ -188,7 +188,7 @@ function doCreateMainWindow(initialUrl, initialBounds) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
mainWindow.webContents.on('did-fail-load', function (event, errorCode,
|
mainWindow.webContents.on('did-fail-load', function (event, errorCode,
|
||||||
errorDesc, validatedURL) {
|
errorDesc, validatedURL) {
|
||||||
loadErrors.showLoadFailure(mainWindow, validatedURL, errorDesc, errorCode, retry, false);
|
loadErrors.showLoadFailure(mainWindow, validatedURL, errorDesc, errorCode, retry, false);
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -218,7 +218,7 @@ function doCreateMainWindow(initialUrl, initialBounds) {
|
|||||||
const menu = electron.Menu.buildFromTemplate(getTemplate(app));
|
const menu = electron.Menu.buildFromTemplate(getTemplate(app));
|
||||||
electron.Menu.setApplicationMenu(menu);
|
electron.Menu.setApplicationMenu(menu);
|
||||||
|
|
||||||
mainWindow.on('close', function(e) {
|
mainWindow.on('close', function (e) {
|
||||||
if (willQuitApp) {
|
if (willQuitApp) {
|
||||||
destroyAllWindows();
|
destroyAllWindows();
|
||||||
return;
|
return;
|
||||||
@ -259,7 +259,7 @@ function doCreateMainWindow(initialUrl, initialBounds) {
|
|||||||
|
|
||||||
// When download is in progress, send necessary data to indicate the same
|
// When download is in progress, send necessary data to indicate the same
|
||||||
webContents.send('downloadProgress');
|
webContents.send('downloadProgress');
|
||||||
|
|
||||||
// An extra check to see if the user created downloads directory has been deleted
|
// An extra check to see if the user created downloads directory has been deleted
|
||||||
// This scenario can occur when user doesn't quit electron and continues using it
|
// This scenario can occur when user doesn't quit electron and continues using it
|
||||||
// across days and then deletes the folder.
|
// across days and then deletes the folder.
|
||||||
@ -267,21 +267,17 @@ function doCreateMainWindow(initialUrl, initialBounds) {
|
|||||||
downloadsDirectory = defaultDownloadsDirectory;
|
downloadsDirectory = defaultDownloadsDirectory;
|
||||||
updateConfigField("downloadsDirectory", downloadsDirectory);
|
updateConfigField("downloadsDirectory", downloadsDirectory);
|
||||||
}
|
}
|
||||||
|
|
||||||
// We check the downloads directory to see if a file with the similar name
|
// We check the downloads directory to see if a file with the similar name
|
||||||
// already exists and get a unique filename if that's the case
|
// already exists and get a unique filename if that's the case
|
||||||
let newFileName = getUniqueFileName(item.getFilename());
|
let newFileName = getUniqueFileName(item.getFilename());
|
||||||
item.setSavePath(downloadsDirectory + "/" + newFileName);
|
if (isMac) {
|
||||||
|
item.setSavePath(downloadsDirectory + "/" + newFileName);
|
||||||
// Send file path to construct the DOM in the UI when the download is complete
|
} else {
|
||||||
|
item.setSavePath(downloadsDirectory + "\\" + newFileName);
|
||||||
// if the user has set a custom downloads directory, save file to that directory
|
|
||||||
// if otherwise, we save it to the operating system's default downloads directory
|
|
||||||
if (downloadsDirectory) {
|
|
||||||
item.setSavePath(downloadsDirectory + "/" + item.getFilename());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Send file path when download is complete
|
// Send file path to construct the DOM in the UI when the download is complete
|
||||||
item.once('done', (e, state) => {
|
item.once('done', (e, state) => {
|
||||||
if (state === 'completed') {
|
if (state === 'completed') {
|
||||||
let data = {
|
let data = {
|
||||||
@ -296,25 +292,25 @@ function doCreateMainWindow(initialUrl, initialBounds) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
getConfigField('url')
|
getConfigField('url')
|
||||||
.then(initializeCrashReporter)
|
.then(initializeCrashReporter)
|
||||||
.catch(app.quit);
|
.catch(app.quit);
|
||||||
|
|
||||||
function initializeCrashReporter(podUrl) {
|
function initializeCrashReporter(podUrl) {
|
||||||
getConfigField('crashReporter')
|
getConfigField('crashReporter')
|
||||||
.then((crashReporterConfig) => {
|
.then((crashReporterConfig) => {
|
||||||
log.send(logLevels.INFO, 'Initializing crash reporter on the main window!');
|
log.send(logLevels.INFO, 'Initializing crash reporter on the main window!');
|
||||||
crashReporter.start({companyName: crashReporterConfig.companyName, submitURL: crashReporterConfig.submitURL, uploadToServer: crashReporterConfig.uploadToServer, extra: {'process': 'renderer / main window', podUrl: podUrl}});
|
crashReporter.start({ companyName: crashReporterConfig.companyName, submitURL: crashReporterConfig.submitURL, uploadToServer: crashReporterConfig.uploadToServer, extra: { 'process': 'renderer / main window', podUrl: podUrl } });
|
||||||
log.send(logLevels.INFO, 'initialized crash reporter on the main window!');
|
log.send(logLevels.INFO, 'initialized crash reporter on the main window!');
|
||||||
mainWindow.webContents.send('register-crash-reporter', {companyName: crashReporterConfig.companyName, submitURL: crashReporterConfig.submitURL, uploadToServer: crashReporterConfig.uploadToServer, process: 'preload script / main window renderer'});
|
mainWindow.webContents.send('register-crash-reporter', { companyName: crashReporterConfig.companyName, submitURL: crashReporterConfig.submitURL, uploadToServer: crashReporterConfig.uploadToServer, process: 'preload script / main window renderer' });
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
log.send(logLevels.ERROR, 'Unable to initialize crash reporter in the main window. Error is -> ' + err);
|
log.send(logLevels.ERROR, 'Unable to initialize crash reporter in the main window. Error is -> ' + err);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// open external links in default browser - a tag with href='_blank' or window.open
|
// open external links in default browser - a tag with href='_blank' or window.open
|
||||||
mainWindow.webContents.on('new-window', function (event, newWinUrl,
|
mainWindow.webContents.on('new-window', function (event, newWinUrl,
|
||||||
frameName, disposition, newWinOptions) {
|
frameName, disposition, newWinOptions) {
|
||||||
|
|
||||||
let newWinParsedUrl = getParsedUrl(newWinUrl);
|
let newWinParsedUrl = getParsedUrl(newWinUrl);
|
||||||
let mainWinParsedUrl = getParsedUrl(url);
|
let mainWinParsedUrl = getParsedUrl(url);
|
||||||
@ -346,7 +342,7 @@ function doCreateMainWindow(initialUrl, initialBounds) {
|
|||||||
let newX = Number.parseInt(query.x, 10);
|
let newX = Number.parseInt(query.x, 10);
|
||||||
let newY = Number.parseInt(query.y, 10);
|
let newY = Number.parseInt(query.y, 10);
|
||||||
|
|
||||||
let newWinRect = {x: newX, y: newY, width, height};
|
let newWinRect = { x: newX, y: newY, width, height };
|
||||||
|
|
||||||
// only accept if both are successfully parsed.
|
// only accept if both are successfully parsed.
|
||||||
if (Number.isInteger(newX) && Number.isInteger(newY) &&
|
if (Number.isInteger(newX) && Number.isInteger(newY) &&
|
||||||
@ -359,7 +355,7 @@ function doCreateMainWindow(initialUrl, initialBounds) {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// create new window at slight offset from main window.
|
// create new window at slight offset from main window.
|
||||||
({x, y} = getWindowSizeAndPosition(mainWindow));
|
({ x, y } = getWindowSizeAndPosition(mainWindow));
|
||||||
x += 50;
|
x += 50;
|
||||||
y += 50;
|
y += 50;
|
||||||
}
|
}
|
||||||
@ -393,18 +389,18 @@ function doCreateMainWindow(initialUrl, initialBounds) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
getConfigField('url')
|
getConfigField('url')
|
||||||
.then((podUrl) => {
|
.then((podUrl) => {
|
||||||
getConfigField('crashReporter')
|
getConfigField('crashReporter')
|
||||||
.then((crashReporterConfig) => {
|
.then((crashReporterConfig) => {
|
||||||
crashReporter.start({companyName: crashReporterConfig.companyName, submitURL: crashReporterConfig.submitURL, uploadToServer: crashReporterConfig.uploadToServer, extra: {'process': 'renderer / child window', podUrl: podUrl}});
|
crashReporter.start({ companyName: crashReporterConfig.companyName, submitURL: crashReporterConfig.submitURL, uploadToServer: crashReporterConfig.uploadToServer, extra: { 'process': 'renderer / child window', podUrl: podUrl } });
|
||||||
log.send(logLevels.INFO, 'initialized crash reporter on a child window!');
|
log.send(logLevels.INFO, 'initialized crash reporter on a child window!');
|
||||||
browserWin.webContents.send('register-crash-reporter', {companyName: crashReporterConfig.companyName, submitURL: crashReporterConfig.submitURL, uploadToServer: crashReporterConfig.uploadToServer, process: 'preload script / child window renderer'});
|
browserWin.webContents.send('register-crash-reporter', { companyName: crashReporterConfig.companyName, submitURL: crashReporterConfig.submitURL, uploadToServer: crashReporterConfig.uploadToServer, process: 'preload script / child window renderer' });
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
log.send(logLevels.ERROR, 'Unable to initialize crash reporter in the child window. Error is -> ' + err);
|
||||||
|
});
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch(app.quit);
|
||||||
log.send(logLevels.ERROR, 'Unable to initialize crash reporter in the child window. Error is -> ' + err);
|
|
||||||
});
|
|
||||||
})
|
|
||||||
.catch(app.quit);
|
|
||||||
|
|
||||||
browserWin.winName = frameName;
|
browserWin.winName = frameName;
|
||||||
browserWin.setAlwaysOnTop(alwaysOnTop);
|
browserWin.setAlwaysOnTop(alwaysOnTop);
|
||||||
@ -412,7 +408,7 @@ function doCreateMainWindow(initialUrl, initialBounds) {
|
|||||||
let handleChildWindowClosed = () => {
|
let handleChildWindowClosed = () => {
|
||||||
removeWindowKey(newWinKey);
|
removeWindowKey(newWinKey);
|
||||||
browserWin.removeListener('move', throttledBoundsChange);
|
browserWin.removeListener('move', throttledBoundsChange);
|
||||||
browserWin.removeListener('resize', throttledBoundsChange);
|
browserWin.removeListener('resize', throttledBoundsChange);
|
||||||
};
|
};
|
||||||
|
|
||||||
browserWin.once('closed', () => {
|
browserWin.once('closed', () => {
|
||||||
@ -448,11 +444,11 @@ function doCreateMainWindow(initialUrl, initialBounds) {
|
|||||||
childEvent.preventDefault();
|
childEvent.preventDefault();
|
||||||
openUrlInDefaultBrowser(childWinUrl);
|
openUrlInDefaultBrowser(childWinUrl);
|
||||||
};
|
};
|
||||||
|
|
||||||
// In case we navigate to an external link from inside a pop-out,
|
// In case we navigate to an external link from inside a pop-out,
|
||||||
// we open that link in an external browser rather than creating
|
// we open that link in an external browser rather than creating
|
||||||
// a new window
|
// a new window
|
||||||
browserWin.webContents.on('new-window', handleChildNewWindowEvent);
|
browserWin.webContents.on('new-window', handleChildNewWindowEvent);
|
||||||
|
|
||||||
addWindowKey(newWinKey, browserWin);
|
addWindowKey(newWinKey, browserWin);
|
||||||
|
|
||||||
@ -465,7 +461,7 @@ function doCreateMainWindow(initialUrl, initialBounds) {
|
|||||||
let throttledBoundsChange = throttle(1000,
|
let throttledBoundsChange = throttle(1000,
|
||||||
sendChildWinBoundsChange.bind(null, browserWin));
|
sendChildWinBoundsChange.bind(null, browserWin));
|
||||||
browserWin.on('move', throttledBoundsChange);
|
browserWin.on('move', throttledBoundsChange);
|
||||||
browserWin.on('resize', throttledBoundsChange);
|
browserWin.on('resize', throttledBoundsChange);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
@ -475,14 +471,14 @@ function doCreateMainWindow(initialUrl, initialBounds) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// whenever the main window is navigated for ex: window.location.href or url redirect
|
// whenever the main window is navigated for ex: window.location.href or url redirect
|
||||||
mainWindow.webContents.on('will-navigate', function(event, navigatedURL) {
|
mainWindow.webContents.on('will-navigate', function (event, navigatedURL) {
|
||||||
deleteIndexFolder();
|
deleteIndexFolder();
|
||||||
isWhitelisted(navigatedURL)
|
isWhitelisted(navigatedURL)
|
||||||
.catch(() => {
|
.catch(() => {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
electron.dialog.showMessageBox(mainWindow, {
|
electron.dialog.showMessageBox(mainWindow, {
|
||||||
type: 'warning',
|
type: 'warning',
|
||||||
buttons: [ 'Ok' ],
|
buttons: ['Ok'],
|
||||||
title: 'Not Allowed',
|
title: 'Not Allowed',
|
||||||
message: `Sorry, you are not allowed to access this website (${navigatedURL}), please contact your administrator for more details`,
|
message: `Sorry, you are not allowed to access this website (${navigatedURL}), please contact your administrator for more details`,
|
||||||
});
|
});
|
||||||
@ -628,7 +624,7 @@ function sendChildWinBoundsChange(window) {
|
|||||||
* @param urlToOpen
|
* @param urlToOpen
|
||||||
*/
|
*/
|
||||||
function openUrlInDefaultBrowser(urlToOpen) {
|
function openUrlInDefaultBrowser(urlToOpen) {
|
||||||
if (urlToOpen) {
|
if (urlToOpen) {
|
||||||
electron.shell.openExternal(urlToOpen);
|
electron.shell.openExternal(urlToOpen);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -677,7 +673,7 @@ eventEmitter.on('notificationSettings', (notificationSettings) => {
|
|||||||
function verifyDisplays() {
|
function verifyDisplays() {
|
||||||
|
|
||||||
// This is only for Windows, macOS handles this by itself
|
// This is only for Windows, macOS handles this by itself
|
||||||
if (!mainWindow || isMac){
|
if (!mainWindow || isMac) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -687,14 +683,14 @@ function verifyDisplays() {
|
|||||||
let isYAxisValid = true;
|
let isYAxisValid = true;
|
||||||
|
|
||||||
// checks to make sure the x,y are valid pairs
|
// checks to make sure the x,y are valid pairs
|
||||||
if ((bounds.x === undefined && (bounds.y || bounds.y === 0))){
|
if ((bounds.x === undefined && (bounds.y || bounds.y === 0))) {
|
||||||
isXAxisValid = false;
|
isXAxisValid = false;
|
||||||
}
|
}
|
||||||
if ((bounds.y === undefined && (bounds.x || bounds.x === 0))){
|
if ((bounds.y === undefined && (bounds.x || bounds.x === 0))) {
|
||||||
isYAxisValid = false;
|
isYAxisValid = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isXAxisValid && !isYAxisValid){
|
if (!isXAxisValid && !isYAxisValid) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -725,7 +721,7 @@ function checkExternalDisplay(appBounds) {
|
|||||||
// Loops through all the available displays and
|
// Loops through all the available displays and
|
||||||
// verifies if the wrapper exists within the display bounds
|
// verifies if the wrapper exists within the display bounds
|
||||||
// returns false if not exists otherwise true
|
// returns false if not exists otherwise true
|
||||||
return !!screen.getAllDisplays().find(({bounds}) => {
|
return !!screen.getAllDisplays().find(({ bounds }) => {
|
||||||
|
|
||||||
const leftMost = x + (width * factor);
|
const leftMost = x + (width * factor);
|
||||||
const topMost = y + (height * factor);
|
const topMost = y + (height * factor);
|
||||||
@ -748,7 +744,7 @@ function checkExternalDisplay(appBounds) {
|
|||||||
function repositionMainWindow() {
|
function repositionMainWindow() {
|
||||||
const screen = electron.screen;
|
const screen = electron.screen;
|
||||||
|
|
||||||
const {workArea} = screen.getPrimaryDisplay();
|
const { workArea } = screen.getPrimaryDisplay();
|
||||||
const bounds = workArea;
|
const bounds = workArea;
|
||||||
|
|
||||||
if (!bounds) {
|
if (!bounds) {
|
||||||
@ -765,10 +761,10 @@ function repositionMainWindow() {
|
|||||||
const x = Math.round(centerX - (windowWidth / 2.0));
|
const x = Math.round(centerX - (windowWidth / 2.0));
|
||||||
const y = Math.round(centerY - (windowHeight / 2.0));
|
const y = Math.round(centerY - (windowHeight / 2.0));
|
||||||
|
|
||||||
let rectangle = {x, y, width: windowWidth, height: windowHeight};
|
let rectangle = { x, y, width: windowWidth, height: windowHeight };
|
||||||
|
|
||||||
// resetting the main window bounds
|
// resetting the main window bounds
|
||||||
if (mainWindow){
|
if (mainWindow) {
|
||||||
if (!mainWindow.isVisible()) {
|
if (!mainWindow.isVisible()) {
|
||||||
mainWindow.show();
|
mainWindow.show();
|
||||||
}
|
}
|
||||||
@ -790,33 +786,33 @@ function repositionMainWindow() {
|
|||||||
* @returns {String} the new filename
|
* @returns {String} the new filename
|
||||||
*/
|
*/
|
||||||
function getUniqueFileName(filename) {
|
function getUniqueFileName(filename) {
|
||||||
|
|
||||||
// By default, we assume that the file exists
|
// By default, we assume that the file exists
|
||||||
const fileExists = true;
|
const fileExists = true;
|
||||||
|
|
||||||
// We break the file from it's extension to get the name
|
// We break the file from it's extension to get the name
|
||||||
const actualFilename = filename.substr(0, filename.lastIndexOf('.')) || filename;
|
const actualFilename = filename.substr(0, filename.lastIndexOf('.')) || filename;
|
||||||
const fileType = filename.split('.').pop();
|
const fileType = filename.split('.').pop();
|
||||||
|
|
||||||
// We use this to set the new file name with an increment on the previous existing file
|
// We use this to set the new file name with an increment on the previous existing file
|
||||||
let fileNumber = 0;
|
let fileNumber = 0;
|
||||||
let newPath;
|
let newPath;
|
||||||
|
|
||||||
while (fileExists) {
|
while (fileExists) {
|
||||||
|
|
||||||
let fileNameString = fileNumber.toString();
|
let fileNameString = fileNumber.toString();
|
||||||
|
|
||||||
// By default, we know if the file doesn't exist,
|
// By default, we know if the file doesn't exist,
|
||||||
// we can use the filename sent by the remote server
|
// we can use the filename sent by the remote server
|
||||||
let current = filename;
|
let current = filename;
|
||||||
|
|
||||||
// If the file already exists, we know that the
|
// If the file already exists, we know that the
|
||||||
// file number variable is increased, so,
|
// file number variable is increased, so,
|
||||||
// we construct a new file name with the file number
|
// we construct a new file name with the file number
|
||||||
if (fileNumber > 0) {
|
if (fileNumber > 0) {
|
||||||
current = actualFilename + " (" + fileNameString + ")." + fileType;
|
current = actualFilename + " (" + fileNameString + ")." + fileType;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the file exists, increment the file number and repeat the loop
|
// If the file exists, increment the file number and repeat the loop
|
||||||
if (fs.existsSync(downloadsDirectory + "/" + current)) {
|
if (fs.existsSync(downloadsDirectory + "/" + current)) {
|
||||||
fileNumber++;
|
fileNumber++;
|
||||||
@ -824,9 +820,9 @@ function getUniqueFileName(filename) {
|
|||||||
newPath = current;
|
newPath = current;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return newPath;
|
return newPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user