refactor: debugLog for frontend (#5587)

This commit is contained in:
Sline
2025-11-25 10:01:04 +08:00
committed by GitHub
parent 64727ad660
commit caca8b2bc4
24 changed files with 181 additions and 99 deletions
+12 -16
View File
@@ -60,14 +60,12 @@ import {
} from "@/services/cmds";
import { showNotice } from "@/services/noticeService";
import { useSetLoadingCache, useThemeMode } from "@/services/states";
import { debugLog } from "@/utils/debug";
// 记录profile切换状态
const debugProfileSwitch = (action: string, profile: string, extra?: any) => {
const timestamp = new Date().toISOString().substring(11, 23);
console.log(
`[Profile-Debug][${timestamp}] ${action}: ${profile}`,
extra || "",
);
debugLog(`[Profile-Debug][${timestamp}] ${action}: ${profile}`, extra || "");
};
// 检查请求是否已过期
@@ -223,7 +221,7 @@ const ProfilePage = () => {
// 添加紧急恢复功能
const onEmergencyRefresh = useLockFn(async () => {
console.log("[紧急刷新] 开始强制刷新所有数据");
debugLog("[紧急刷新] 开始强制刷新所有数据");
try {
// 清除所有SWR缓存
@@ -327,7 +325,7 @@ const ProfilePage = () => {
while (retryCount < maxRetries) {
try {
console.log(`[导入刷新] 第${retryCount + 1}次尝试刷新配置数据`);
debugLog(`[导入刷新] 第${retryCount + 1}次尝试刷新配置数据`);
// 强制刷新,绕过所有缓存
await mutateProfiles(undefined, {
@@ -393,7 +391,7 @@ const ProfilePage = () => {
!abortController.signal.aborted
) {
await activateSelected();
console.log(`[Profile] 后台处理完成,序列号: ${sequence}`);
debugLog(`[Profile] 后台处理完成,序列号: ${sequence}`);
} else {
debugProfileSwitch(
"BACKGROUND_TASK_SKIPPED",
@@ -411,9 +409,7 @@ const ProfilePage = () => {
const activateProfile = useCallback(
async (profile: string, notifySuccess: boolean) => {
if (profiles.current === profile && !notifySuccess) {
console.log(
`[Profile] 目标profile ${profile} 已经是当前配置,跳过切换`,
);
debugLog(`[Profile] 目标profile ${profile} 已经是当前配置,跳过切换`);
return;
}
@@ -445,7 +441,7 @@ const ProfilePage = () => {
});
try {
console.log(
debugLog(
`[Profile] 开始切换到: ${profile},序列号: ${currentSequence}`,
);
@@ -489,7 +485,7 @@ const ProfilePage = () => {
);
}
console.log(
debugLog(
`[Profile] 切换到 ${profile} 完成,序列号: ${currentSequence},开始后台处理`,
);
@@ -569,7 +565,7 @@ const ProfilePage = () => {
const onEnhance = useLockFn(async (notifySuccess: boolean) => {
if (switchingProfileRef.current) {
console.log(
debugLog(
`[Profile] 有profile正在切换中(${switchingProfileRef.current}),跳过enhance操作`,
);
return;
@@ -752,20 +748,20 @@ const ProfilePage = () => {
const newProfileId = event.payload;
const now = Date.now();
console.log(`[Profile] 收到配置变更事件: ${newProfileId}`);
debugLog(`[Profile] 收到配置变更事件: ${newProfileId}`);
if (
lastProfileId === newProfileId &&
now - lastUpdateTime < debounceDelay
) {
console.log(`[Profile] 重复事件被防抖,跳过`);
debugLog(`[Profile] 重复事件被防抖,跳过`);
return;
}
lastProfileId = newProfileId;
lastUpdateTime = now;
console.log(`[Profile] 执行配置数据刷新`);
debugLog(`[Profile] 执行配置数据刷新`);
if (refreshTimer !== null) {
window.clearTimeout(refreshTimer);
+3 -2
View File
@@ -15,6 +15,7 @@ import {
patchClashMode,
updateProxyChainConfigInRuntime,
} from "@/services/cmds";
import { debugLog } from "@/utils/debug";
const MODES = ["rule", "global", "direct"] as const;
type Mode = (typeof MODES)[number];
@@ -81,9 +82,9 @@ const ProxyPage = () => {
if (!newChainMode) {
// 退出链式代理模式时,清除链式代理配置
try {
console.log("Exiting chain mode, clearing chain configuration");
debugLog("Exiting chain mode, clearing chain configuration");
await updateProxyChainConfigInRuntime(null);
console.log("Chain configuration cleared successfully");
debugLog("Chain configuration cleared successfully");
} catch (error) {
console.error("Failed to clear chain configuration:", error);
}