electron-17: merged master onto electron-17 and resolved conflicts

This commit is contained in:
Vishwas Shashidhar 2017-07-05 15:45:46 +05:30
commit 981df664a9
6 changed files with 127 additions and 1 deletions

View File

@ -7,5 +7,10 @@
"notificationSettings": {
"position": "upper-right",
"display": ""
},
"crashReporterDetails": {
"backendURL": "http://crash.symphony.com/",
"sendCrashReports": true,
"autoSubmit": true
}
}

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) {

41
js/crashReporter/index.js Executable file
View File

@ -0,0 +1,41 @@
'use strict';
const electron = require('electron');
const {crashReporter} = require('electron');
const {app} = process.type === 'browser' ? electron : electron.remote;
/**
* Setup the crash reporter with appropriate information
* @param crashReporterDetails: An object to get crash information
* from the global config file
* @param detailObj: An object to send extra parameters
* via the crash reporter
*/
function setupCrashReporter(detailObj, crashReporterDetails) {
// Fetch details from config file
if (!crashReporterDetails){
return
}
let crashReportInfo = {
companyName: app.getName(),
submitURL: crashReporterDetails.backendURL,
autoSubmit: crashReporterDetails.autoSubmit,
uploadToServer: crashReporterDetails.sendCrashReports,
extra: detailObj
};
// App store builds cannot use crash reporter, so, return if that's the case
if (process.platform === 'darwin' && process.mas) {
return
}
if (process.type === 'renderer' && !(process.platform === 'darwin')) {
return;
}
crashReporter.start(crashReportInfo);
}
exports.setupCrashReporter = setupCrashReporter;

View File

@ -9,7 +9,8 @@ const urlParser = require('url');
const { getConfigField } = require('./config.js');
const { isMac, isDevEnv } = require('./utils/misc.js');
const protocolHandler = require('./protocolHandler');
const getCmdLineArg = require('./utils/getCmdLineArg.js')
const getCmdLineArg = require('./utils/getCmdLineArg.js');
const crashReporter = require('./crashReporter');
require('electron-dl')();
@ -151,6 +152,20 @@ function createWin(urlFromConfig) {
windowMgr.createMainWindow(url);
}
/**
* Get crash info from global config and setup crash reporter for Main Process.
*/
function initializeCrashReporter () {
getConfigField('crashReporterDetails').then(
function (data) {
crashReporter.setupCrashReporter({'window': 'main'}, data);
}
).catch(function (err) {
let title = 'Error loading configuration';
electron.dialog.showErrorBox(title, title + ': ' + err);
})
}
/**
* processes protocol action for windows clients
* @param argv {Array} an array of command line arguments
@ -188,3 +203,6 @@ function handleProtocolAction(uri) {
protocolHandler.processProtocolAction(uri);
}
}
// Initialize the crash reporter
initializeCrashReporter();

View File

@ -18,6 +18,7 @@ const apiEnums = require('../enums/api.js');
const apiCmds = apiEnums.cmds;
const apiName = apiEnums.apiName;
const getMediaSources = require('../desktopCapturer/getSources');
const crashReporter = require('../crashReporter');
require('../downloadManager/downloadManager');
@ -36,6 +37,14 @@ const throttledSetBadgeCount = throttle(1000, function(count) {
});
});
// Setup the crash reporter
var demoData = {
"backendURL": "http://localhost:1127/post",
"sendCrashReports": true,
"autoSubmit": true
};
crashReporter.setupCrashReporter({'window': 'preloadMain'}, demoData);
createAPI();
// creates API exposed from electron.
@ -111,6 +120,13 @@ function createAPI() {
*/
ScreenSnippet: remote.require('./screenSnippet/ScreenSnippet.js').ScreenSnippet,
/**
* Provides API to crash the renderer process that calls this function
*/
crashRendererProcess: function () {
process.crash();
},
/**
* Brings window forward and gives focus.
* @param {String} windowName Name of window. Note: main window name is 'main'

View File

@ -7,6 +7,7 @@ const path = require('path');
const nodeURL = require('url');
const querystring = require('querystring');
const filesize = require('filesize');
const {dialog} = require('electron');
const { getTemplate, getMinimizeOnClose } = require('./menus/menuTemplate.js');
const loadErrors = require('./dialogs/showLoadError.js');
@ -20,6 +21,8 @@ const eventEmitter = require('./eventEmitter');
const throttle = require('./utils/throttle.js');
const { getConfigField, updateConfigField } = require('./config.js');
const crashReporter = require('./crashReporter');
//context menu
const contextMenu = require('./menus/contextMenu.js');
@ -71,6 +74,18 @@ function doCreateMainWindow(initialUrl, initialBounds) {
let url = initialUrl;
let key = getGuid();
/**
* Get crash info from global config and setup crash reporter.
*/
getConfigField('crashReporterDetails').then(
function (data) {
crashReporter.setupCrashReporter({'window': 'main'}, data);
}
).catch(function (err) {
let title = 'Error loading configuration';
electron.dialog.showErrorBox(title, title + ': ' + err);
});
log.send(logLevels.INFO, 'creating main window url: ' + url);
let newWinOpts = {
@ -157,6 +172,24 @@ function doCreateMainWindow(initialUrl, initialBounds) {
loadErrors.showLoadFailure(mainWindow, validatedURL, errorDesc, errorCode, retry);
});
// 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: 'Uh oh! Looks like we have had a crash. Please reload or close this window.',
buttons: ['Reload', 'Close']
};
dialog.showMessageBox(options, function (index) {
if (index === 0) {
mainWindow.reload();
}
else mainWindow.close();
});
});
addWindowKey(key, mainWindow);
mainWindow.loadURL(url);