|
| 1 | +// modeled after https://github.com/codeforscience/sciencefair/blob/444bb75e0c73cc1e632ec833b98ba2d693668cde/app/client/lib/raven.js#L41 |
| 2 | +var os = require('os') |
| 3 | + |
| 4 | +var RAVEN_A = '3e06dec4e996422080e1853bdb663246' // eh.. can we get these out of source code? |
| 5 | +var RAVEN_B = '7e4004b4423044b3b19d2f4523748552' |
| 6 | +var RAVEN_C = '243594' |
| 7 | + |
| 8 | +var MAIN_THREAD = 'browser' |
| 9 | +var RENDERER = 'renderer' |
| 10 | + |
| 11 | +function getopts (processtype, name) { |
| 12 | + return { |
| 13 | + captureUnhandledRejections: true, |
| 14 | + name: name || 'Hyperamp', |
| 15 | + release: require('./package.json').version, |
| 16 | + extra: { |
| 17 | + platform: os.platform(), |
| 18 | + process: processtype, |
| 19 | + release: os.release(), |
| 20 | + arch: os.arch(), |
| 21 | + totalmem: os.totalmem() |
| 22 | + }, |
| 23 | + sendTimeout: 5, |
| 24 | + allowSecretKey: processtype === 'browser', |
| 25 | + debug: true |
| 26 | + } |
| 27 | +} |
| 28 | + |
| 29 | +function setup (name) { |
| 30 | + // process.type === 'browser' : main thread |
| 31 | + // process.type === 'renderer' : electron window |
| 32 | + var raven = process.type === MAIN_THREAD ? require('raven') : require('raven-js') |
| 33 | + var url = process.type === MAIN_THREAD ? `https://${RAVEN_A}:${RAVEN_B}@sentry.io/${RAVEN_C}` : `https://${RAVEN_A}@sentry.io/${RAVEN_C}` |
| 34 | + |
| 35 | + if (process.type === MAIN_THREAD) { |
| 36 | + // Main thread stuff only |
| 37 | + process.on('uncaughtException', (err) => { |
| 38 | + const dialog = require('electron').dialog |
| 39 | + |
| 40 | + dialog.showMessageBox({ |
| 41 | + title: 'An error occurred', |
| 42 | + message: `Sorry for the trouble, but an error has occurred in Hyperamp and we don't know how to recover from it. |
| 43 | +
|
| 44 | +If you are connected to the internet, this has been reported anonymously to the project maintainers - they will work on a fix. |
| 45 | +
|
| 46 | +The app may now quit - you can safely reopen it.`, |
| 47 | + detail: err.stack, |
| 48 | + buttons: ['OK'] |
| 49 | + }) |
| 50 | + }) |
| 51 | + } |
| 52 | + |
| 53 | + if (process.type === RENDERER) { |
| 54 | + // Renderer stuff only |
| 55 | + } |
| 56 | + |
| 57 | + var sentry = raven.config(url, getopts(process.type), name).install() |
| 58 | + console.log('Sentry installed') |
| 59 | + return sentry |
| 60 | +} |
| 61 | + |
| 62 | +module.exports = setup |
0 commit comments