Skip to content

Commit

Permalink
feat: support disable telemetry & hide news
Browse files Browse the repository at this point in the history
  • Loading branch information
ci010 committed May 3, 2023
1 parent fd4b700 commit 1d03cd7
Show file tree
Hide file tree
Showing 12 changed files with 86 additions and 20 deletions.
7 changes: 7 additions & 0 deletions xmcl-keystone-ui/locales/en.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ browseApp:
cancel: Cancel
checkUpdate:
name: Check Update
compatibleDetail:
current: Current
requirements: Requirements
confirm: Start
copyClipboard:
success: Copy to clipboard
Expand Down Expand Up @@ -1104,10 +1107,14 @@ setting:
darkThemeDescription: Choose the dark or light theme
developerMode: Developer Mode
developerModeDescription: Developer Mode is targeting to test your own written mod
disableTelemetry: Disable Telemetry
disableTelemetryDescription: XMCL will collect the game launch and user login events.
general: General
githubRelease: Github Release
globalSetting: Global Instance Setting
globalSettingHint: Instance will use these settings by default.
hideNews: Hide News
hideNewsDescription: This will hide the news under the instance page
language: Language
languageDescription: The display language
latestVersion: Latest Version
Expand Down
8 changes: 8 additions & 0 deletions xmcl-keystone-ui/locales/zh-CN.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ browseApp:
cancel: 取消
checkUpdate:
name: 检查更新
compatibleDetail:
current: 当前版本
id: Id
requirements: 兼容版本
confirm: 开始
copyClipboard:
success: 复制到剪贴板
Expand Down Expand Up @@ -1084,10 +1088,14 @@ setting:
darkThemeDescription: 选择深色或浅色主题
developerMode: 开发者模式
developerModeDescription: 开发者模式意在于帮助你测试你自己写的 Mod
disableTelemetry: 关闭遥测
disableTelemetryDescription: XMCL 会收集游戏启动以及用户登录事件
general: 基本设置
githubRelease: Github
globalSetting: 全局实例设置
globalSettingHint: 实例默认情况下会使用这些全局设置
hideNews: 隐藏新闻
hideNewsDescription: 隐藏实例页面下的新闻
language: 语言
languageDescription: 当前显示的语言
latestVersion: 最新版本
Expand Down
8 changes: 8 additions & 0 deletions xmcl-keystone-ui/src/composables/setting.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { useService, useServiceBusy } from '@/composables'
import { BaseServiceKey } from '@xmcl/runtime-api'
import { useLocalStorageCacheBool } from './cache'

export function useUpdateSettings() {
const { state, checkUpdate } = useService(BaseServiceKey)
Expand All @@ -20,6 +21,7 @@ export function useUpdateSettings() {

export function useSettings() {
const { state } = useService(BaseServiceKey)
const hideNews = useLocalStorageCacheBool('hideNews', false)

const getProxy = () => {
const proxy = state.httpProxy
Expand Down Expand Up @@ -70,6 +72,10 @@ export function useSettings() {
get: () => state.developerMode,
set: v => state.developerModeSet(v),
})
const disableTelemetry = computed({
get: () => state.disableTelemetry,
set: v => state.disableTelemetrySet(v),
})
const apiSets = computed(() => state.apiSets)

onMounted(() => {
Expand Down Expand Up @@ -112,6 +118,8 @@ export function useSettings() {
autoInstallOnAppQuit,
apiSetsPreference,
apiSets,
disableTelemetry,
hideNews,
}
}

Expand Down
1 change: 0 additions & 1 deletion xmcl-keystone-ui/src/views/BaseSettingGeneral.vue
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
<v-list-item-title>
{{ t('instance.icon') }}
</v-list-item-title>
<v-list-item-subtitle>Drop file or link URL here to set icon</v-list-item-subtitle>
</v-list-item-content>
</v-list-item>
</v-list>
Expand Down
5 changes: 3 additions & 2 deletions xmcl-keystone-ui/src/views/HomeCardHost.vue
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
:id="instance.upstream.projectId.toString()"
/>
<GridLayout
v-else
v-else-if="!hideNews"
:layout.sync="newsLayout"
:is-draggable="false"
:col-num="12"
Expand Down Expand Up @@ -104,7 +104,7 @@
</template>
<script lang="ts" setup>
import { useLocalStorageCache } from '@/composables/cache'
import { useLocalStorageCache, useLocalStorageCacheBool } from '@/composables/cache'
import { kInstanceContext } from '@/composables/instanceContext'
import { kUpstream } from '@/composables/instanceUpdate'
import { useMojangNews } from '@/composables/mojangNews'
Expand Down Expand Up @@ -233,6 +233,7 @@ const onResized = (i: string, newH: number, newW: number, newHPx: number, newWPx
saveLayouts()
}
const hideNews = useLocalStorageCacheBool('hideNews', false)
const getRowCount = (width: number) => width ? Math.floor((width - 34) / 30) : 7
const resourcePackRowCount = computed(() => getRowCount(containerWidths[CardType.ResourcePack]))
const modRowCount = computed(() => getRowCount(containerWidths[CardType.Mod]))
Expand Down
28 changes: 28 additions & 0 deletions xmcl-keystone-ui/src/views/SettingGeneral.vue
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,32 @@
</v-btn>
</v-list-item-action>
</v-list-item>
<v-list-item @click="disableTelemetry = !disableTelemetry">
<v-list-item-action class="self-center">
<v-checkbox v-model="disableTelemetry" />
</v-list-item-action>
<v-list-item-content>
<v-list-item-title>
{{ t('setting.disableTelemetry') }}
</v-list-item-title>
<v-list-item-subtitle>
{{ t('setting.disableTelemetryDescription') }}
</v-list-item-subtitle>
</v-list-item-content>
</v-list-item>
<v-list-item @click="hideNews = !hideNews">
<v-list-item-action class="self-center">
<v-checkbox v-model="hideNews" />
</v-list-item-action>
<v-list-item-content>
<v-list-item-title>
{{ t('setting.hideNews') }}
</v-list-item-title>
<v-list-item-subtitle>
{{ t('setting.hideNewsDescription') }}
</v-list-item-subtitle>
</v-list-item-content>
</v-list-item>
<v-list-item>
<v-list-item-content>
<v-list-item-title>
Expand Down Expand Up @@ -187,6 +213,8 @@ const {
apiSetsPreference,
selectedLocale,
maxSockets,
disableTelemetry,
hideNews,
locales: rawLocales,
} = useSettings()
const { t } = useI18n()
Expand Down
5 changes: 5 additions & 0 deletions xmcl-runtime-api/src/entities/SettingSchema.json
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,10 @@
"developerMode": {
"default": false,
"type": "boolean"
},
"disableTelemetry": {
"default": false,
"type": "boolean"
}
},
"required": [
Expand All @@ -140,6 +144,7 @@
"autoDownload",
"autoInstallOnAppQuit",
"developerMode",
"disableTelemetry",
"discordPresence",
"globalAssignMemory",
"globalFastLaunch",
Expand Down
8 changes: 4 additions & 4 deletions xmcl-runtime-api/src/entities/UserSchema.json
Original file line number Diff line number Diff line change
Expand Up @@ -104,15 +104,15 @@
"type": "object",
"properties": {
"SKIN": {
"$ref": "#/definitions/GameProfile.Texture"
"$ref": "#/definitions/YggdrasilTexture"
},
"CAPE": {
"description": "The data structure that hold the texture",
"$ref": "#/definitions/GameProfile.Texture"
"$ref": "#/definitions/YggdrasilTexture"
},
"ELYTRA": {
"description": "The data structure that hold the texture",
"$ref": "#/definitions/GameProfile.Texture"
"$ref": "#/definitions/YggdrasilTexture"
}
},
"required": [
Expand Down Expand Up @@ -235,7 +235,7 @@
"textures"
]
},
"GameProfile.Texture": {
"YggdrasilTexture": {
"description": "The data structure that hold the texture",
"type": "object",
"properties": {
Expand Down
2 changes: 1 addition & 1 deletion xmcl-runtime-api/src/entities/setting.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,5 +107,5 @@ export interface SettingSchema {
/**
* @default false
*/
hideNews: boolean
disableTelemetry: boolean
}
6 changes: 5 additions & 1 deletion xmcl-runtime-api/src/services/BaseService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export interface MigrateOptions {
export class BaseState implements SettingSchema {
globalMinMemory = 0
globalMaxMemory = 0
hideNews = false
disableTelemetry = false
globalAssignMemory: 'auto' | boolean = false
globalVmOptions: string[] = []
globalMcOptions: string[] = []
Expand Down Expand Up @@ -187,6 +187,10 @@ export class BaseState implements SettingSchema {
this.maxAPISockets = val
}

disableTelemetrySet(disable: boolean) {
this.disableTelemetry = disable
}

globalInstanceSetting(settings: {
globalMinMemory: number
globalMaxMemory: number
Expand Down
26 changes: 15 additions & 11 deletions xmcl-runtime/lib/plugins/pluginTelemetry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { IS_DEV } from '../constant'
import { kTelemtrySession, APP_INSIGHT_KEY } from '../entities/telemetry'
import { LaunchService } from '../services/LaunchService'
import { UserService } from '../services/UserService'
import { BaseService } from '../services/BaseService'

export const pluginTelemetry: LauncherAppPlugin = async (app) => {
if (IS_DEV) {
Expand All @@ -26,17 +27,6 @@ export const pluginTelemetry: LauncherAppPlugin = async (app) => {

app.registry.register(kTelemtrySession, sessionId)

process.on('uncaughtException', (e) => {
if (appInsight.defaultClient) {
appInsight.defaultClient.trackException({ exception: e })
}
})
process.on('unhandledRejection', (e) => {
if (appInsight.defaultClient) {
appInsight.defaultClient.trackException({ exception: e as any }) // the applicationinsights will convert it to error automatically
}
})

appInsight.setup(APP_INSIGHT_KEY)
.setDistributedTracingMode(appInsight.DistributedTracingModes.AI_AND_W3C)
.setAutoCollectExceptions(true)
Expand All @@ -52,14 +42,27 @@ export const pluginTelemetry: LauncherAppPlugin = async (app) => {
tags[contract.applicationVersion] = `${app.version}#${app.build}`

app.on('engine-ready', () => {
const baseService = app.serviceManager.get(BaseService)
process.on('uncaughtException', (e) => {
if (appInsight.defaultClient) {
appInsight.defaultClient.trackException({ exception: e })
}
})
process.on('unhandledRejection', (e) => {
if (appInsight.defaultClient) {
appInsight.defaultClient.trackException({ exception: e as any }) // the applicationinsights will convert it to error automatically
}
})
app.serviceManager.get(LaunchService)
.on('minecraft-start', (options) => {
if (baseService.state.disableTelemtry) return
appInsight.defaultClient.trackEvent({
name: 'minecraft-start',
properties: options,
})
})
.on('minecraft-exit', ({ code, signal, crashReport }) => {
if (baseService.state.disableTelemtry) return
const normalExit = code === 0
const crashed = crashReport && crashReport.length > 0
if (normalExit) {
Expand All @@ -79,6 +82,7 @@ export const pluginTelemetry: LauncherAppPlugin = async (app) => {
})

app.serviceManager.get(UserService).on('user-login', (authService) => {
if (baseService.state.disableTelemtry) return
appInsight.defaultClient.trackEvent({
name: 'user-login',
properties: {
Expand Down
2 changes: 2 additions & 0 deletions xmcl-runtime/lib/services/BaseService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export class BaseService extends StatefulService<BaseState> implements IBaseServ
'discordPresenceSet',
'globalInstanceSetting',
'developerModeSet',
'disableTelemtrySet',
], () => {
this.settingFile.write({
locale: this.state.locale,
Expand All @@ -74,6 +75,7 @@ export class BaseService extends StatefulService<BaseState> implements IBaseServ
discordPresence: this.state.discordPresence,
developerMode: this.state.developerMode,
hideNews: this.state.hideNews,
disableTelemtry: this.state.disableTelemtry,
})
})
}
Expand Down

0 comments on commit 1d03cd7

Please sign in to comment.