Skip to content

Commit

Permalink
feat: support disable collecting statistics
Browse files Browse the repository at this point in the history
  • Loading branch information
yetone committed May 2, 2023
1 parent cd394a2 commit 31dfa42
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 7 deletions.
22 changes: 22 additions & 0 deletions src/common/components/Settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,25 @@ function AutoTranslateCheckbox(props: AutoTranslateCheckboxProps) {
)
}

interface MyCheckboxProps {
value?: boolean
onChange?: (value: boolean) => void
onBlur?: () => void
}

function MyCheckbox(props: MyCheckboxProps) {
return (
<Checkbox
checkmarkType='toggle_round'
checked={props.value}
onChange={(e) => {
props.onChange?.(e.target.checked)
props.onBlur?.()
}}
/>
)
}

interface RestorePreviousPositionCheckboxProps {
value?: boolean
onChange?: (value: boolean) => void
Expand Down Expand Up @@ -1024,6 +1043,9 @@ export function Settings(props: IPopupProps) {
<FormItem name='ocrHotkey' label={t('OCR Hotkey')}>
<HotkeyRecorder onBlur={onBlur} />
</FormItem>
<FormItem name='disableCollectingStatistics' label={t('disable collecting statistics')}>
<MyCheckbox onBlur={onBlur} />
</FormItem>
<div
style={{
display: 'flex',
Expand Down
8 changes: 6 additions & 2 deletions src/common/components/Translator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { clsx } from 'clsx'
import { Button } from 'baseui-sd/button'
import { ErrorBoundary } from 'react-error-boundary'
import { ErrorFallback } from '../components/ErrorFallback'
import { defaultAPIURL, exportToCsv, isDesktopApp, isTauri } from '../utils'
import { defaultAPIURL, exportToCsv, getSettings, isDesktopApp, isTauri } from '../utils'
import { Settings } from './Settings'
import { documentPadding } from '../../browser-extension/content_script/consts'
import Dropzone from 'react-dropzone'
Expand Down Expand Up @@ -50,11 +50,15 @@ import ReactGA from 'react-ga4'

let isAnalysisSetupped = false

function setupAnalysis() {
async function setupAnalysis() {
if (isAnalysisSetupped) {
return
}
isAnalysisSetupped = true
const settings = await getSettings()
if (settings.disableCollectingStatistics) {
return
}
if (isDesktopApp()) {
Sentry.init({
dsn: 'https://477519542bd6491cb347ca3f55fcdce6@o441417.ingest.sentry.io/4505051776090112',
Expand Down
3 changes: 2 additions & 1 deletion src/common/i18n/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,6 @@
"last review": "Last Review Time",
"vocabulary": "Vocabulary",
"generate article": "Generate Article",
"insert to editor": "Insert to Editor"
"insert to editor": "Insert to Editor",
"disable collecting statistics": "Disable collecting statistics"
}
3 changes: 2 additions & 1 deletion src/common/i18n/locales/ja/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,6 @@
"last review": "最近のクエリ時間",
"vocabulary": "語彙",
"generate article": "記事を生成",
"insert to editor": "エディタに挿入"
"insert to editor": "エディタに挿入",
"disable collecting statistics": "統計情報の収集を無効にする"
}
3 changes: 2 additions & 1 deletion src/common/i18n/locales/th/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,6 @@
"last review": "เวลาสอบถามล่าสุด",
"vocabulary": "คำศัพท์",
"generate article": "สร้างบทความ",
"insert to editor": "แทรกลงในตัวแก้ไข"
"insert to editor": "แทรกลงในตัวแก้ไข",
"disable collecting statistics": "ปิดใช้งานการสถิติการเก็บรวบรวม"
}
3 changes: 2 additions & 1 deletion src/common/i18n/locales/zh-Hans/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,6 @@
"last review": "最近查询时间",
"vocabulary": "词汇表",
"generate article": "生成文章",
"insert to editor": "插入编辑器"
"insert to editor": "插入编辑器",
"disable collecting statistics": "禁用统计"
}
3 changes: 2 additions & 1 deletion src/common/i18n/locales/zh-Hant/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,6 @@
"last review": "最近査詢時間",
"vocabulary": "單詞",
"generate article": "創作文章",
"insert to editor": "插入編輯器"
"insert to editor": "插入編輯器",
"disable collecting statistics": "停用統計"
}
1 change: 1 addition & 0 deletions src/common/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,5 @@ export interface ISettings {
restorePreviousPosition?: boolean
selectInputElementsText?: boolean
runAtStartup?: boolean
disableCollectingStatistics?: boolean
}
4 changes: 4 additions & 0 deletions src/common/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ const settingKeys: Record<keyof ISettings, number> = {
restorePreviousPosition: 1,
runAtStartup: 1,
selectInputElementsText: 1,
disableCollectingStatistics: 1,
}

export async function getSettings(): Promise<ISettings> {
Expand Down Expand Up @@ -81,6 +82,9 @@ export async function getSettings(): Promise<ISettings> {
if (!settings.i18n) {
settings.i18n = defaulti18n
}
if (!settings.disableCollectingStatistics) {
settings.disableCollectingStatistics = false
}
if (settings.selectInputElementsText === undefined || settings.selectInputElementsText === null) {
settings.selectInputElementsText = defaultSelectInputElementsText
}
Expand Down

0 comments on commit 31dfa42

Please sign in to comment.