Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
"commitlint": "^20.4.2",
"css-loader": "^7.1.4",
"decompress": "^4.2.1",
"fake-indexeddb": "^6.2.5",
"husky": "^9.1.7",
"jest": "^30.2.0",
"jest-environment-jsdom": "^30.2.0",
Expand All @@ -65,10 +66,11 @@
"echarts": "^6.0.0",
"element-plus": "2.13.2",
"punycode": "^2.3.1",
"typescript-guard": "^0.2.1",
"vue": "^3.5.28",
"vue-router": "^5.0.3"
},
"engines": {
"node": ">=22"
}
}
}
1 change: 0 additions & 1 deletion rspack/rspack.common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ const generateJsonPlugins: RspackPluginInstance[] = []

const localeJsonFiles = Object.entries(i18nChrome)
.map(([locale, message]) => new GenerateJsonPlugin(`_locales/${locale}/messages.json`, message))
.map(plugin => plugin as unknown as RspackPluginInstance)
generateJsonPlugins.push(...localeJsonFiles)

type EntryConfig = {
Expand Down
2 changes: 1 addition & 1 deletion src/background/data-cleaner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const cleanPeriodData = async () => {
export default function initDataCleaner() {
alarmManager.setWhen(
PERIOD_ALARM_NAME,
() => getStartOfDay(new Date()).getTime() + MILL_PER_DAY,
() => getStartOfDay(new Date()) + MILL_PER_DAY,
cleanPeriodData,
)
}
5 changes: 1 addition & 4 deletions src/background/limit-processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,7 @@ function initDailyBroadcast() {
// Broadcast rules at the start of each day
alarmManager.setWhen(
'limit-daily-broadcast',
() => {
const startOfThisDay = getStartOfDay(new Date())
return startOfThisDay.getTime() + MILL_PER_DAY
},
() => getStartOfDay(new Date()) + MILL_PER_DAY,
() => limitService.broadcastRules(),
)
}
Expand Down
2 changes: 1 addition & 1 deletion src/background/message-dispatcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class MessageDispatcher {
const result = await handler(message.data, sender)
return { code: 'success', data: result }
} catch (error) {
const msg = (error as Error)?.message ?? error?.toString?.()
const msg = error instanceof Error ? error.message : error?.toString?.()
return { code: 'fail', msg }
}
}
Expand Down
5 changes: 2 additions & 3 deletions src/background/migrator/cate-initializer.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import cateService from "@service/cate-service"
import { batchSaveSiteCate } from "@service/site-service"
import { Migrator } from "./common"
import type { Migrator } from "./types"

type InitialCate = {
name: string
Expand Down Expand Up @@ -44,7 +44,6 @@ export default class CateInitializer implements Migrator {
}
}

onUpdate(version: string): void {
version === '3.0.1' && this.onInstall()
onUpdate(_version: string): void {
}
}
2 changes: 1 addition & 1 deletion src/background/migrator/host-merge-initializer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

import mergeRuleDatabase from "@db/merge-rule-database"
import { type Migrator } from "./common"
import type { Migrator } from "./types"

/**
* v0.1.2
Expand Down
6 changes: 3 additions & 3 deletions src/background/migrator/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@

import { getVersion, onInstalled } from "@api/chrome/runtime"
import CateInitializer from "./cate-initializer"
import { type Migrator } from "./common"
import HostMergeInitializer from "./host-merge-initializer"
import LimitRuleMigrator from "./limit-rule-migrator"
import IndexedDBMigrator from './indexed-migrator'
import LocalFileInitializer from "./local-file-initializer"
import type { Migrator } from "./types"
import WhitelistInitializer from "./whitelist-initializer"

/**
Expand All @@ -27,7 +27,7 @@ class VersionManager {
new LocalFileInitializer(),
new WhitelistInitializer(),
new CateInitializer(),
new LimitRuleMigrator(),
new IndexedDBMigrator(),
)
}

Expand Down
20 changes: 20 additions & 0 deletions src/background/migrator/indexed-migrator.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import timelineDatabase from '@db/timeline-database'
import type { Migrator } from './types'

// IndexedDB support was introduced in v4.0.0
const INDEXED_DB_MIN_VERSION = 4

class IndexedMigrator implements Migrator {
onInstall(): void {
}
onUpdate(previousVersion: string): void {
const major = parseInt(previousVersion.split('.')[0] ?? '0', 10)
if (isNaN(major) || major >= INDEXED_DB_MIN_VERSION) return

timelineDatabase.migrateFromClassic()
.then(() => console.log('Timeline data migrated to IndexedDB'))
.catch(e => console.error('Failed to migrate timeline data to IndexedDB', e))
}
}

export default IndexedMigrator
35 changes: 0 additions & 35 deletions src/background/migrator/limit-rule-migrator.ts

This file was deleted.

2 changes: 1 addition & 1 deletion src/background/migrator/local-file-initializer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import mergeRuleDatabase from "@db/merge-rule-database"
import { t2Chrome } from "@i18n/chrome/t"
import { saveAlias } from '@service/site-service'
import { JSON_HOST, LOCAL_HOST_PATTERN, MERGED_HOST, PDF_HOST, PIC_HOST, TXT_HOST } from "@util/constant/remain-host"
import { type Migrator } from "./common"
import { type Migrator } from "./types"

/**
* Process the host of local files
Expand Down
File renamed without changes.
5 changes: 2 additions & 3 deletions src/background/migrator/whitelist-initializer.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import whitelistService from "@service/whitelist/service"
import { type Migrator } from "./common"
import type { Migrator } from "./types"

export default class WhitelistInitializer implements Migrator {
onInstall(): void {
whitelistService.add('localhost:*/**')
}

onUpdate(version: string): void {
version === '2.5.7' && this.onInstall()
onUpdate(_version: string): void {
}
}
2 changes: 1 addition & 1 deletion src/background/track-server/group.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import itemService from '@service/item-service'

function handleTabGroupRemove(group: chrome.tabGroups.TabGroup) {
itemService.batchDeleteGroupById(group.id)
itemService.deleteByGroup(group.id)
}

export function handleTabGroupEnabled() {
Expand Down
2 changes: 1 addition & 1 deletion src/background/track-server/runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { formatTimeYMD, getStartOfDay, MILL_PER_DAY } from "@util/time"
function splitRunTime(start: number, end: number): Record<string, number> {
const res: Record<string, number> = {}
while (start < end) {
const startOfNextDay = getStartOfDay(start).getTime() + MILL_PER_DAY
const startOfNextDay = getStartOfDay(start) + MILL_PER_DAY
const newStart = Math.min(end, startOfNextDay)
const runTime = newStart - start
runTime && (res[formatTimeYMD(start)] = runTime)
Expand Down
4 changes: 0 additions & 4 deletions src/database/backup-database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,6 @@ class BackupDatabase extends BaseDatabase {
async updateCache(type: timer.backup.Type, newVal: unknown): Promise<void> {
return this.storage.put(cacheKeyOf(type), newVal as Object)
}

async importData(_data: any): Promise<void> {
// Do nothing
}
}

const backupDatabase = new BackupDatabase()
Expand Down
8 changes: 0 additions & 8 deletions src/database/common/base-database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,4 @@ export default abstract class BaseDatabase {
protected setByKey(key: string, val: any): Promise<void> {
return this.storage.put(key, val)
}

/**
* Import data
*
* @since 0.2.5
* @param data backup data
*/
abstract importData(data: any): Promise<void>
}
Loading