83 lines
2.6 KiB
JavaScript
83 lines
2.6 KiB
JavaScript
"use strict";
|
|
|
|
Object.defineProperty(exports, "__esModule", {
|
|
value: true
|
|
});
|
|
exports.injectBuildInfo = injectBuildInfo;
|
|
exports.metadata = void 0;
|
|
|
|
const electron = require('electron');
|
|
|
|
const lodash = require('lodash');
|
|
|
|
const childProcess = require('child_process');
|
|
|
|
const {
|
|
getElectronMajorVersion,
|
|
flatten,
|
|
reconcileCrashReporterMetadata
|
|
} = require('../common/utility');
|
|
|
|
const {
|
|
CRASH_REPORTER_UPDATE_METADATA
|
|
} = require('../common/constants').IPCEvents;
|
|
|
|
const metadata = {};
|
|
exports.metadata = metadata;
|
|
|
|
function injectBuildInfo(buildInfo) {
|
|
metadata['channel'] = buildInfo.releaseChannel;
|
|
const sentryMetadata = metadata['sentry'] != null ? metadata['sentry'] : {};
|
|
sentryMetadata['environment'] = buildInfo.releaseChannel;
|
|
sentryMetadata['release'] = buildInfo.version;
|
|
metadata['sentry'] = sentryMetadata;
|
|
}
|
|
|
|
if (process.platform === 'linux') {
|
|
const XDG_CURRENT_DESKTOP = process.env.XDG_CURRENT_DESKTOP || 'unknown';
|
|
const GDMSESSION = process.env.GDMSESSION || 'unknown';
|
|
metadata['wm'] = `${XDG_CURRENT_DESKTOP},${GDMSESSION}`;
|
|
|
|
try {
|
|
metadata['distro'] = childProcess.execFileSync('lsb_release', ['-ds'], {
|
|
timeout: 100,
|
|
maxBuffer: 512,
|
|
encoding: 'utf-8'
|
|
}).trim();
|
|
} catch (_) {} // just in case lsb_release doesn't exist
|
|
|
|
}
|
|
|
|
function getCrashReporterArgs(metadata) {
|
|
// NB: we need to flatten the metadata because modern electron caps metadata values at 127 bytes,
|
|
// which our sentry subobject can easily exceed.
|
|
let flat_metadata = flatten(metadata);
|
|
return {
|
|
productName: 'Discord',
|
|
companyName: 'Discord Inc.',
|
|
submitURL: 'https://sentry.io/api/146342/minidump/?sentry_key=384ce4413de74fe0be270abe03b2b35a',
|
|
uploadToServer: true,
|
|
ignoreSystemCrashHandler: false,
|
|
extra: flat_metadata
|
|
};
|
|
}
|
|
|
|
electron.crashReporter.start(getCrashReporterArgs(metadata));
|
|
electron.ipcMain.handle(CRASH_REPORTER_UPDATE_METADATA, async (_, additional_metadata) => {
|
|
const final_metadata = lodash.defaultsDeep({}, metadata, additional_metadata || {});
|
|
const result = {
|
|
metadata: final_metadata
|
|
}; // In Electron 9 we only start the crashReporter once and let reconcileCrashReporterMetadata
|
|
// do the work of keeping `extra` up-to-date. Prior to this we would simply start crashReporter
|
|
// again to apply new metadata as well as pass the full arguments back to the renderer so it
|
|
// could do similarly.
|
|
|
|
if (getElectronMajorVersion() < 9) {
|
|
const args = getCrashReporterArgs(final_metadata);
|
|
electron.crashReporter.start(args);
|
|
result.args = args;
|
|
}
|
|
|
|
reconcileCrashReporterMetadata(electron.crashReporter, final_metadata);
|
|
return result;
|
|
}); |