Merge branch 'analytics' into dev

This commit is contained in:
Kylart 2019-07-13 15:31:21 +02:00
commit 42b51d91df
9 changed files with 72 additions and 6 deletions

View File

@ -1,3 +1,6 @@
VUE_APP_KAWANIME_API_URL=
VUE_APP_KAWANIME_SECRET=
VUE_APP_ANILIST_CLIENT_ID=
VUE_APP_ANILIST_CLIENT_SECRET=

View File

@ -0,0 +1,31 @@
import { readFileSync } from 'fs'
import { eventsList } from '../../../../vendor'
import { Logger, https } from '../../utils'
import { localFiles } from '../../externals'
const events = eventsList.analytics
const secretKey = process.env.VUE_APP_KAWANIME_SECRET
const ANALYTICS_URL = process.env.VUE_APP_KAWANIME_API_URL
const VERSION = process.env.KAWANIME_VERSION
const userToken = readFileSync(localFiles.getPath('_token'))
const logger = new Logger('Analytics')
async function send (event, { eventName, data }) {
https.post(`${ANALYTICS_URL}/analytics`, {
eventName,
data,
userToken,
version: VERSION
}, [], { Authorization: `Bearer ${secretKey}` })
.catch(() => {
// We ignore errors
logger.error(`Could not send ${eventName} analytics event.`)
})
}
export default {
eventName: events.main,
handler: send
}

View File

@ -13,6 +13,7 @@ import isOnline from './isOnline'
import vault from './vault'
import watchLists from './watchLists'
import registerService from './registerService'
import analytics from './analytics'
const services = [
...config,
@ -29,7 +30,8 @@ const services = [
news,
seasons,
episodes,
isOnline
isOnline,
analytics
]
// auto update

View File

@ -32,7 +32,8 @@ export default {
darkTheme: true,
autoStart: false,
toTray: false,
center: true
center: true,
analytics: true
},
bounds: {
height: null,

View File

@ -6,7 +6,7 @@
v-card-text
v-container(grid-list-lg, pa-0, pb-2)
v-layout(row, wrap, justify-space-around, align-center)
v-flex(xs12, sm4)
v-flex(xs12, sm3)
v-switch.mt-0(
v-model='tray',
color='primary',
@ -14,7 +14,7 @@
persistent-hint,
hint='*Should KawAnime be in your tray?'
)
v-flex(xs12, sm4)
v-flex(xs12, sm3)
v-switch.mt-0(
v-model='autoStart',
color='primary',
@ -22,7 +22,7 @@
persistent-hint,
hint='*Should KawAnime start on boot?'
)
v-flex(xs12, sm4)
v-flex(xs12, sm3)
v-switch.mt-0(
v-model='darkTheme',
color='primary',
@ -30,6 +30,14 @@
persistent-hint,
hint='Theme to apply'
)
v-flex(xs12, sm3)
v-switch.mt-0(
v-model='analytics',
color='primary',
:label="analytics ? 'Ok' : 'Nope'"
persistent-hint,
hint='Allows the app to send events to our server (mainly to know how many users we have)'
)
v-container(grid-list-lg, pa-0, mt-3)
v-layout(row, wrap, justify-space-around, align-center)
@ -144,6 +152,14 @@ export default {
this.setDeepValue('system.darkTheme', val)
}
},
analytics: {
get () {
return this.system.analytics
},
set (val) {
this.setDeepValue('system.analytics', val)
}
},
height: {
get () {
return this.bounds.height

View File

@ -32,6 +32,14 @@ export default {
checkOnlineStatus () {
ipcRenderer.send(eventsList.isOnline.main)
},
analytics ({ state }, args) {
const { config: { system: { analytics } } } = state.config
if (analytics) {
ipcRenderer.send(eventsList.analytics.main, args)
}
},
setEvents ({ state, commit, dispatch }) {
ipcRenderer.on(eventsList.isOnline.success, (e) => {
const isConnected = state.isConnected

View File

@ -4,6 +4,8 @@ export const get = {
success ({ commit, dispatch }, data) {
commit('set', data.config)
dispatch('analytics', { eventName: 'appOpen' }, isRoot)
// Setting defaults
dispatch('player/setUp', null, isRoot)
commit('localFiles/setDir', data.config.localPath, isRoot)

View File

@ -19,7 +19,8 @@ const getOnly = [
// Internal
'env',
'isOnline',
'externalOpen'
'externalOpen',
'analytics'
]
const updatable = [

View File

@ -1,6 +1,8 @@
const fs = require('fs')
const path = require('path')
process.env.KAWANIME_VERSION = JSON.parse(fs.readFileSync(path.resolve(__dirname, 'package.json'))).version
/**
* Taken from https://gist.github.com/kethinov/6658166#gistcomment-2389484
*