perf: disable tracking in development environment

This commit is contained in:
Lykin 2024-03-15 16:31:39 +08:00
parent af6748ac59
commit bb9c25a880
2 changed files with 6 additions and 16 deletions

View File

@ -14,7 +14,7 @@ import useConnectionStore from './stores/connections.js'
import { useI18n } from 'vue-i18n' import { useI18n } from 'vue-i18n'
import { darkTheme, NButton, NSpace } from 'naive-ui' import { darkTheme, NButton, NSpace } from 'naive-ui'
import KeyFilterDialog from './components/dialogs/KeyFilterDialog.vue' import KeyFilterDialog from './components/dialogs/KeyFilterDialog.vue'
import { WindowSetDarkTheme, WindowSetLightTheme } from 'wailsjs/runtime/runtime.js' import { Environment, WindowSetDarkTheme, WindowSetLightTheme } from 'wailsjs/runtime/runtime.js'
import { darkThemeOverrides, themeOverrides } from '@/utils/theme.js' import { darkThemeOverrides, themeOverrides } from '@/utils/theme.js'
import AboutDialog from '@/components/dialogs/AboutDialog.vue' import AboutDialog from '@/components/dialogs/AboutDialog.vue'
import FlushDbDialog from '@/components/dialogs/FlushDbDialog.vue' import FlushDbDialog from '@/components/dialogs/FlushDbDialog.vue'
@ -22,8 +22,7 @@ import ExportKeyDialog from '@/components/dialogs/ExportKeyDialog.vue'
import ImportKeyDialog from '@/components/dialogs/ImportKeyDialog.vue' import ImportKeyDialog from '@/components/dialogs/ImportKeyDialog.vue'
import { Info } from 'wailsjs/go/services/systemService.js' import { Info } from 'wailsjs/go/services/systemService.js'
import DecoderDialog from '@/components/dialogs/DecoderDialog.vue' import DecoderDialog from '@/components/dialogs/DecoderDialog.vue'
import { enableTrack, loadModule, trackEvent } from '@/utils/analytics.js' import { loadModule, trackEvent } from '@/utils/analytics.js'
import { endsWith } from 'lodash'
const prefStore = usePreferencesStore() const prefStore = usePreferencesStore()
const connectionStore = useConnectionStore() const connectionStore = useConnectionStore()
@ -38,13 +37,10 @@ onMounted(async () => {
if (prefStore.autoCheckUpdate) { if (prefStore.autoCheckUpdate) {
prefStore.checkForUpdate() prefStore.checkForUpdate()
} }
loadModule(prefStore.general.allowTrack !== false).then(() => { const env = await Environment()
loadModule(env.buildType !== 'dev' && prefStore.general.allowTrack !== false).then(() => {
Info().then(({ data }) => { Info().then(({ data }) => {
if (endsWith(data.version, 'dev')) { trackEvent('startup', data, true)
enableTrack(false)
} else {
trackEvent('startup', data, true)
}
}) })
}) })

View File

@ -1,5 +1,4 @@
let inited = false let inited = false
let allow = false
/** /**
* load umami analytics module * load umami analytics module
@ -7,7 +6,6 @@ let allow = false
* @return {Promise<void>} * @return {Promise<void>}
*/ */
export const loadModule = async (allowTrack = true) => { export const loadModule = async (allowTrack = true) => {
allow = allowTrack !== false
await new Promise((resolve, reject) => { await new Promise((resolve, reject) => {
const script = document.createElement('script') const script = document.createElement('script')
script.setAttribute('src', 'https://analytics.tinycraft.cc/script.js') script.setAttribute('src', 'https://analytics.tinycraft.cc/script.js')
@ -27,11 +25,7 @@ export const loadModule = async (allowTrack = true) => {
} }
const enable = () => { const enable = () => {
return inited && allow && umami return inited && umami
}
export const enableTrack = (enable) => {
allow = enable
} }
export const trackEvent = async (event, data) => { export const trackEvent = async (event, data) => {