Skip to content

Commit

Permalink
refactor: Track resource metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
ci010 committed May 28, 2023
1 parent b1e716b commit 9644265
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions xmcl-runtime/lib/plugins/pluginTelemetry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import { kTelemtrySession, APP_INSIGHT_KEY } from '../entities/telemetry'
import { LaunchService } from '../services/LaunchService'
import { UserService } from '../services/UserService'
import { BaseService } from '../services/BaseService'
import { ResourceService } from '../services/ResourceService'
import { Resource } from '@xmcl/runtime-api'

export const pluginTelemetry: LauncherAppPlugin = async (app) => {
if (IS_DEV) {
Expand Down Expand Up @@ -115,6 +117,30 @@ export const pluginTelemetry: LauncherAppPlugin = async (app) => {
})
})

app.serviceManager.get(ResourceService).on('resourceAdd', (res: Resource) => {
if (baseService.state.disableTelemetry) return
appInsight.defaultClient.trackEvent({
name: 'resource-metadata',
properties: {
fileName: res.fileName,
domain: res.domain,
sha1: res.hash,
metadata: res.metadata,
},
})
}).on('resourceUpdate', (res: Resource) => {
if (baseService.state.disableTelemetry) return
appInsight.defaultClient.trackEvent({
name: 'resource-metadata',
properties: {
fileName: res.fileName,
domain: res.domain,
sha1: res.hash,
metadata: res.metadata,
},
})
})

app.serviceManager.get(UserService).on('user-login', (authService) => {
if (baseService.state.disableTelemetry) return
appInsight.defaultClient.trackEvent({
Expand Down

0 comments on commit 9644265

Please sign in to comment.