electron/lib/browser/api/crash-reporter.ts

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

86 lines
2.5 KiB
TypeScript
Raw Normal View History

import * as deprecate from '@electron/internal/common/deprecate';
import { app } from 'electron/main';
const binding = process._linkedBinding('electron_browser_crash_reporter');
2016-01-12 02:40:23 +00:00
class CrashReporter implements Electron.CrashReporter {
start (options: Electron.CrashReporterStartOptions) {
const {
productName = app.name,
2017-10-31 02:51:22 +00:00
companyName,
extra = {},
globalExtra = {},
ignoreSystemCrashHandler = false,
submitURL = '',
uploadToServer = true,
rateLimit = false,
compress = true
} = options || {};
if (uploadToServer && !submitURL) throw new Error('submitURL must be specified when uploadToServer is true');
if (!compress && uploadToServer) {
deprecate.log('Sending uncompressed crash reports is deprecated and will be removed in a future version of Electron. Set { compress: true } to opt-in to the new behavior. Crash reports will be uploaded gzipped, which most crash reporting servers support.');
}
const appVersion = app.getVersion();
if (companyName && globalExtra._companyName == null) globalExtra._companyName = companyName;
const globalExtraAmended = {
_productName: productName,
_version: appVersion,
...globalExtra
};
binding.start(submitURL, uploadToServer,
ignoreSystemCrashHandler, rateLimit, compress, globalExtraAmended, extra, false);
}
2016-01-12 02:40:23 +00:00
getLastCrashReport () {
const reports = this.getUploadedReports()
2018-03-13 20:57:12 +00:00
.sort((a, b) => {
const ats = (a && a.date) ? new Date(a.date).getTime() : 0;
const bts = (b && b.date) ? new Date(b.date).getTime() : 0;
2018-03-13 20:57:12 +00:00
return bts - ats;
});
2017-10-31 02:51:22 +00:00
return (reports.length > 0) ? reports[0] : null;
}
2016-01-12 02:40:23 +00:00
getUploadedReports (): Electron.CrashReport[] {
return binding.getUploadedReports();
}
2016-01-12 02:40:23 +00:00
2016-11-22 08:30:20 +00:00
getUploadToServer () {
if (process.type === 'browser') {
2017-02-02 21:00:00 +00:00
return binding.getUploadToServer();
} else {
2016-11-22 08:30:20 +00:00
throw new Error('getUploadToServer can only be called from the main process');
}
2016-11-08 00:03:57 +00:00
}
setUploadToServer (uploadToServer: boolean) {
if (process.type === 'browser') {
2017-02-02 21:00:00 +00:00
return binding.setUploadToServer(uploadToServer);
} else {
2016-11-22 08:30:20 +00:00
throw new Error('setUploadToServer can only be called from the main process');
}
2016-11-08 00:03:57 +00:00
}
2017-02-02 22:23:21 +00:00
addExtraParameter (key: string, value: string) {
binding.addExtraParameter(key, value);
}
removeExtraParameter (key: string) {
binding.removeExtraParameter(key);
}
getParameters () {
2017-10-31 17:51:44 +00:00
return binding.getParameters();
}
}
export default new CrashReporter();