Skip to content

Commit 185b717

Browse files
committed
feat(limit): optimize rule modification
1 parent 09534f3 commit 185b717

File tree

32 files changed

+310
-250
lines changed

32 files changed

+310
-250
lines changed

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@
3434
"@rsdoctor/rspack-plugin": "^1.3.9",
3535
"@rspack/cli": "^1.6.3",
3636
"@rspack/core": "^1.6.3",
37-
"@swc/core": "^1.15.1",
37+
"@swc/core": "^1.15.2",
3838
"@swc/jest": "^0.2.39",
39-
"@types/chrome": "0.1.28",
39+
"@types/chrome": "0.1.29",
4040
"@types/decompress": "^4.2.7",
4141
"@types/jest": "^30.0.0",
4242
"@types/node": "^24.10.1",
@@ -63,7 +63,7 @@
6363
"dependencies": {
6464
"@element-plus/icons-vue": "^2.3.2",
6565
"echarts": "^6.0.0",
66-
"element-plus": "2.11.7",
66+
"element-plus": "2.11.8",
6767
"punycode": "^2.3.1",
6868
"vue": "^3.5.24",
6969
"vue-router": "^4.6.3"

src/background/content-script-handler.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { createTab } from "@api/chrome/tab"
1010
import { ANALYSIS_ROUTE, LIMIT_ROUTE } from "@app/router/constants"
1111
import optionHolder from "@service/components/option-holder"
1212
import limitService from "@service/limit-service"
13-
import siteService from "@service/site-service"
13+
import { getSite } from "@service/site-service"
1414
import timelineThrottler from '@service/throttler/timeline-throttler'
1515
import whitelistHolder from "@service/whitelist/holder"
1616
import { getAppPageUrl } from "@util/constant/url"
@@ -71,7 +71,7 @@ export default function init(dispatcher: MessageDispatcher) {
7171
const { host } = extractHostname(url) || {}
7272
if (!host) return null
7373
const site: timer.site.SiteKey = { host, type: 'normal' }
74-
const exist = await siteService.get(site)
74+
const exist = await getSite(site)
7575
return exist?.run ? site : null
7676
})
7777
.register<void, boolean>('cs.getAudible', async (_, sender) => !!sender.tab?.audible)

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*/
77

88
import { getTab } from "@api/chrome/tab"
9-
import siteService from "@service/site-service"
9+
import { saveAlias, saveIconUrl } from "@service/site-service"
1010
import { IS_ANDROID, IS_CHROME, IS_SAFARI } from "@util/constant/environment"
1111
import { extractHostname, isBrowserUrl, isHomepage } from "@util/pattern"
1212
import { extractSiteName } from "@util/site"
@@ -19,7 +19,7 @@ async function collectAlias(key: timer.site.SiteKey, tabTitle: string) {
1919
if (!tabTitle) return
2020
if (isUrl(tabTitle)) return
2121
const siteName = extractSiteName(tabTitle, key.host)
22-
siteName && await siteService.saveAlias(key, siteName, true)
22+
siteName && await saveAlias(key, siteName, true)
2323
}
2424

2525
/**
@@ -35,7 +35,7 @@ async function processTabInfo(tab: ChromeTab): Promise<void> {
3535
// localhost hosts with Chrome use cache, so keep the favIcon url undefined
3636
IS_CHROME && /^localhost(:.+)?/.test(host) && (favIconUrl = undefined)
3737
const siteKey: timer.site.SiteKey = { host, type: 'normal' }
38-
favIconUrl && await siteService.saveIconUrl(siteKey, favIconUrl)
38+
favIconUrl && await saveIconUrl(siteKey, favIconUrl)
3939
!IS_ANDROID
4040
&& !isBrowserUrl(url)
4141
&& isHomepage(url)

src/background/migrator/cate-initializer.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import cateService from "@service/cate-service"
2-
import siteService from "@service/site-service"
2+
import { batchSaveSiteCate } from "@service/site-service"
33
import { Migrator } from "./common"
44

55
type InitialCate = {
@@ -34,7 +34,7 @@ async function initItem(item: InitialCate) {
3434
const cate = await cateService.add(name)
3535
const cateId = cate.id
3636
const siteKeys = hosts.map(host => ({ host, type: 'normal' } satisfies timer.site.SiteKey))
37-
await siteService.batchSaveCate(cateId, siteKeys)
37+
await batchSaveSiteCate(cateId, siteKeys)
3838
}
3939

4040
export default class CateInitializer implements Migrator {

src/background/migrator/local-file-initializer.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
import mergeRuleDatabase from "@db/merge-rule-database"
99
import { t2Chrome } from "@i18n/chrome/t"
10-
import siteService from "@service/site-service"
10+
import { saveAlias } from '@service/site-service'
1111
import { JSON_HOST, LOCAL_HOST_PATTERN, MERGED_HOST, PDF_HOST, PIC_HOST, TXT_HOST } from "@util/constant/remain-host"
1212
import { type Migrator } from "./common"
1313

@@ -27,19 +27,19 @@ export default class LocalFileInitializer implements Migrator {
2727
merged: MERGED_HOST,
2828
}).then(() => console.log('Local file merge rules initialized'))
2929
// Add site name
30-
siteService.saveAlias(
30+
saveAlias(
3131
{ host: PDF_HOST, type: 'normal' },
3232
t2Chrome(msg => msg.initial.localFile.pdf),
3333
)
34-
siteService.saveAlias(
34+
saveAlias(
3535
{ host: JSON_HOST, type: 'normal' },
3636
t2Chrome(msg => msg.initial.localFile.json),
3737
)
38-
siteService.saveAlias(
38+
saveAlias(
3939
{ host: PIC_HOST, type: 'normal' },
4040
t2Chrome(msg => msg.initial.localFile.pic),
4141
)
42-
siteService.saveAlias(
42+
saveAlias(
4343
{ host: TXT_HOST, type: 'normal' },
4444
t2Chrome(msg => msg.initial.localFile.txt),
4545
)

src/database/option-database.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class OptionDatabase extends BaseDatabase {
4444
_areaName: chrome.storage.AreaName,
4545
) => {
4646
const optionInfo = changes[DB_KEY]
47-
optionInfo && listener(optionInfo.newValue || {} as timer.option.AllOption)
47+
optionInfo && listener(optionInfo.newValue as timer.option.AllOption ?? {})
4848
}
4949
chrome.storage.onChanged.addListener(storageListener)
5050
}

src/database/whitelist-database.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,9 @@ class WhitelistDatabase extends BaseDatabase {
4747
_areaName: chrome.storage.AreaName,
4848
) => {
4949
const changeInfo = changes[WHITELIST_KEY]
50-
changeInfo && listener(changeInfo.newValue || [])
50+
const newValue = changeInfo?.newValue
51+
const whitelists: string[] = Array.isArray(newValue) ? newValue.map(n => new String(n).toString()) : []
52+
changeInfo && listener(whitelists)
5153
}
5254
chrome.storage.onChanged.addListener(storageListener)
5355
}

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

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
"deleteConfirm": "是否要删除规则 [{name}]?",
3636
"lockConfirm": "锁定后,即使未触发此规则,所有操作也需要验证",
3737
"inputTestUrl": "请先输入需要测试的网址链接",
38-
"clickTestButton": "输入完成后请点击【{buttonText}】按钮",
3938
"noRuleMatched": "该网址未命中任何规则",
4039
"rulesMatched": "该网址命中以下规则:",
4140
"timeout": "倒计时已结束 XD"
@@ -88,7 +87,6 @@
8887
"deleteConfirm": "確定要刪除規則「{name}」嗎?",
8988
"lockConfirm": "如果鎖定,所有操作都需要驗證,即使規則未觸發也一樣。",
9089
"inputTestUrl": "請輸入要測試的網址",
91-
"clickTestButton": "輸入完成後請點擊【{buttonText}】按鈕",
9290
"noRuleMatched": "此網址未符合任何規則",
9391
"rulesMatched": "此網址符合以下規則:",
9492
"timeout": "時間到啦!XDDD"
@@ -108,6 +106,7 @@
108106
"en": {
109107
"filterDisabled": "Only enabled",
110108
"wildcardTip": "You can use wildcards to match subdomains or subpages, and use \"+\" as a prefix to exclude subpages!",
109+
"emptyTips": "Click here to create one rule!",
111110
"item": {
112111
"name": "Rule name",
113112
"condition": "Restricted URL",
@@ -141,7 +140,6 @@
141140
"deleteConfirm": "Do you want to delete the rule [{name}]?",
142141
"lockConfirm": "If locked, all operations will require verification even if the rule is not triggered.",
143142
"inputTestUrl": "Please enter the URL link to be tested first",
144-
"clickTestButton": "After inputting, please click the button ({buttonText})",
145143
"noRuleMatched": "The URL does not hit any rules",
146144
"rulesMatched": "The URL hits the following rules:",
147145
"timeout": "Time is up! XD"
@@ -192,7 +190,6 @@
192190
"noRule": "ルールが記入されていません",
193191
"deleteConfirm": "ルール [{name}] を削除しますか?",
194192
"inputTestUrl": "最初にテストする URL リンクを入力してください",
195-
"clickTestButton": "入力後、ボタン({buttonText})をクリックしてください",
196193
"noRuleMatched": "URL がどのルールとも一致しません",
197194
"rulesMatched": "URL は次のルールに一致します。"
198195
},
@@ -244,7 +241,6 @@
244241
"deleteConfirm": "Eliminar a regra [{name}]?",
245242
"lockConfirm": "Se bloqueado, exigirá verificação mesmo sem ser acionado",
246243
"inputTestUrl": "Introduza primeiro o URL a testar",
247-
"clickTestButton": "Clique no botão ({buttonText}) após introduzir",
248244
"noRuleMatched": "O URL não corresponde a nenhuma regra",
249245
"rulesMatched": "O URL corresponde às seguintes regras:",
250246
"timeout": "Tempo esgotado! XD"
@@ -297,7 +293,6 @@
297293
"deleteConfirm": "Ви дійсно хочете видалити правило {cond}?",
298294
"lockConfirm": "Якщо заблоковано, всі операції потребують перевірки, навіть якщо правило не спрацьовує.",
299295
"inputTestUrl": "Спочатку введіть URL-адресу посилання для перевірки",
300-
"clickTestButton": "Після введення натисніть кнопку ({buttonText})",
301296
"noRuleMatched": "URL не відповідає жодному правилу",
302297
"rulesMatched": "URL-адреса отримує такі правила:",
303298
"timeout": "Час вийшов! XD"
@@ -348,7 +343,6 @@
348343
"deleteConfirm": "¿Deseas eliminar la regla de {cond}?",
349344
"lockConfirm": "Si está bloqueado, todas las operaciones requerirán verificación incluso si no se activa la regla.",
350345
"inputTestUrl": "Por favor, introduce primero el enlace URL a ser probado",
351-
"clickTestButton": "Después de ingresarla, haz clic en el botón ({buttonText})",
352346
"noRuleMatched": "La URL no sigue ninguna regla",
353347
"rulesMatched": "La URL sigue las siguientes reglas:",
354348
"timeout": "¡Tiempo se acabó! XD"
@@ -401,7 +395,6 @@
401395
"deleteConfirm": "Möchten Sie die Regel [{name}] löschen?",
402396
"lockConfirm": "Wenn gesperrt, müssen alle Operationen geprüft werden, auch wenn die Regel nicht ausgelöst wird.",
403397
"inputTestUrl": "Bitte geben Sie zunächst den zu testenden URL-Link ein",
404-
"clickTestButton": "Klicken Sie nach der Eingabe bitte auf die Schaltfläche ({buttonText}).",
405398
"noRuleMatched": "Die URL entspricht keinen Regeln",
406399
"rulesMatched": "Die URL erfüllt die folgenden Regeln:",
407400
"timeout": "Zeit ist abgelaufen! XD"
@@ -454,7 +447,6 @@
454447
"deleteConfirm": "Voulez-vous supprimer la règle [{name}]?",
455448
"lockConfirm": "Si verrouillé, toutes les opérations nécessiteront une vérification, même si la règle n'est pas activée.",
456449
"inputTestUrl": "Veuillez entrer le lien URL à tester en premier",
457-
"clickTestButton": "Après l'entrée, cliquez sur le bouton ({buttonText})",
458450
"noRuleMatched": "L'URL ne correspond à aucune règle",
459451
"rulesMatched": "L'URL atteint les règles suivantes :",
460452
"timeout": "Temps écoulé ! XD"
@@ -500,7 +492,6 @@
500492
"noRule": "Нет заполненных правил",
501493
"deleteConfirm": "Вы хотите удалить правило [{name}]?",
502494
"inputTestUrl": "Пожалуйста, введите ссылку для тестирования",
503-
"clickTestButton": "После ввода информации, пожалуйста, нажмите кнопку ({buttonText})",
504495
"noRuleMatched": "URL не содержит правил",
505496
"rulesMatched": "URL попадает в следующие правила:"
506497
},
@@ -551,7 +542,6 @@
551542
"deleteConfirm": "هل تريد حذف القاعدة [{name}]؟",
552543
"lockConfirm": "إذا تم القَفل، فإن جميع العمليات ستتطلب التحقق حتى وإن لم يتم تفعيل القاعدة.",
553544
"inputTestUrl": "الرجاء إدخال رابط URL ليتم اختباره أولاً",
554-
"clickTestButton": "بعد الإدخال، الرجاء الضغط على الزر ({buttonText})",
555545
"noRuleMatched": "عنوان URL لا يصطدم بأي قواعد",
556546
"rulesMatched": "يتوافق عنوان URL مع القواعد التالية:",
557547
"timeout": "انتهى الوقت! XD"
@@ -604,7 +594,6 @@
604594
"deleteConfirm": "{name} kuralını silmek istiyor musunuz?",
605595
"lockConfirm": "Kilitliyse, kural tetiklenmemiş olsa bile tüm işlemler doğrulama gerektirecektir.",
606596
"inputTestUrl": "Lütfen önce test edilecek URL bağlantısını girin",
607-
"clickTestButton": "Giriş yaptıktan sonra, lütfen düğmeye tıklayın ({buttonText})",
608597
"noRuleMatched": "URL hiçbir kurala uymuyor",
609598
"rulesMatched": "URL aşağıdaki kurallara uygundur:",
610599
"timeout": "Zaman doldu!"
@@ -657,7 +646,6 @@
657646
"deleteConfirm": "Na pewno chcesz usunąć regułę [{name}]?",
658647
"lockConfirm": "Jeśli zablokowane, wszystkie operacje będą wymagały weryfikacji, nawet jeśli reguła nie zostanie uruchomiona.",
659648
"inputTestUrl": "Wpisz URL do przetestowania",
660-
"clickTestButton": "Po wpisaniu kliknij przycisk ({buttonText})",
661649
"noRuleMatched": "Podany URL nie aktywuje żadnej reguły",
662650
"rulesMatched": "Podany URL aktywuje następujące reguły:",
663651
"timeout": "Czas minął! XD"

src/i18n/message/app/limit.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import resource from './limit-resource.json'
1010
export type LimitMessage = {
1111
filterDisabled: string
1212
wildcardTip: string
13+
emptyTips: string
1314
step: {
1415
base: string
1516
url: string
@@ -43,7 +44,6 @@ export type LimitMessage = {
4344
deleteConfirm: string
4445
lockConfirm: string
4546
inputTestUrl: string
46-
clickTestButton: string
4747
noRuleMatched: string
4848
rulesMatched: string
4949
timeout: string

src/pages/app/components/Analysis/components/AnalysisFilter/TargetSelect.tsx

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { useCategory } from "@app/context"
22
import { t } from "@app/locale"
3-
import { useDebounce, useRequest, useState } from "@hooks"
3+
import { useDebounceState, useRequest } from "@hooks"
44
import Flex from "@pages/components/Flex"
5-
import siteService from "@service/site-service"
5+
import { selectAllSites } from "@service/site-service"
66
import { listHosts } from "@service/stat-service"
77
import { identifySiteKey, parseSiteKeyFromIdentity, SiteMap } from "@util/site"
88
import { ElSelectV2, ElTag, useNamespace } from "element-plus"
@@ -67,7 +67,7 @@ const fetchItems = async (categories: timer.site.Cate[]): Promise<[siteItems: Ta
6767
collectHosts(hosts, siteSet)
6868

6969
// 2.2 query sites from sites
70-
const sites = await siteService.selectAll()
70+
const sites = await selectAllSites()
7171
sites?.forEach(site => siteSet.put(site, site))
7272

7373
const siteItems = siteSet?.map((_, site) => site)
@@ -115,11 +115,9 @@ const TargetSelect = defineComponent(() => {
115115
{ defaultValue: [[], []], deps: [() => cate.all] },
116116
)
117117

118-
const [query, setQuery] = useState('')
119-
const debouncedQuery = useDebounce(query, 50)
120-
118+
const [query, setQuery] = useDebounceState('', 50)
121119
const options = computed(() => {
122-
const q = debouncedQuery.value?.trim?.()
120+
const q = query.value?.trim?.()
123121
let [cateItems, siteItems] = allItems.value
124122
if (q) {
125123
siteItems = siteItems.filter(item => {

0 commit comments

Comments
 (0)