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

84 lines
2.4 KiB
TypeScript
Raw Normal View History

import { app, deprecate } from 'electron/main';
const binding = process._linkedBinding('electron_browser_crash_reporter');
2016-01-12 02:40:23 +00:00
class 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) => {
2020-03-20 20:28:31 +00:00
const ats = (a && a.date) ? new Date(a.date).getTime() : 0;
const bts = (b && b.date) ? new Date(b.date).getTime() : 0;
return bts - ats;
});
2018-03-13 20:57:12 +00:00
2020-03-20 20:28:31 +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') {
2020-03-20 20:28:31 +00:00
return binding.getUploadToServer();
} else {
2020-03-20 20:28:31 +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') {
2020-03-20 20:28:31 +00:00
return binding.setUploadToServer(uploadToServer);
} else {
2020-03-20 20:28:31 +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) {
2020-03-20 20:28:31 +00:00
binding.addExtraParameter(key, value);
}
removeExtraParameter (key: string) {
2020-03-20 20:28:31 +00:00
binding.removeExtraParameter(key);
}
getParameters () {
2020-03-20 20:28:31 +00:00
return binding.getParameters();
}
}
export default new CrashReporter();