electron-17: fixes merge conflicts with master

This commit is contained in:
Vishwas Shashidhar 2017-10-09 19:57:38 +05:30
commit dd0882c0b6
3 changed files with 43 additions and 22 deletions

View File

@ -44,6 +44,16 @@ function getTemplatePath() {
* which this window should show * which this window should show
*/ */
function openAboutWindow(windowName) { 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(); let allWindows = BrowserWindow.getAllWindows();
allWindows = allWindows.find((window) => { return window.winName === windowName }); allWindows = allWindows.find((window) => { return window.winName === windowName });

View File

@ -266,17 +266,7 @@ function doCreateMainWindow(initialUrl, initialBounds) {
.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);
}); });
} }
// 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 // 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,
@ -369,13 +359,22 @@ function doCreateMainWindow(initialUrl, initialBounds) {
browserWin.winName = frameName; browserWin.winName = frameName;
browserWin.setAlwaysOnTop(alwaysOnTop); browserWin.setAlwaysOnTop(alwaysOnTop);
browserWin.once('closed', function () { 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', () => {
handleChildWindowClosed();
}); });
browserWin.webContents.on('crashed', function () { browserWin.on('close', () => {
browserWin.webContents.removeListener('new-window', handleChildNewWindowEvent);
browserWin.webContents.removeListener('crashed', handleChildWindowCrashEvent);
});
let handleChildWindowCrashEvent = () => {
const options = { const options = {
type: 'error', type: 'error',
title: 'Renderer Process Crashed', title: 'Renderer Process Crashed',
@ -385,13 +384,25 @@ function doCreateMainWindow(initialUrl, initialBounds) {
electron.dialog.showMessageBox(options, function (index) { electron.dialog.showMessageBox(options, function (index) {
if (index === 0) { if (index === 0) {
mainWindow.reload(); browserWin.reload();
} }
else { 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); addWindowKey(newWinKey, browserWin);
@ -409,7 +420,7 @@ function doCreateMainWindow(initialUrl, initialBounds) {
}); });
} else { } else {
event.preventDefault(); event.preventDefault();
openUrlInDefaultBrower(newWinUrl); openUrlInDefaultBrowser(newWinUrl);
} }
}); });
@ -505,7 +516,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. * brings to front and gives focus.
* @param {String} windowName Name of target window. Note: main window has * @param {String} windowName Name of target window. Note: main window has
* name 'main'. * name 'main'.
@ -551,8 +562,8 @@ function sendChildWinBoundsChange(window) {
* Opens an external url in the system's default browser * Opens an external url in the system's default browser
* @param urlToOpen * @param urlToOpen
*/ */
function openUrlInDefaultBrower(urlToOpen) { function openUrlInDefaultBrowser(urlToOpen) {
if (urlToOpen) { if (urlToOpen) {
electron.shell.openExternal(urlToOpen); electron.shell.openExternal(urlToOpen);
} }
} }

View File

@ -76,7 +76,7 @@
"devDependencies": { "devDependencies": {
"browserify": "^14.1.0", "browserify": "^14.1.0",
"cross-env": "^3.2.4", "cross-env": "^3.2.4",
"electron": "1.7.5", "electron": "1.7.8",
"electron-builder": "^13.9.0", "electron-builder": "^13.9.0",
"electron-builder-squirrel-windows": "^12.3.0", "electron-builder-squirrel-windows": "^12.3.0",
"electron-packager": "^8.5.2", "electron-packager": "^8.5.2",