Skip to content

Commit 0a55f8a

Browse files
authored
refactor: option codes (#576)
1 parent 23bcc91 commit 0a55f8a

File tree

19 files changed

+190
-213
lines changed

19 files changed

+190
-213
lines changed

package.json

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
"@babel/plugin-transform-modules-commonjs": "^7.27.1",
3333
"@babel/preset-env": "^7.28.3",
3434
"@crowdin/crowdin-api-client": "^1.48.3",
35-
"@rsdoctor/rspack-plugin": "^1.3.2",
35+
"@rsdoctor/rspack-plugin": "^1.3.3",
3636
"@rspack/cli": "^1.5.8",
3737
"@rspack/core": "^1.5.8",
3838
"@swc/core": "^1.13.5",
@@ -51,21 +51,20 @@
5151
"jest": "^30.2.0",
5252
"jest-environment-jsdom": "^30.2.0",
5353
"jest-junit": "^16.0.0",
54+
"jszip": "^3.10.1",
5455
"postcss": "^8.5.6",
5556
"postcss-loader": "^8.2.0",
5657
"postcss-rtlcss": "^5.7.1",
57-
"puppeteer": "^24.24.0",
58+
"puppeteer": "^24.25.0",
5859
"sass": "^1.93.2",
5960
"sass-loader": "^16.0.5",
60-
"style-loader": "^4.0.0",
6161
"ts-loader": "^9.5.4",
6262
"ts-node": "^10.9.2",
6363
"tsconfig-paths": "^4.2.0",
64-
"typescript": "5.9.3",
65-
"url-loader": "^4.1.1"
64+
"typescript": "5.9.3"
6665
},
6766
"optionalDependencies": {
68-
"web-ext": "^8.10.0"
67+
"web-ext": "^9.0.0"
6968
},
7069
"dependencies": {
7170
"@element-plus/icons-vue": "^2.3.2",
@@ -75,7 +74,7 @@
7574
"js-base64": "^3.7.8",
7675
"punycode": "^2.3.1",
7776
"vue": "^3.5.22",
78-
"vue-router": "^4.5.1"
77+
"vue-router": "^4.6.2"
7978
},
8079
"engines": {
8180
"node": ">=20"

rspack/rspack.common.ts

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -93,21 +93,16 @@ const staticOptions: Configuration = {
9393
test: /\.css$/,
9494
use: [CssExtractRspackPlugin.loader, 'css-loader', POSTCSS_LOADER_CONF],
9595
}, {
96-
test: /\.sc|ass$/,
96+
test: /\.s[ac]ss$/,
9797
use: [CssExtractRspackPlugin.loader, 'css-loader', POSTCSS_LOADER_CONF, 'sass-loader']
9898
}, {
9999
test: /\.(jpg|jpeg|png|woff|woff2|eot|ttf|svg)$/,
100-
exclude: /node_modules/,
101-
use: ['url-loader']
102-
}, {
103-
test: /\.m?js$/,
104-
exclude: /(node_modules)/,
105-
use: ['babel-loader']
100+
type: 'asset/resource'
106101
}
107102
]
108103
},
109104
resolve: {
110-
extensions: ['.ts', '.tsx', ".js", '.css', '.scss', '.sass'],
105+
extensions: ['.ts', '.tsx', '.js', '.css', '.scss', '.sass'],
111106
tsConfig: join(__dirname, '..', 'tsconfig.json'),
112107
},
113108
optimization: {

src/background/icon-and-alias-collector.ts

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,11 @@
66
*/
77

88
import { getTab } from "@api/chrome/tab"
9-
import optionDatabase from "@db/option-database"
109
import siteService from "@service/site-service"
1110
import { IS_ANDROID, IS_CHROME, IS_SAFARI } from "@util/constant/environment"
12-
import { defaultStatistics } from "@util/constant/option"
1311
import { extractHostname, isBrowserUrl, isHomepage } from "@util/pattern"
1412
import { extractSiteName } from "@util/site"
1513

16-
const storage: chrome.storage.StorageArea = chrome.storage.local
17-
18-
let collectAliasEnabled = defaultStatistics().collectSiteName
19-
const setCollectAliasEnabled = (opt: timer.option.AllOption) => collectAliasEnabled = opt.collectSiteName
20-
optionDatabase.getOption().then(setCollectAliasEnabled)
21-
optionDatabase.addOptionChangeListener(setCollectAliasEnabled)
22-
2314
function isUrl(title: string) {
2415
return title.startsWith('https://') || title.startsWith('http://') || title.startsWith('ftp://')
2516
}
@@ -45,8 +36,7 @@ async function processTabInfo(tab: ChromeTab): Promise<void> {
4536
IS_CHROME && /^localhost(:.+)?/.test(host) && (favIconUrl = undefined)
4637
const siteKey: timer.site.SiteKey = { host, type: 'normal' }
4738
favIconUrl && await siteService.saveIconUrl(siteKey, favIconUrl)
48-
collectAliasEnabled
49-
&& !isBrowserUrl(url)
39+
!isBrowserUrl(url)
5040
&& isHomepage(url)
5141
&& await collectAlias(siteKey, title)
5242
}

src/i18n/message/app/option-resource.json

Lines changed: 22 additions & 62 deletions
Large diffs are not rendered by default.

src/i18n/message/app/option.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import resource from './option-resource.json'
99
export type OptionMessage = {
1010
yes: string
1111
no: string
12+
followBrowser: string
1213
popup: {
1314
title: string
1415
max: string
@@ -27,7 +28,6 @@ export type OptionMessage = {
2728
badgeTextContent: string
2829
locale: {
2930
label: string
30-
default: string
3131
changeConfirm: string
3232
reloadButton: string
3333
}
@@ -38,7 +38,7 @@ export type OptionMessage = {
3838
},
3939
darkMode: {
4040
label: string
41-
options: Record<timer.option.DarkMode, string>
41+
options: Omit<Record<timer.option.DarkMode, string>, 'default'>
4242
}
4343
animationDuration: string
4444
}
@@ -52,9 +52,6 @@ export type OptionMessage = {
5252
countTabGroup: string
5353
tabGroupInfo: string
5454
tabGroupsPermGrant: string
55-
collectSiteName: string
56-
siteNameUsage: string
57-
siteName: string
5855
fileAccessDisabled: string
5956
fileAccessFirefox: string
6057
weekStart: string
Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { t } from "@app/locale"
21
import { defaultAccessibility } from "@util/constant/option"
32
import { ElSwitch } from "element-plus"
43
import { defineComponent } from "vue"
@@ -15,19 +14,11 @@ const _default = defineComponent((_, ctx) => {
1514
ctx.expose({
1615
reset: () => copy(option, defaultAccessibility())
1716
} satisfies OptionInstance)
18-
return () => <>
19-
<OptionItem
20-
label={msg => msg.option.accessibility.chartDecal}
21-
defaultValue={t(msg => msg.option.no)}
22-
hideDivider
23-
v-slots={{
24-
default: () => <ElSwitch
25-
modelValue={option.chartDecal}
26-
onChange={val => option.chartDecal = val as boolean}
27-
/>
28-
}}
29-
/>
30-
</>
17+
return () => (
18+
<OptionItem label={msg => msg.option.accessibility.chartDecal} defaultValue={false}>
19+
<ElSwitch modelValue={option.chartDecal} onChange={val => option.chartDecal = val as boolean} />
20+
</OptionItem>
21+
)
3122
})
3223

3324
export default _default

src/pages/app/components/Option/components/AppearanceOption/DarkModeInput.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,10 @@ const _default = defineComponent<Props>(props => {
4848
onChange={val => props.onChange?.(val as timer.option.DarkMode, [props.startSecond, props.endSecond])}
4949
>
5050
{
51-
ALL_MODES.map(value => <ElOption value={value} label={t(msg => msg.option.appearance.darkMode.options[value])} />)
51+
ALL_MODES.map(value => <ElOption
52+
value={value}
53+
label={t(msg => value === 'default' ? msg.option.followBrowser : msg.option.appearance.darkMode.options[value])}
54+
/>)
5255
}
5356
</ElSelect>
5457
{props.modelValue === "timed" && <>

src/pages/app/components/Option/components/AppearanceOption/index.tsx

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,19 @@
55
* https://opensource.org/licenses/MIT
66
*/
77

8-
import { t, tWith } from "@app/locale"
8+
import { type I18nKey, t, tWith } from "@app/locale"
99
import { ALL_LOCALES, localeSameAsBrowser } from "@i18n"
1010
import localeMessages from "@i18n/message/common/locale"
1111
import optionService from "@service/option-service"
1212
import { IS_ANDROID } from "@util/constant/environment"
1313
import { defaultAppearance } from "@util/constant/option"
1414
import { toggle } from "@util/dark-mode"
15-
import { ElColorPicker, ElMessageBox, ElOption, ElSelect, ElSlider, ElSwitch, ElTag } from "element-plus"
15+
import { ElColorPicker, ElMessageBox, ElOption, ElSelect, ElSlider, ElSwitch, ElTag, type TagProps } from "element-plus"
1616
import { computed, defineComponent, type StyleValue } from "vue"
1717
import { type OptionInstance } from "../../common"
1818
import { useOption } from "../../useOption"
1919
import OptionItem from "../OptionItem"
20+
import OptionLines from '../OptionLines'
2021
import OptionTag from "../OptionTag"
2122
import DarkModeInput from "./DarkModeInput"
2223

@@ -38,6 +39,7 @@ function copy(target: timer.option.AppearanceOption, source: timer.option.Appear
3839
}
3940

4041
const DEFAULT_ANIMA_DURATION = defaultAppearance().chartAnimationDuration
42+
const FOLLOW_BROWSER: I18nKey = msg => msg.option.followBrowser
4143

4244
const _default = defineComponent((_props, ctx) => {
4345
const { option } = useOption<timer.option.AppearanceOption>({
@@ -64,20 +66,16 @@ const _default = defineComponent((_props, ctx) => {
6466
closeOnClickModal: false
6567
}).then(() => { location.reload?.() }).catch(() => {/* do nothing */ })
6668
}
67-
const animaDurationTagType = computed<'info' | 'primary' | 'warning'>(() => {
69+
const animaDurationTagType = computed<TagProps['type']>(() => {
6870
const val = option.chartAnimationDuration
6971
if (!val) return 'info'
7072
if (val > DEFAULT_ANIMA_DURATION) return 'warning'
7173
return 'primary'
7274
})
7375

7476
return () => (
75-
<div>
76-
<OptionItem
77-
label={msg => msg.option.appearance.darkMode.label}
78-
defaultValue={t(msg => msg.option.appearance.darkMode.options.default)}
79-
hideDivider
80-
>
77+
<OptionLines>
78+
<OptionItem label={msg => msg.option.appearance.darkMode.label} defaultValue={FOLLOW_BROWSER}>
8179
<DarkModeInput
8280
modelValue={option.darkMode}
8381
startSecond={option.darkModeTimeStart}
@@ -89,10 +87,7 @@ const _default = defineComponent((_props, ctx) => {
8987
}}
9088
/>
9189
</OptionItem>
92-
<OptionItem
93-
label={msg => msg.option.appearance.locale.label}
94-
defaultValue={t(msg => msg.option.appearance.locale.default)}
95-
>
90+
<OptionItem label={msg => msg.option.appearance.locale.label} defaultValue={FOLLOW_BROWSER}>
9691
<ElSelect
9792
modelValue={option.locale}
9893
size="small"
@@ -102,7 +97,7 @@ const _default = defineComponent((_props, ctx) => {
10297
>
10398
{allLocaleOptions.map(locale => <ElOption
10499
value={locale}
105-
label={locale === "default" ? t(msg => msg.option.appearance.locale.default) : localeMessages[locale].name}
100+
label={locale === "default" ? t(FOLLOW_BROWSER) : localeMessages[locale].name}
106101
/>)}
107102
</ElSelect>
108103
</OptionItem>
@@ -179,7 +174,7 @@ const _default = defineComponent((_props, ctx) => {
179174
{option.chartAnimationDuration}ms
180175
</ElTag>
181176
</OptionItem>
182-
</div>
177+
</OptionLines>
183178
)
184179
})
185180

src/pages/app/components/Option/components/BackupOption/index.tsx

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { ElInput, ElOption, ElSelect } from "element-plus"
1313
import { computed, defineComponent } from "vue"
1414
import { type OptionInstance } from "../../common"
1515
import OptionItem from "../OptionItem"
16+
import OptionLines from '../OptionLines'
1617
import OptionTooltip from "../OptionTooltip"
1718
import AutoInput from "./AutoInput"
1819
import Footer from "./Footer"
@@ -45,8 +46,8 @@ const _default = defineComponent((_, ctx) => {
4546

4647
ctx.expose({ reset } satisfies OptionInstance)
4748

48-
return () => <>
49-
<OptionItem label={msg => msg.option.backup.type} defaultValue={TYPE_NAMES['none']} hideDivider>
49+
return () => <OptionLines>
50+
<OptionItem label={msg => msg.option.backup.type} defaultValue={TYPE_NAMES['none']}>
5051
<ElSelect
5152
modelValue={backupType.value}
5253
size="small"
@@ -101,7 +102,7 @@ const _default = defineComponent((_, ctx) => {
101102
onInput={val => setExtField('endpoint', val)}
102103
/>
103104
</OptionItem>
104-
<OptionItem label={_ => "Vault Name {input}"}>
105+
<OptionItem key="obsidian-vault" label={_ => "Vault Name {input}"}>
105106
<ElInput
106107
placeholder={DEFAULT_OBSIDIAN_BUCKET}
107108
modelValue={ext.value?.bucket}
@@ -110,15 +111,15 @@ const _default = defineComponent((_, ctx) => {
110111
onInput={val => setExtField('bucket', val)}
111112
/>
112113
</OptionItem>
113-
<OptionItem label={msg => msg.option.backup.label.path} required>
114+
<OptionItem key="obsidian-path" label={msg => msg.option.backup.label.path} required>
114115
<ElInput
115116
modelValue={ext.value?.dirPath}
116117
size="small"
117118
style={{ width: "400px" }}
118119
onInput={val => setExtField('dirPath', val)}
119120
/>
120121
</OptionItem>
121-
<OptionItem required label={_ => "Authorization {input}"}>
122+
<OptionItem key="obsidian-auth" label={_ => "Authorization {input}"} required>
122123
<ElInput
123124
modelValue={auth.value}
124125
size="small"
@@ -144,7 +145,7 @@ const _default = defineComponent((_, ctx) => {
144145
onInput={val => setExtField('endpoint', val)}
145146
/>
146147
</OptionItem>
147-
<OptionItem label={msg => msg.option.backup.label.path} required>
148+
<OptionItem key='web-dav-path' label={msg => msg.option.backup.label.path} required>
148149
<ElInput
149150
modelValue={ext.value?.dirPath}
150151
placeholder="/for/example"
@@ -153,15 +154,15 @@ const _default = defineComponent((_, ctx) => {
153154
onInput={val => setExtField('dirPath', val)}
154155
/>
155156
</OptionItem>
156-
<OptionItem label={msg => msg.option.backup.label.account} required>
157+
<OptionItem key='web-dav-acc' label={msg => msg.option.backup.label.account} required>
157158
<ElInput
158159
modelValue={account.value}
159160
size="small"
160161
style={{ width: "200px" }}
161162
onInput={val => account.value = val?.trim?.()}
162163
/>
163164
</OptionItem>
164-
<OptionItem label={msg => msg.option.backup.label.password} required>
165+
<OptionItem key='web-dav-psw' label={msg => msg.option.backup.label.password} required>
165166
<ElInput
166167
modelValue={password.value}
167168
size="small"
@@ -180,7 +181,7 @@ const _default = defineComponent((_, ctx) => {
180181
/>
181182
</OptionItem>
182183
{isNotNone.value && <Footer type={backupType.value} />}
183-
</>
184+
</OptionLines>
184185
})
185186

186187
export default _default

src/pages/app/components/Option/components/LimitOption/index.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { defineComponent, type StyleValue } from "vue"
1313
import { type OptionInstance } from "../../common"
1414
import { useOption } from "../../useOption"
1515
import OptionItem from "../OptionItem"
16+
import OptionLines from '../OptionLines'
1617
import "./limit-option.sass"
1718
import { usePswEdit } from "./usePswEdit"
1819
import { useVerify } from "./useVerify"
@@ -93,9 +94,8 @@ const _default = defineComponent((_, ctx) => {
9394
}
9495
}
9596

96-
return () => <>
97+
return () => <OptionLines>
9798
<OptionItem
98-
hideDivider
9999
label={msg => msg.option.dailyLimit.reminder}
100100
defaultValue={t(msg => msg.option.no)}
101101
v-slots={{
@@ -176,7 +176,7 @@ const _default = defineComponent((_, ctx) => {
176176
style={{ width: "280px" }}
177177
/>
178178
</OptionItem>
179-
</>
179+
</OptionLines>
180180
})
181181

182182
export default _default

0 commit comments

Comments
 (0)