mirror of
https://github.com/finos/SymphonyElectron.git
synced 2025-02-25 18:55:29 -06:00
Merge branch 'master' into electron-141
* master: Fixed failing tests with Download Manager. electron-135: added logic to clean up event listeners electron-135: fixes as per PR comments to avoid leakages electron-151: pinned the electron version Electron-142 - Fixes the issue where it prevents creating multiple instances of the about window electron-135: fixed typo in the method name electron-135: added code comments electron-135: fixes the raised issue electron-151: added electron 1.7.8 as dependency # Conflicts: # tests/DownloadManager.test.js
This commit is contained in:
@@ -44,6 +44,16 @@ function getTemplatePath() {
|
||||
* which this window should show
|
||||
*/
|
||||
function openAboutWindow(windowName) {
|
||||
|
||||
// This prevents creating multiple instances of the
|
||||
// about window
|
||||
if (aboutWindow) {
|
||||
if (aboutWindow.isMinimized()) {
|
||||
aboutWindow.restore();
|
||||
}
|
||||
aboutWindow.focus();
|
||||
return;
|
||||
}
|
||||
let allWindows = BrowserWindow.getAllWindows();
|
||||
allWindows = allWindows.find((window) => { return window.winName === windowName });
|
||||
|
||||
|
||||
@@ -250,17 +250,7 @@ function doCreateMainWindow(initialUrl, initialBounds) {
|
||||
webContents.send('downloadCompleted', data);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// bug in electron is preventing this from working in sandboxed evt...
|
||||
// https://github.com/electron/electron/issues/8841
|
||||
mainWindow.webContents.on('will-navigate', function(event, willNavUrl) {
|
||||
if (!sandboxed) {
|
||||
return;
|
||||
}
|
||||
event.preventDefault();
|
||||
openUrlInDefaultBrower(willNavUrl);
|
||||
});
|
||||
});
|
||||
|
||||
// open external links in default browser - a tag with href='_blank' or window.open
|
||||
mainWindow.webContents.on('new-window', function (event, newWinUrl,
|
||||
@@ -341,13 +331,22 @@ function doCreateMainWindow(initialUrl, initialBounds) {
|
||||
browserWin.winName = frameName;
|
||||
browserWin.setAlwaysOnTop(alwaysOnTop);
|
||||
|
||||
browserWin.once('closed', function () {
|
||||
let handleChildWindowClosed = () => {
|
||||
removeWindowKey(newWinKey);
|
||||
browserWin.removeListener('move', throttledBoundsChange);
|
||||
browserWin.removeListener('resize', throttledBoundsChange);
|
||||
browserWin.removeListener('resize', throttledBoundsChange);
|
||||
};
|
||||
|
||||
browserWin.once('closed', () => {
|
||||
handleChildWindowClosed();
|
||||
});
|
||||
|
||||
browserWin.webContents.on('crashed', function () {
|
||||
browserWin.on('close', () => {
|
||||
browserWin.webContents.removeListener('new-window', handleChildNewWindowEvent);
|
||||
browserWin.webContents.removeListener('crashed', handleChildWindowCrashEvent);
|
||||
});
|
||||
|
||||
let handleChildWindowCrashEvent = () => {
|
||||
const options = {
|
||||
type: 'error',
|
||||
title: 'Renderer Process Crashed',
|
||||
@@ -357,13 +356,25 @@ function doCreateMainWindow(initialUrl, initialBounds) {
|
||||
|
||||
electron.dialog.showMessageBox(options, function (index) {
|
||||
if (index === 0) {
|
||||
mainWindow.reload();
|
||||
browserWin.reload();
|
||||
}
|
||||
else {
|
||||
mainWindow.close();
|
||||
browserWin.close();
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
browserWin.webContents.on('crashed', handleChildWindowCrashEvent);
|
||||
|
||||
let handleChildNewWindowEvent = (childEvent, childWinUrl) => {
|
||||
childEvent.preventDefault();
|
||||
openUrlInDefaultBrowser(childWinUrl);
|
||||
};
|
||||
|
||||
// In case we navigate to an external link from inside a pop-out,
|
||||
// we open that link in an external browser rather than creating
|
||||
// a new window
|
||||
browserWin.webContents.on('new-window', handleChildNewWindowEvent);
|
||||
|
||||
addWindowKey(newWinKey, browserWin);
|
||||
|
||||
@@ -381,7 +392,7 @@ function doCreateMainWindow(initialUrl, initialBounds) {
|
||||
});
|
||||
} else {
|
||||
event.preventDefault();
|
||||
openUrlInDefaultBrower(newWinUrl)
|
||||
openUrlInDefaultBrowser(newWinUrl);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -477,7 +488,7 @@ function setIsOnline(status) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Tries finding a window we have created with given name. If founds then
|
||||
* Tries finding a window we have created with given name. If found, then
|
||||
* brings to front and gives focus.
|
||||
* @param {String} windowName Name of target window. Note: main window has
|
||||
* name 'main'.
|
||||
@@ -523,8 +534,8 @@ function sendChildWinBoundsChange(window) {
|
||||
* Opens an external url in the system's default browser
|
||||
* @param urlToOpen
|
||||
*/
|
||||
function openUrlInDefaultBrower(urlToOpen) {
|
||||
if (urlToOpen) {
|
||||
function openUrlInDefaultBrowser(urlToOpen) {
|
||||
if (urlToOpen) {
|
||||
electron.shell.openExternal(urlToOpen);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -76,7 +76,7 @@
|
||||
"devDependencies": {
|
||||
"browserify": "^14.1.0",
|
||||
"cross-env": "^3.2.4",
|
||||
"electron": "1.7.5",
|
||||
"electron": "1.7.8",
|
||||
"electron-builder": "^13.9.0",
|
||||
"electron-builder-squirrel-windows": "^12.3.0",
|
||||
"electron-packager": "^8.5.2",
|
||||
|
||||
@@ -10,18 +10,24 @@ describe('download manager', function() {
|
||||
});
|
||||
|
||||
it('should inject download bar element into DOM once download is initiated', function() {
|
||||
electron.ipcRenderer.send('downloadCompleted', { _id: '12345', fileName: 'test', total: 100 });
|
||||
expect(document.getElementsByClassName('text-cutoff')[0].innerHTML).toBe('test');
|
||||
electron.ipcRenderer.send('downloadCompleted', { _id: '12345', fileName: 'test.png', total: 100 });
|
||||
expect(document.getElementsByClassName('text-cutoff')[0].innerHTML).toBe('test.png');
|
||||
expect(document.getElementById('per').innerHTML).toBe('100 Downloaded');
|
||||
});
|
||||
|
||||
it('should inject multiple download items during multiple downloads', function() {
|
||||
electron.ipcRenderer.send('downloadCompleted', { _id: '12345', fileName: 'test', total: 100 });
|
||||
electron.ipcRenderer.send('downloadCompleted', { _id: '67890', fileName: 'test1', total: 200 });
|
||||
electron.ipcRenderer.send('downloadCompleted', { _id: '12345', fileName: 'test.png', total: 100 });
|
||||
electron.ipcRenderer.send('downloadCompleted', { _id: '67890', fileName: 'test.png', total: 200 });
|
||||
|
||||
let fileNames = document.getElementsByClassName('text-cutoff');
|
||||
expect(fileNames[0].innerHTML).toBe('test1');
|
||||
expect(fileNames[1].innerHTML).toBe('test');
|
||||
let fNames = [];
|
||||
|
||||
for (var i = 0; i < fileNames.length; i++) {
|
||||
fNames.push(fileNames[i].innerHTML);
|
||||
}
|
||||
|
||||
expect(fNames).toEqual(expect.arrayContaining(['test (1).png', 'test (2).png']));
|
||||
expect(document.getElementById('per').innerHTML).toBe('100 Downloaded');
|
||||
|
||||
let downloadElements = document.getElementsByClassName('download-element');
|
||||
expect(downloadElements[0].id).toBe('67890');
|
||||
|
||||
Reference in New Issue
Block a user