diff --git a/src/locales/en.json b/src/locales/en.json index 7a4d5132..d614c85c 100644 --- a/src/locales/en.json +++ b/src/locales/en.json @@ -677,5 +677,6 @@ "Controller address copied to clipboard": "Controller address copied to clipboard", "Secret copied to clipboard": "Secret copied to clipboard", "Saving...": "Saving...", - "Proxy node already exists in chain": "Proxy node already exists in chain" + "Proxy node already exists in chain": "Proxy node already exists in chain", + "Detection timeout or failed": "Detection timeout or failed" } diff --git a/src/locales/zh.json b/src/locales/zh.json index d94fff83..af70b0d8 100644 --- a/src/locales/zh.json +++ b/src/locales/zh.json @@ -677,5 +677,6 @@ "Controller address copied to clipboard": "控制器地址已复制到剪贴板", "Secret copied to clipboard": "访问密钥已复制到剪贴板", "Saving...": "保存中...", - "Proxy node already exists in chain": "该节点已在链式代理表中" + "Proxy node already exists in chain": "该节点已在链式代理表中", + "Detection timeout or failed": "检测超时或失败" } diff --git a/src/pages/unlock.tsx b/src/pages/unlock.tsx index a9c66765..d4d6c227 100644 --- a/src/pages/unlock.tsx +++ b/src/pages/unlock.tsx @@ -26,7 +26,6 @@ import { } from "@mui/icons-material"; import { showNotice } from "@/services/noticeService"; -// 定义流媒体检测项类型 interface UnlockItem { name: string; status: string; @@ -34,7 +33,6 @@ interface UnlockItem { check_time?: string | null; } -// 用于存储测试结果的本地存储键名 const UNLOCK_RESULTS_STORAGE_KEY = "clash_verge_unlock_results"; const UNLOCK_RESULTS_TIME_KEY = "clash_verge_unlock_time"; @@ -42,14 +40,10 @@ const UnlockPage = () => { const { t } = useTranslation(); const theme = useTheme(); - // 保存所有流媒体检测项的状态 const [unlockItems, setUnlockItems] = useState([]); - // 是否正在执行全部检测 const [isCheckingAll, setIsCheckingAll] = useState(false); - // 记录正在检测中的项目 const [loadingItems, setLoadingItems] = useState([]); - // 按首字母排序项目 const sortItemsByName = (items: UnlockItem[]) => { return [...items].sort((a, b) => a.name.localeCompare(b.name)); }; @@ -66,7 +60,6 @@ const UnlockPage = () => { } }; - // 从本地存储加载测试结果 const loadResultsFromStorage = (): { items: UnlockItem[] | null; time: string | null; @@ -88,24 +81,17 @@ const UnlockPage = () => { return { items: null, time: null }; }; - // 页面加载时获取初始检测项列表 useEffect(() => { - // 尝试从本地存储加载上次测试结果 const { items: storedItems } = loadResultsFromStorage(); if (storedItems && storedItems.length > 0) { - // 如果有存储的结果,优先使用 setUnlockItems(storedItems); - - // 后台同时获取最新的初始状态(但不更新UI) getUnlockItems(false); } else { - // 没有存储的结果,获取初始状态 getUnlockItems(true); } }, []); - // 获取所有解锁检测项列表 const getUnlockItems = async (updateUI: boolean = true) => { try { const items = await invoke("get_unlock_items"); @@ -119,7 +105,6 @@ const UnlockPage = () => { } }; - // invoke加超时,防止后端卡死 const invokeWithTimeout = async ( cmd: string, args?: any, @@ -128,7 +113,10 @@ const UnlockPage = () => { return Promise.race([ invoke(cmd, args), new Promise((_, reject) => - setTimeout(() => reject(new Error("Timeout")), timeout), + setTimeout( + () => reject(new Error(t("Detection timeout or failed"))), + timeout, + ), ), ]); }; @@ -149,8 +137,10 @@ const UnlockPage = () => { setIsCheckingAll(false); } catch (err: any) { setIsCheckingAll(false); - showNotice("error", err?.message || err?.toString() || "检测超时或失败"); - alert("检测超时或失败: " + (err?.message || err)); + showNotice( + "error", + err?.message || err?.toString() || t("Detection timeout or failed"), + ); console.error("Failed to check media unlock:", err); } }); @@ -180,13 +170,17 @@ const UnlockPage = () => { setLoadingItems((prev) => prev.filter((item) => item !== name)); } catch (err: any) { setLoadingItems((prev) => prev.filter((item) => item !== name)); - showNotice("error", err?.message || err?.toString() || `检测${name}失败`); - alert("检测超时或失败: " + (err?.message || err)); + showNotice( + "error", + err?.message || + err?.toString() || + t("Detection failed for {name}").replace("{name}", name), + ); console.error(`Failed to check ${name}:`, err); } }); - // 获取状态对应的颜色 + // 状态颜色 const getStatusColor = (status: string) => { if (status === "Pending") return "default"; if (status === "Yes") return "success"; @@ -204,7 +198,7 @@ const UnlockPage = () => { return "default"; }; - // 获取状态对应的图标 + // 状态图标 const getStatusIcon = (status: string) => { if (status === "Pending") return ; if (status === "Yes") return ; @@ -214,7 +208,7 @@ const UnlockPage = () => { return ; }; - // 获取状态对应的边框色 + // 边框色 const getStatusBorderColor = (status: string) => { if (status === "Yes") return theme.palette.success.main; if (status === "No") return theme.palette.error.main; @@ -263,7 +257,7 @@ const UnlockPage = () => { ) : ( {unlockItems.map((item) => ( - + { minWidth: "32px", width: "32px", height: "32px", - //p: 0, borderRadius: "50%", }} onClick={() => checkSingleMedia(item.name)} > - {loadingItems.includes(item.name) ? ( - - ) : ( - - )} +