refactor: knip cleanup (#7468)

* chore(frontend): expand Knip reports

* chore: remove unused Mihomo changelog sync script

* refactor: remove unused value exports

* refactor: remove unused type exports

* refactor: remove circular route dependencies

* chore(frontend): move Knip scope to config

* chore(i18n): remove stale portable update message
This commit is contained in:
Tunglies
2026-07-13 11:29:25 +08:00
committed by GitHub
parent 6f9fb97b31
commit 7ca20fc4ed
44 changed files with 266 additions and 602 deletions
-79
View File
@@ -100,10 +100,6 @@ export async function getRuntimeYaml() {
return invoke<string | null>('get_runtime_yaml')
}
export async function getRuntimeExists() {
return invoke<string[]>('get_runtime_exists')
}
export async function getRuntimeLogs() {
return invoke<Record<string, [string, string][]>>('get_runtime_logs')
}
@@ -264,10 +260,6 @@ export async function getClashLogs() {
}, [])
}
export async function clearLogs() {
return invoke<void>('clear_logs')
}
export async function getVergeConfig() {
return invoke<IVergeConfig>('get_verge_config')
}
@@ -302,23 +294,10 @@ export async function getAutotemProxy() {
}
}
export async function getAutoLaunchStatus() {
try {
return await invoke<boolean>('get_auto_launch_status')
} catch (error) {
console.error('获取自启动状态失败:', error)
return false
}
}
export async function changeClashCore(clashCore: string) {
return invoke<string | null>('change_clash_core', { clashCore })
}
export async function startCore() {
return invoke<void>('start_core')
}
export async function stopCore() {
return invoke<void>('stop_core')
}
@@ -355,38 +334,6 @@ export const openWebUrl = async (url: string) => {
}
}
export async function cmdGetProxyDelay(
name: string,
timeout: number,
url?: string,
) {
// 确保URL不为空
const testUrl = url || 'http://cp.cloudflare.com/generate_204'
try {
// 不再在前端编码代理名称,由后端统一处理编码
const result = await invoke<{ delay: number }>(
'clash_api_get_proxy_delay',
{
name,
url: testUrl, // 传递经过验证的URL
timeout,
},
)
// 验证返回结果中是否有delay字段,并且值是一个有效的数字
if (result && typeof result.delay === 'number') {
return result
} else {
// 返回一个有效的结果对象,但标记为超时
return { delay: 1e6 }
}
} catch {
// 返回一个有效的结果对象,但标记为错误
return { delay: 1e6 }
}
}
export async function cmdTestDelay(url: string) {
return invoke<number>('test_delay', { url })
}
@@ -397,10 +344,6 @@ export async function invoke_uwp_tool() {
)
}
export async function getPortableFlag() {
return invoke<boolean>('get_portable_flag')
}
export async function openDevTools() {
return invoke('open_devtools')
}
@@ -518,14 +461,6 @@ export async function listLocalBackup() {
return invoke<ILocalBackupFile[]>('list_local_backup')
}
export async function scriptValidateNotice(status: string, msg: string) {
return invoke<void>('script_validate_notice', { status, msg })
}
export async function validateScriptFile(filePath: string) {
return invoke<ValidationOutcome>('validate_script_file', { filePath })
}
// 获取当前运行模式
export const getRunningMode = async () => {
return invoke<string>('get_running_mode')
@@ -546,16 +481,6 @@ export const uninstallService = async () => {
return invoke<void>('uninstall_service')
}
// 重装系统服务
export const reinstallService = async () => {
return invoke<void>('reinstall_service')
}
// 修复系统服务
export const repairService = async () => {
return invoke<void>('repair_service')
}
// 系统服务是否可用
export const isServiceAvailable = async () => {
try {
@@ -569,10 +494,6 @@ export const entry_lightweight_mode = async () => {
return invoke<void>('entry_lightweight_mode')
}
export const exit_lightweight_mode = async () => {
return invoke<void>('exit_lightweight_mode')
}
export const isAdmin = async () => {
try {
return await invoke<boolean>('app_is_admin')
-11
View File
@@ -105,14 +105,6 @@ const localeLoaders = Object.entries(localeModules).reduce<
return acc
}, {})
export const languages: Record<string, any> = supportedLanguages.reduce(
(acc, lang) => {
acc[lang] = {}
return acc
},
{} as Record<string, any>,
)
const loadLanguageSections = async (
language: string,
sections: readonly string[],
@@ -144,9 +136,6 @@ const loadLanguageSections = async (
}
}
export const loadLanguage = async (language: string) =>
loadLanguageSections(language, STARTUP_LANGUAGE_SECTIONS)
const getLoadedLanguageSections = (language: string) =>
Object.keys(i18n.getResourceBundle(language, 'translation') ?? {})
+1 -1
View File
@@ -3,7 +3,7 @@ import { ReactNode, isValidElement } from 'react'
type NoticeType = 'success' | 'error' | 'info'
export interface NoticeTranslationDescriptor {
interface NoticeTranslationDescriptor {
key: string
params?: Record<string, unknown>
}
+2 -2
View File
@@ -45,7 +45,7 @@ export const setPreloadConfig = (config: IVergeConfig | null) => {
export const getPreloadConfig = () => vergeConfigCache
export const preloadConfig = async () => {
const preloadConfig = async () => {
try {
const config = await getVergeConfig()
setPreloadConfig(config)
@@ -57,7 +57,7 @@ export const preloadConfig = async () => {
}
}
export const preloadLanguage = async (
const preloadLanguage = async (
vergeConfig?: IVergeConfig | null,
loadConfig: () => Promise<IVergeConfig | null> = preloadConfig,
) => {
+1 -1
View File
@@ -31,7 +31,7 @@ type QueryResult<T> = SWRResponse<T> & {
const serializeQueryKey = (queryKey: QueryKey) => unstable_serialize(queryKey)
export const queryCache = new Map<string, unknown>()
const queryCache = new Map<string, unknown>()
const setCachedData = <T>(queryKey: QueryKey, data: T | undefined) => {
const cacheKey = serializeQueryKey(queryKey)
+7 -16
View File
@@ -6,7 +6,7 @@ import {
import { version as appVersion } from '@root/package.json'
export type VersionParts = {
type VersionParts = {
main: number[]
pre: (number | string)[]
}
@@ -16,33 +16,27 @@ const SEMVER_FULL_REGEX =
const SEMVER_SEARCH_REGEX =
/v?\d+(?:\.\d+){1,2}(?:-[0-9A-Za-z.-]+)?(?:\+[0-9A-Za-z.-]+)?/i
export const normalizeVersion = (
input: string | null | undefined,
): string | null => {
const normalizeVersion = (input: string | null | undefined): string | null => {
if (typeof input !== 'string') return null
const trimmed = input.trim()
if (!trimmed) return null
return trimmed.replace(/^v/i, '')
}
export const ensureSemver = (
input: string | null | undefined,
): string | null => {
const ensureSemver = (input: string | null | undefined): string | null => {
const normalized = normalizeVersion(input)
if (!normalized) return null
return SEMVER_FULL_REGEX.test(normalized) ? normalized : null
}
export const extractSemver = (
input: string | null | undefined,
): string | null => {
const extractSemver = (input: string | null | undefined): string | null => {
if (typeof input !== 'string') return null
const match = input.match(SEMVER_SEARCH_REGEX)
if (!match) return null
return normalizeVersion(match[0])
}
export const splitVersion = (version: string | null): VersionParts | null => {
const splitVersion = (version: string | null): VersionParts | null => {
if (!version) return null
const [mainPart, preRelease] = version.split('-')
const main = mainPart
@@ -93,17 +87,14 @@ const compareVersionParts = (a: VersionParts, b: VersionParts): number => {
return 0
}
export const compareVersions = (
a: string | null,
b: string | null,
): number | null => {
const compareVersions = (a: string | null, b: string | null): number | null => {
const partsA = splitVersion(a)
const partsB = splitVersion(b)
if (!partsA || !partsB) return null
return compareVersionParts(partsA, partsB)
}
export const resolveRemoteVersion = (update: Update): string | null => {
const resolveRemoteVersion = (update: Update): string | null => {
const primary = ensureSemver(update.version)
if (primary) return primary