2020-05-07 13:31:26 -07:00
|
|
|
import { app } from 'electron';
|
2016-03-10 11:54:17 -08:00
|
|
|
|
2020-03-20 13:28:31 -07:00
|
|
|
const binding = process.electronBinding('crash_reporter');
|
2016-01-11 18:40:23 -08:00
|
|
|
|
2016-10-05 13:40:39 -07:00
|
|
|
class CrashReporter {
|
2020-05-07 13:31:26 -07:00
|
|
|
start (options: Electron.CrashReporterStartOptions) {
|
2019-03-28 15:04:16 -04:00
|
|
|
const {
|
2020-05-07 13:31:26 -07:00
|
|
|
productName = app.name,
|
2017-10-30 22:51:22 -04:00
|
|
|
companyName,
|
2019-03-28 15:04:16 -04:00
|
|
|
extra = {},
|
2020-05-07 13:31:26 -07:00
|
|
|
globalExtra = {},
|
2019-03-28 15:04:16 -04:00
|
|
|
ignoreSystemCrashHandler = false,
|
2017-10-30 22:51:22 -04:00
|
|
|
submitURL,
|
2020-04-14 10:36:31 -07:00
|
|
|
uploadToServer = true,
|
|
|
|
rateLimit = false,
|
|
|
|
compress = false
|
2020-05-07 13:31:26 -07:00
|
|
|
} = options || {};
|
2016-11-28 14:51:24 -08:00
|
|
|
|
2020-03-20 13:28:31 -07:00
|
|
|
if (submitURL == null) throw new Error('submitURL is a required option to crashReporter.start');
|
2016-10-05 13:40:39 -07:00
|
|
|
|
2020-05-07 13:31:26 -07:00
|
|
|
const appVersion = app.getVersion();
|
2018-09-26 07:43:34 +02:00
|
|
|
|
2020-05-07 13:31:26 -07:00
|
|
|
if (companyName && globalExtra._companyName == null) globalExtra._companyName = companyName;
|
2018-09-26 07:43:34 +02:00
|
|
|
|
2020-05-07 13:31:26 -07:00
|
|
|
const globalExtraAmended = {
|
|
|
|
_productName: productName,
|
|
|
|
_version: appVersion,
|
|
|
|
...globalExtra
|
|
|
|
};
|
2016-10-05 13:40:39 -07:00
|
|
|
|
2020-05-07 13:31:26 -07:00
|
|
|
binding.start(submitURL, uploadToServer,
|
|
|
|
ignoreSystemCrashHandler, rateLimit, compress, globalExtraAmended, extra, false);
|
2016-03-25 12:41:24 -07:00
|
|
|
}
|
2016-01-11 18:40:23 -08:00
|
|
|
|
2016-10-05 13:40:39 -07:00
|
|
|
getLastCrashReport () {
|
|
|
|
const reports = this.getUploadedReports()
|
2018-03-13 13:57:12 -07:00
|
|
|
.sort((a, b) => {
|
2020-03-20 13:28:31 -07: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 13:57:12 -07:00
|
|
|
|
2020-03-20 13:28:31 -07:00
|
|
|
return (reports.length > 0) ? reports[0] : null;
|
2016-03-25 12:41:24 -07:00
|
|
|
}
|
2016-01-11 18:40:23 -08:00
|
|
|
|
2020-05-07 13:31:26 -07:00
|
|
|
getUploadedReports (): Electron.CrashReport[] {
|
|
|
|
return binding.getUploadedReports();
|
2016-03-25 12:41:24 -07:00
|
|
|
}
|
2016-01-11 18:40:23 -08:00
|
|
|
|
2016-10-06 10:39:57 -07:00
|
|
|
getCrashesDirectory () {
|
2020-05-07 13:31:26 -07:00
|
|
|
return app.getPath('crashDumps');
|
2016-10-06 10:39:57 -07:00
|
|
|
}
|
|
|
|
|
2016-11-22 19:30:20 +11:00
|
|
|
getUploadToServer () {
|
2016-11-08 13:39:11 +13:00
|
|
|
if (process.type === 'browser') {
|
2020-03-20 13:28:31 -07:00
|
|
|
return binding.getUploadToServer();
|
2016-11-08 13:39:11 +13:00
|
|
|
} else {
|
2020-03-20 13:28:31 -07:00
|
|
|
throw new Error('getUploadToServer can only be called from the main process');
|
2016-11-08 13:39:11 +13:00
|
|
|
}
|
2016-11-08 11:03:57 +11:00
|
|
|
}
|
|
|
|
|
2020-05-07 13:31:26 -07:00
|
|
|
setUploadToServer (uploadToServer: boolean) {
|
2016-11-08 13:39:11 +13:00
|
|
|
if (process.type === 'browser') {
|
2020-03-20 13:28:31 -07:00
|
|
|
return binding.setUploadToServer(uploadToServer);
|
2016-11-08 13:39:11 +13:00
|
|
|
} else {
|
2020-03-20 13:28:31 -07:00
|
|
|
throw new Error('setUploadToServer can only be called from the main process');
|
2016-11-08 13:39:11 +13:00
|
|
|
}
|
2016-11-08 11:03:57 +11:00
|
|
|
}
|
2017-02-02 14:23:21 -08:00
|
|
|
|
2020-05-07 13:31:26 -07:00
|
|
|
addExtraParameter (key: string, value: string) {
|
2020-03-20 13:28:31 -07:00
|
|
|
binding.addExtraParameter(key, value);
|
2017-11-01 21:57:43 -04:00
|
|
|
}
|
|
|
|
|
2020-05-07 13:31:26 -07:00
|
|
|
removeExtraParameter (key: string) {
|
2020-03-20 13:28:31 -07:00
|
|
|
binding.removeExtraParameter(key);
|
2017-11-01 21:57:43 -04:00
|
|
|
}
|
|
|
|
|
2019-03-28 15:04:16 -04:00
|
|
|
getParameters () {
|
2020-03-20 13:28:31 -07:00
|
|
|
return binding.getParameters();
|
2017-10-31 13:06:54 -04:00
|
|
|
}
|
2016-10-06 10:02:46 -07:00
|
|
|
}
|
|
|
|
|
2020-05-07 13:31:26 -07:00
|
|
|
export default new CrashReporter();
|