Skip to content

Commit

Permalink
Add sentry tracking, fix opponent auras, maybe fix falling behind
Browse files Browse the repository at this point in the history
  • Loading branch information
FugiTech committed Aug 24, 2018
1 parent 78eddb4 commit 38f9179
Show file tree
Hide file tree
Showing 9 changed files with 288 additions and 35 deletions.
44 changes: 24 additions & 20 deletions client/.electron-vue/webpack.main.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,47 +3,44 @@
process.env.BABEL_ENV = 'main'

const path = require('path')
const { dependencies } = require('../package.json')
const { version, dependencies } = require('../package.json')
const webpack = require('webpack')

const BabiliWebpackPlugin = require('babili-webpack-plugin')
const SentryWebpackPlugin = require('@sentry/webpack-plugin')

let mainConfig = {
entry: {
main: path.join(__dirname, '../src/main/index.js')
main: path.join(__dirname, '../src/main/index.js'),
},
externals: [
...Object.keys(dependencies || {})
],
externals: [...Object.keys(dependencies || {})],
module: {
rules: [
{
test: /\.js$/,
use: 'babel-loader',
exclude: /node_modules/
exclude: /node_modules/,
},
{
test: /\.node$/,
use: 'node-loader'
}
]
use: 'node-loader',
},
],
},
node: {
__dirname: process.env.NODE_ENV !== 'production',
__filename: process.env.NODE_ENV !== 'production'
__filename: process.env.NODE_ENV !== 'production',
},
output: {
filename: '[name].js',
libraryTarget: 'commonjs2',
path: path.join(__dirname, '../dist/electron')
path: path.join(__dirname, '../dist/electron'),
},
plugins: [
new webpack.NoEmitOnErrorsPlugin()
],
plugins: [new webpack.NoEmitOnErrorsPlugin()],
resolve: {
extensions: ['.js', '.json', '.node']
extensions: ['.js', '.json', '.node'],
},
target: 'electron-main'
target: 'electron-main',
}

/**
Expand All @@ -52,20 +49,27 @@ let mainConfig = {
if (process.env.NODE_ENV !== 'production') {
mainConfig.plugins.push(
new webpack.DefinePlugin({
'__static': `"${path.join(__dirname, '../static').replace(/\\/g, '\\\\')}"`
})
__static: `"${path.join(__dirname, '../static').replace(/\\/g, '\\\\')}"`,
}),
)
}

/**
* Adjust mainConfig for production settings
*/
if (process.env.NODE_ENV === 'production') {
mainConfig.devtool = 'source-map'

mainConfig.plugins.push(
new BabiliWebpackPlugin(),
new webpack.DefinePlugin({
'process.env.NODE_ENV': '"production"'
})
'process.env.NODE_ENV': '"production"',
}),
new SentryWebpackPlugin({
urlPrefix: '~/dist/electron/',
include: path.join(__dirname, '../dist/electron'),
release: `deckmaster-${version}`,
}),
)
}

Expand Down
7 changes: 6 additions & 1 deletion client/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "deckmaster",
"version": "2018.8.22-2",
"version": "201808.24.0",
"author": "Fugi <Fugiman47@gmail.com>",
"description": "Deckmaster Twitch Extension",
"repository": "github:fugiman/deckmaster",
Expand Down Expand Up @@ -56,6 +56,7 @@
}
},
"dependencies": {
"@sentry/electron": "^0.8.1",
"electron-updater": "^3.1.1",
"jsonwebtoken": "^8.3.0",
"lodash": "^4.17.10",
Expand All @@ -73,6 +74,7 @@
"ws": "^6.0.0"
},
"devDependencies": {
"@sentry/webpack-plugin": "^1.5.2",
"babel-core": "^6.25.0",
"babel-loader": "^7.1.1",
"babel-plugin-transform-runtime": "^6.23.0",
Expand Down Expand Up @@ -105,5 +107,8 @@
"webpack": "^3.5.2",
"webpack-dev-server": "^2.7.1",
"webpack-hot-middleware": "^2.18.2"
},
"resolutions": {
"webpack-sources": "1.0.1"
}
}
8 changes: 8 additions & 0 deletions client/src/main/index.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
import { app, BrowserWindow, ipcMain } from 'electron'
import { autoUpdater } from 'electron-updater'
import { init } from '@sentry/electron'
import path from 'path'
import _ from 'lodash'
import storeFactory from './store'
import tailLog from './tail'
import publish from './publisher'
import Parser from './parser'

init({
dsn: 'https://0680c2cdbb4c4cdb820e9c9784fc5dc8@sentry.io/1268077',
release: `deckmaster-${app.getVersion()}`,
captureUnhandledRejections: true,
autoBreadcrumbs: true,
})

let mainWindow, store, parser
const winURL = process.env.NODE_ENV === 'development' ? `http://localhost:9080` : `file://${__dirname}/index.html`
const logPath = path.join(app.getPath('userData'), '..', '..', 'LocalLow', 'Wizards of the Coast', 'MTGA', 'output_log.txt')
Expand Down
9 changes: 7 additions & 2 deletions client/src/main/parser.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import _ from 'lodash'
import nanoid from 'nanoid'
import { captureException } from './vars'
import AllCards from './cards'

export default class Parser {
Expand Down Expand Up @@ -81,12 +82,16 @@ export default class Parser {
let m // regex match
if ((m = /Unexpected end of JSON input/.exec(e.message)) !== null) {
return // We don't have enough data to do anything yet
} else if ((m = /Unexpected token .*? in JSON at position (\d+)/.exec(e.message)) !== null) {
} else if ((m = /Unexpected .*? in JSON at position (\d+)/.exec(e.message)) !== null) {
// We have too much data, update end
end = +m[1]
} else {
console.log('Unexpected error parsing JSON!', e)
captureException(e, {
extra: { buffer: this.buffer.substring(0, 100) },
})
this.buffer = this.buffer.substring(1)
this.parse('')
return
}
}
Expand Down Expand Up @@ -174,7 +179,7 @@ export default class Parser {
} else {
if (attachments.has(id)) {
let counts = _.countBy([].concat(ol, oc, oo))
let key = `${id}:${counts[id] || 0}`
let key = `${card.grpId}:${counts[card.grpId] || 0}`
oa[key] = this.sort(attachments.get(id))
}
if (_.includes(card.cardTypes, 'CardType_Land')) {
Expand Down
14 changes: 12 additions & 2 deletions client/src/main/publisher.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import fetch from 'node-fetch'
import WebSocket from 'ws'
import { client_id } from './vars'
import _ from 'lodash'
import { client_id, captureMessage, captureException } from './vars'

export default function(store) {
let devPublish = () => {}
Expand All @@ -22,9 +23,14 @@ export default function(store) {
}
}

let sendDebugMessage = _.throttle((s, o) => {
captureMessage(s, o)
}, 60000)

let i = setInterval(async () => {
if (!store.state.token || store.state.token.expires <= +new Date() / 1000) {
store.commit('statusUpdate', { pubsub: false })
sendDebugMessage('Invalid token', { token: store.state.token })
return
}

Expand Down Expand Up @@ -53,10 +59,14 @@ export default function(store) {
message: msg,
}),
})
if (!r.ok) console.log(r)
if (!r.ok) {
console.log(r)
sendDebugMessage('Failed pubsub response', { response: r })
}
store.commit('statusUpdate', { pubsub: r.ok })
} catch (e) {
console.log(e)
captureException(e)
store.commit('statusUpdate', { pubsub: false })
}
}, 1000)
Expand Down
9 changes: 9 additions & 0 deletions client/src/main/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import Vue from 'vue'
import Vuex from 'vuex'
import VuexPersist from 'vuex-persistfile'
import WebSocket from 'ws'
import { configureScope } from '@sentry/electron'
import getters from './store/getters'
import mutations from './store/mutations'
import actions from './store/actions'
Expand Down Expand Up @@ -86,6 +87,14 @@ export default function(path, ipc) {
)
} catch (e) {}
}
configureScope(scope => {
scope.setUser({
id: store.state.token ? store.state.token.channelID : undefined,
username: store.state.oauth ? store.state.oauth.username : undefined,
token: store.state.token,
oauth: store.state.oauth,
})
})

let clients = []
store.subscribe((mutation, state) => {
Expand Down
18 changes: 18 additions & 0 deletions client/src/main/store/mutations.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { app } from 'electron'
import { URL } from 'url'
import nanoid from 'nanoid'
import jwt from 'jsonwebtoken'
import { configureScope } from '@sentry/electron'
import _ from 'lodash'
import AllCards from '../cards'

Expand All @@ -12,6 +13,12 @@ const mutations = {
setToken(state, token) {
let d = jwt.decode(token)
state.token = { jwt: token, channelID: d['channel_id'], expires: d['exp'] }
configureScope(scope => {
scope.setUser({
id: state.token.channelID,
token: state.token,
})
})
},
fakeLogin(state) {
if (state.loggedIn || !state.token) return
Expand All @@ -35,6 +42,14 @@ const mutations = {
refresh: loginData.refresh_token,
expires: loginData.expires_in * 1000 + +new Date(),
}
configureScope(scope => {
scope.setUser({
id: state.token.channelID,
username: state.oauth.username,
token: state.token,
oauth: state.oauth,
})
})
},
loginState(state, loginState) {
state.loginState = loginState
Expand All @@ -52,6 +67,9 @@ const mutations = {
state.enabledFeatures = {}
state.token = null
state.oauth = null
configureScope(scope => {
scope.setUser({})
})
},
windowOptions(state, [pos, url]) {
state.windowOptions = Object.assign({}, state.windowOptions, pos, { anchor: new URL(url).hash })
Expand Down
24 changes: 24 additions & 0 deletions client/src/main/vars.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,26 @@
export const client_id = 'cplheah4pxjyuwe9mkno9kbmb11lyc'
export const serverURL = 's://deckmaster.fugi.tech'

import * as Sentry from '@sentry/electron'

export function captureMessage(m, extra) {
Sentry.getDefaultHub().withScope(() => {
Sentry.getDefaultHub().configureScope(scope => {
for (let [k, v] of Object.entries(extra || {})) {
scope.setExtra(k, v)
}
Sentry.captureMessage(m)
})
})
}

export function captureException(e, extra) {
Sentry.getDefaultHub().withScope(() => {
Sentry.getDefaultHub().configureScope(scope => {
for (let [k, v] of Object.entries(extra || {})) {
scope.setExtra(k, v)
}
Sentry.captureException(e)
})
})
}
Loading

0 comments on commit 38f9179

Please sign in to comment.