Merge pull request #190 from VishwasShashidhar/electron-17

Electron 17 - Crash Reporter Implementation
This commit is contained in:
Vikas Shashidhar 2017-09-27 00:16:13 +05:30 committed by GitHub
commit 1a312544d7
6 changed files with 87 additions and 8 deletions

View File

@ -6,5 +6,5 @@
"notificationSettings": {
"position": "upper-right",
"display": ""
}
}
}

View File

@ -37,6 +37,13 @@
<button id='open-config-win'>Open configure window</button>
<br>
<hr>
<p>
Crash Process:
<p>
<button id='crash'>Crash Renderer</button>
</p>
<br>
<hr>
<p>Badge Count:<p>
<button id='inc-badge'>increment badge count</button>
<br>
@ -172,6 +179,12 @@
console.log('bounds changed for=', arg)
}
// crash the renderer process
const crash = document.getElementById('crash');
crash.addEventListener('click', function () {
ssf.crashRendererProcess();
});
var getSources = document.getElementById('get-sources');
getSources.addEventListener('click', function() {
ssf.getMediaSources({types: ['window', 'screen']}, function(error, sources) {

View File

@ -3,6 +3,7 @@
// Third Party Dependencies
const electron = require('electron');
const app = electron.app;
const crashReporter = electron.crashReporter;
const nodeURL = require('url');
const squirrelStartup = require('electron-squirrel-startup');
const AutoLaunch = require('auto-launch');
@ -31,6 +32,8 @@ require('./memoryMonitor.js');
const windowMgr = require('./windowMgr.js');
crashReporter.start({companyName: 'Symphony', submitURL: 'http://localhost:3000', uploadToServer: false, extra: {'process': 'main'}});
// only allow a single instance of app.
const shouldQuit = app.makeSingleInstance((argv) => {
// Someone tried to run a second instance, we should focus our window.

View File

@ -65,6 +65,13 @@ const template = [{
}
}
},
{
label: 'Open Crashes Directory',
click() {
const crashesDirectory = electron.crashReporter.getCrashesDirectory() + '/completed';
electron.shell.showItemInFolder(crashesDirectory);
}
},
{
type: 'separator'
},
@ -97,10 +104,11 @@ const template = [{
},
{
role: 'help',
submenu: [{
label: 'Learn More',
click() { electron.shell.openExternal('https://www.symphony.com'); }
}]
submenu: [
{
label: 'Learn More',
click() { electron.shell.openExternal('https://www.symphony.com'); }
}]
}
];

View File

@ -11,7 +11,7 @@
// also to bring pieces of node.js:
// https://github.com/electron/electron/issues/2984
//
const { ipcRenderer, remote } = require('electron');
const { ipcRenderer, remote, crashReporter } = require('electron');
const throttle = require('../utils/throttle.js');
const apiEnums = require('../enums/api.js');
@ -53,6 +53,7 @@ const throttledSetBadgeCount = throttle(1000, function(count) {
});
});
crashReporter.start({companyName: 'Symphony', submitURL: 'http://localhost:3000', uploadToServer: false, extra: {'process': 'preload script / renderer'}});
createAPI();
// creates API exposed from electron.
@ -109,6 +110,19 @@ function createAPI() {
*/
ScreenSnippet: remote.require('./screenSnippet/index.js').ScreenSnippet,
/**
* Provides API to crash the renderer process that calls this function
* Is only used for demos.
*/
crashRendererProcess: function () {
// For practical purposes, we don't allow
// this method to work in non-dev environments
if (!process.env.ELECTRON_DEV) {
return;
}
process.crash();
},
/**
* Brings window forward and gives focus.
* @param {String} windowName Name of window. Note: main window name is 'main'

View File

@ -2,6 +2,7 @@
const electron = require('electron');
const app = electron.app;
const crashReporter = electron.crashReporter;
const BrowserWindow = electron.BrowserWindow;
const path = require('path');
const nodeURL = require('url');
@ -16,7 +17,6 @@ const log = require('./log.js');
const logLevels = require('./enums/logLevels.js');
const notify = require('./notify/electron-notify.js');
const eventEmitter = require('./eventEmitter');
const throttle = require('./utils/throttle.js');
const { getConfigField, updateConfigField } = require('./config.js');
const { isMac, isNodeEnv } = require('./utils/misc');
@ -81,7 +81,7 @@ function createMainWindow(initialUrl) {
// failed, use default bounds
doCreateMainWindow(initialUrl, null);
}
)
);
}
/**
@ -93,6 +93,7 @@ function doCreateMainWindow(initialUrl, initialBounds) {
let url = initialUrl;
let key = getGuid();
crashReporter.start({companyName: 'Symphony', submitURL: 'http://localhost:3000', uploadToServer: false, extra: {'process': 'renderer / main window'}});
log.send(logLevels.INFO, 'creating main window url: ' + url);
let newWinOpts = {
@ -180,6 +181,26 @@ function doCreateMainWindow(initialUrl, initialBounds) {
loadErrors.showLoadFailure(mainWindow, validatedURL, errorDesc, errorCode, retry, false);
});
// In case a renderer process crashes, provide an
// option for the user to either reload or close the window
mainWindow.webContents.on('crashed', function () {
const options = {
type: 'error',
title: 'Renderer Process Crashed',
message: 'Oops! Looks like we have had a crash. Please reload or close this window.',
buttons: ['Reload', 'Close']
};
electron.dialog.showMessageBox(options, function (index) {
if (index === 0) {
mainWindow.reload();
}
else {
mainWindow.close();
}
});
});
addWindowKey(key, mainWindow);
mainWindow.loadURL(url);
@ -315,6 +336,8 @@ function doCreateMainWindow(initialUrl, initialBounds) {
if (browserWin) {
log.send(logLevels.INFO, 'loaded pop-out window url: ' + newWinParsedUrl);
crashReporter.start({companyName: 'Symphony', submitURL: 'http://localhost:3000', uploadToServer: false, extra: {'process': 'renderer / pop out window - winKey -> ' + newWinKey}});
browserWin.winName = frameName;
browserWin.setAlwaysOnTop(alwaysOnTop);
@ -324,6 +347,24 @@ function doCreateMainWindow(initialUrl, initialBounds) {
browserWin.removeListener('resize', throttledBoundsChange);
});
browserWin.webContents.on('crashed', function () {
const options = {
type: 'error',
title: 'Renderer Process Crashed',
message: 'Oops! Looks like we have had a crash. Please reload or close this window.',
buttons: ['Reload', 'Close']
};
electron.dialog.showMessageBox(options, function (index) {
if (index === 0) {
mainWindow.reload();
}
else {
mainWindow.close();
}
});
});
addWindowKey(newWinKey, browserWin);
// throttle changes so we don't flood client.