electron-17: refactored code to read data from the config file and added pod url to the extras object

This commit is contained in:
Vishwas Shashidhar 2017-10-05 22:18:52 +05:30
parent a572330198
commit f83cfb9a44
4 changed files with 63 additions and 8 deletions

View File

@ -6,5 +6,10 @@
"notificationSettings": { "notificationSettings": {
"position": "upper-right", "position": "upper-right",
"display": "" "display": ""
} },
"crashReporter": {
"submitURL": "https://localhost:1127/post",
"companyName": "Symphony",
"uploadToServer": true
}
} }

View File

@ -14,6 +14,8 @@ const {getConfigField, updateUserConfigWin, updateUserConfigMac} = require('./co
const { isMac, isDevEnv } = require('./utils/misc.js'); const { isMac, isDevEnv } = require('./utils/misc.js');
const protocolHandler = require('./protocolHandler'); const protocolHandler = require('./protocolHandler');
const getCmdLineArg = require('./utils/getCmdLineArg.js'); const getCmdLineArg = require('./utils/getCmdLineArg.js');
const log = require('./log.js');
const logLevels = require('./enums/logLevels.js');
require('electron-dl')(); require('electron-dl')();
@ -32,7 +34,22 @@ require('./memoryMonitor.js');
const windowMgr = require('./windowMgr.js'); const windowMgr = require('./windowMgr.js');
crashReporter.start({companyName: 'Symphony', submitURL: 'http://localhost:3000', uploadToServer: false, extra: {'process': 'main'}}); getConfigField('url')
.then(initializeCrashReporter)
.catch(app.quit);
function initializeCrashReporter(podUrl) {
getConfigField('crashReporter')
.then((crashReporterConfig) => {
crashReporter.start({companyName: crashReporterConfig.companyName, submitURL: crashReporterConfig.submitURL, uploadToServer: crashReporterConfig.uploadToServer, extra: {'process': 'main', podUrl: podUrl}});
log.send(logLevels.INFO, 'initialized crash reporter on the main process!');
})
.catch((err) => {
log.send(logLevels.ERROR, 'Unable to initialize crash reporter in the main process. Error is -> ' + err);
});
}
// only allow a single instance of app. // only allow a single instance of app.
const shouldQuit = app.makeSingleInstance((argv) => { const shouldQuit = app.makeSingleInstance((argv) => {

View File

@ -60,7 +60,6 @@ const throttledSetBadgeCount = throttle(1000, function(count) {
}); });
}); });
crashReporter.start({companyName: 'Symphony', submitURL: 'http://localhost:3000', uploadToServer: false, extra: {'process': 'preload script / renderer'}});
createAPI(); createAPI();
// creates API exposed from electron. // creates API exposed from electron.
@ -336,6 +335,12 @@ function createAPI() {
}); });
local.ipcRenderer.on('register-crash-reporter', (event, arg) => {
if (arg) {
crashReporter.start({companyName: arg.companyName, submitURL: arg.submitURL, uploadToServer: arg.uploadToServer, extra: {'process': arg.process, podUrl: arg.podUrl}});
}
});
function updateOnlineStatus() { function updateOnlineStatus() {
local.ipcRenderer.send(apiName, { local.ipcRenderer.send(apiName, {
cmd: apiCmds.isOnline, cmd: apiCmds.isOnline,

View File

@ -93,7 +93,6 @@ function doCreateMainWindow(initialUrl, initialBounds) {
let url = initialUrl; let url = initialUrl;
let key = getGuid(); 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); log.send(logLevels.INFO, 'creating main window url: ' + url);
let newWinOpts = { let newWinOpts = {
@ -252,6 +251,23 @@ function doCreateMainWindow(initialUrl, initialBounds) {
}); });
}); });
getConfigField('url')
.then(initializeCrashReporter)
.catch(app.quit);
function initializeCrashReporter(podUrl) {
getConfigField('crashReporter')
.then((crashReporterConfig) => {
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}});
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'});
})
.catch((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... // bug in electron is preventing this from working in sandboxed evt...
// https://github.com/electron/electron/issues/8841 // https://github.com/electron/electron/issues/8841
mainWindow.webContents.on('will-navigate', function(event, willNavUrl) { mainWindow.webContents.on('will-navigate', function(event, willNavUrl) {
@ -336,7 +352,19 @@ function doCreateMainWindow(initialUrl, initialBounds) {
if (browserWin) { if (browserWin) {
log.send(logLevels.INFO, 'loaded pop-out window url: ' + newWinParsedUrl); 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}}); getConfigField('url')
.then((podUrl) => {
getConfigField('crashReporter')
.then((crashReporterConfig) => {
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!');
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(app.quit);
browserWin.winName = frameName; browserWin.winName = frameName;
browserWin.setAlwaysOnTop(alwaysOnTop); browserWin.setAlwaysOnTop(alwaysOnTop);
@ -363,7 +391,7 @@ function doCreateMainWindow(initialUrl, initialBounds) {
mainWindow.close(); mainWindow.close();
} }
}); });
}); });
addWindowKey(newWinKey, browserWin); addWindowKey(newWinKey, browserWin);
@ -371,12 +399,12 @@ 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 {
event.preventDefault(); event.preventDefault();
openUrlInDefaultBrower(newWinUrl) openUrlInDefaultBrower(newWinUrl);
} }
}); });