Browse Source

Ensure Sentry is correctly loaded in main, renderer, and child processes

master
meriadec 7 years ago
parent
commit
159a507083
No known key found for this signature in database GPG Key ID: 1D2FC2305E2CB399
  1. 1
      .eslintrc
  2. 7
      src/init-sentry.js
  3. 13
      src/internals/index.js
  4. 14
      src/main/index.js
  5. 63
      src/renderer/index.js
  6. 59
      src/renderer/init.js

1
.eslintrc

@ -29,6 +29,7 @@
"no-shadow": 0,
"no-underscore-dangle": 0,
"no-void": 0,
"global-require": 0,
"react/forbid-prop-types": 0,
"react/jsx-curly-brace-presence": 0,
"react/jsx-filename-extension": 0,

7
src/init-sentry.js

@ -0,0 +1,7 @@
const { SENTRY_URL } = process.env
if (__PROD__ && SENTRY_URL) {
const Raven = require('raven')
const ravenConfig = { captureUnhandledRejections: true }
Raven.config(SENTRY_URL, ravenConfig).install()
}

13
src/internals/index.js

@ -5,20 +5,17 @@ import capitalize from 'lodash/capitalize'
import cpuUsage from 'helpers/cpuUsage'
const { FORK_TYPE, SENTRY_URL } = process.env
require('../env')
require('../init-sentry')
process.title = `${require('../../package.json').productName} ${capitalize(FORK_TYPE)}` // eslint-disable-line global-require
const { FORK_TYPE } = process.env
process.title = `${require('../../package.json').productName} ${capitalize(FORK_TYPE)}`
function sendEvent(type: string, data: any, options: Object = { kill: true }) {
process.send({ type, data, options })
}
if (__PROD__ && SENTRY_URL) {
const Raven = require('raven') // eslint-disable-line global-require
const ravenConfig = { captureUnhandledRejections: true }
Raven.config(SENTRY_URL, ravenConfig).install()
}
// $FlowFixMe
const func = require(`./${FORK_TYPE}`) // eslint-disable-line import/no-dynamic-require

14
src/main/index.js

@ -1,18 +1,10 @@
// @flow
require('env')
const { SENTRY_URL } = process.env
if (__PROD__ && SENTRY_URL) {
const Raven = require('raven') // eslint-disable-line global-require
const ravenConfig = { captureUnhandledRejections: true }
Raven.config(SENTRY_URL, ravenConfig).install()
}
process.setMaxListeners(0)
require('../env')
require('../globals')
require('../init-sentry')
require('./app')
setImmediate(() => require('./bridge')) // eslint-disable-line global-require
setImmediate(() => require('./bridge'))

63
src/renderer/index.js

@ -1,27 +1,6 @@
// @flow
const Raven = require('raven-js')
import 'env'
import React from 'react'
import Raven from 'raven-js'
import { remote } from 'electron'
import { render } from 'react-dom'
import { AppContainer } from 'react-hot-loader'
import createHistory from 'history/createHashHistory'
import createStore from 'renderer/createStore'
import events from 'renderer/events'
import { fetchAccounts } from 'actions/accounts'
import { fetchSettings } from 'actions/settings'
import { isLocked } from 'reducers/application'
import { getLanguage } from 'reducers/settings'
import db from 'helpers/db'
import App from 'components/App'
import 'styles/global'
require('../env')
const { SENTRY_URL } = process.env
@ -30,40 +9,4 @@ if (__PROD__ && SENTRY_URL) {
window.addEventListener('unhandledrejection', event => Raven.captureException(event.reason))
}
// init db with defaults if needed
db.init('accounts', [])
db.init('settings', {})
const history = createHistory()
const store = createStore(history)
const rootNode = document.getElementById('app')
store.dispatch(fetchSettings())
const state = store.getState() || {}
const language = getLanguage(state)
const locked = isLocked(state)
if (!locked) {
store.dispatch(fetchAccounts())
}
function r(Comp) {
if (rootNode) {
render(<AppContainer>{Comp}</AppContainer>, rootNode)
}
}
r(<App store={store} history={history} language={language} />)
// Only init events on MainWindow
if (remote.getCurrentWindow().name === 'MainWindow') {
events({ store, locked })
}
if (module.hot) {
module.hot.accept('../components/App', () => {
const NewApp = require('../components/App').default // eslint-disable-line global-require
r(<NewApp store={store} history={history} language={language} />)
})
}
require('./init')

59
src/renderer/init.js

@ -0,0 +1,59 @@
// @flow
import React from 'react'
import { remote } from 'electron'
import { render } from 'react-dom'
import { AppContainer } from 'react-hot-loader'
import createHistory from 'history/createHashHistory'
import createStore from 'renderer/createStore'
import events from 'renderer/events'
import { fetchAccounts } from 'actions/accounts'
import { fetchSettings } from 'actions/settings'
import { isLocked } from 'reducers/application'
import { getLanguage } from 'reducers/settings'
import db from 'helpers/db'
import App from 'components/App'
import 'styles/global'
// init db with defaults if needed
db.init('accounts', [])
db.init('settings', {})
const history = createHistory()
const store = createStore(history)
const rootNode = document.getElementById('app')
store.dispatch(fetchSettings())
const state = store.getState() || {}
const language = getLanguage(state)
const locked = isLocked(state)
if (!locked) {
store.dispatch(fetchAccounts())
}
function r(Comp) {
if (rootNode) {
render(<AppContainer>{Comp}</AppContainer>, rootNode)
}
}
r(<App store={store} history={history} language={language} />)
// Only init events on MainWindow
if (remote.getCurrentWindow().name === 'MainWindow') {
events({ store, locked })
}
if (module.hot) {
module.hot.accept('../components/App', () => {
const NewApp = require('../components/App').default
r(<NewApp store={store} history={history} language={language} />)
})
}
Loading…
Cancel
Save