feat: add telemetry to aware of the presence of other deployment instances

you can disable it by env DISABLE_TELEMETRY=1
pull/147/merge
moonrailgun 1 year ago
parent c7c05b5861
commit c25d3a0b46

@ -250,6 +250,7 @@ export {
isBrowser, isBrowser,
isNavigator, isNavigator,
isDevelopment, isDevelopment,
isProduction,
version, version,
} from './utils/environment'; } from './utils/environment';
export type { PermissionItemType } from './utils/role-helper'; export type { PermissionItemType } from './utils/role-helper';

@ -51,6 +51,11 @@ export interface GlobalConfig {
*/ */
disableAddFriend?: boolean; disableAddFriend?: boolean;
/**
*
*/
disableTelemetry?: boolean;
announcement?: announcement?:
| false | false
| { | {

@ -27,5 +27,6 @@ export const defaultGlobalConfig: GlobalConfig = {
disableCreateGroup: false, disableCreateGroup: false,
disablePluginStore: false, disablePluginStore: false,
disableAddFriend: false, disableAddFriend: false,
disableTelemetry: false,
announcement: false, announcement: false,
}; };

@ -4,4 +4,6 @@ export const isNavigator = typeof navigator !== 'undefined';
export const isDevelopment = process.env.NODE_ENV === 'development'; export const isDevelopment = process.env.NODE_ENV === 'development';
export const isProduction = process.env.NODE_ENV === 'production';
export const version = process.env.VERSION || '0.0.0'; export const version = process.env.VERSION || '0.0.0';

@ -12,10 +12,12 @@ import {
t, t,
fetchGlobalClientConfig, fetchGlobalClientConfig,
isDevelopment, isDevelopment,
isProduction,
setErrorHook, setErrorHook,
showToasts, showToasts,
parseUrlStr, parseUrlStr,
onLanguageLoaded, onLanguageLoaded,
version,
} from 'tailchat-shared'; } from 'tailchat-shared';
import { getPopupContainer } from './utils/dom-helper'; import { getPopupContainer } from './utils/dom-helper';
import { getUserJWT } from './utils/jwt-helper'; import { getUserJWT } from './utils/jwt-helper';
@ -121,7 +123,16 @@ setErrorHook((err) => {
/** /**
* *
*/ */
fetchGlobalClientConfig().catch((e) => { fetchGlobalClientConfig()
.then((config) => {
if (isProduction && !config.disableTelemetry) {
// 发送遥测信息
fetch(
`https://tianji.moonrailgun.com/telemetry/clnzoxcy10001vy2ohi4obbi0/blank.gif?name=tailchat&url=${window.location.origin}&v=${version}`
).catch(() => {});
}
})
.catch((e) => {
showErrorToasts(t('全局配置加载失败')); showErrorToasts(t('全局配置加载失败'));
console.error('全局配置加载失败', e); console.error('全局配置加载失败', e);
}); });

@ -55,6 +55,7 @@ export const config = {
disableCreateGroup: checkEnvTrusty(process.env.DISABLE_CREATE_GROUP), // 是否禁用用户创建群组功能 disableCreateGroup: checkEnvTrusty(process.env.DISABLE_CREATE_GROUP), // 是否禁用用户创建群组功能
disablePluginStore: checkEnvTrusty(process.env.DISABLE_PLUGIN_STORE), // 是否禁用用户插件中心功能 disablePluginStore: checkEnvTrusty(process.env.DISABLE_PLUGIN_STORE), // 是否禁用用户插件中心功能
disableAddFriend: checkEnvTrusty(process.env.DISABLE_ADD_FRIEND), // 是否禁用用户添加好友功能 disableAddFriend: checkEnvTrusty(process.env.DISABLE_ADD_FRIEND), // 是否禁用用户添加好友功能
disableTelemetry: checkEnvTrusty(process.env.DISABLE_TELEMETRY), // 是否禁用遥测
}, },
}; };

@ -84,6 +84,7 @@ class ConfigService extends TcService {
disableCreateGroup: config.feature.disableCreateGroup, disableCreateGroup: config.feature.disableCreateGroup,
disablePluginStore: config.feature.disablePluginStore, disablePluginStore: config.feature.disablePluginStore,
disableAddFriend: config.feature.disableAddFriend, disableAddFriend: config.feature.disableAddFriend,
disableTelemetry: config.feature.disableTelemetry,
...persistConfig, ...persistConfig,
}; };
} }

Loading…
Cancel
Save