mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2026-11-06 17:12:07 +08:00
refactor: debugLog for frontend (#5587)
This commit is contained in:
+4
-2
@@ -1,5 +1,7 @@
|
||||
import { fetch } from "@tauri-apps/plugin-http";
|
||||
|
||||
import { debugLog } from "@/utils/debug";
|
||||
|
||||
// Get current IP and geolocation information (refactored IP detection with service-specific mappings)
|
||||
interface IpInfo {
|
||||
ip: string;
|
||||
@@ -163,7 +165,7 @@ export const getIpInfo = async (): Promise<IpInfo> => {
|
||||
let lastError: Error | null = null;
|
||||
|
||||
for (const service of shuffledServices) {
|
||||
console.log(`尝试IP检测服务: ${service.url}`);
|
||||
debugLog(`尝试IP检测服务: ${service.url}`);
|
||||
|
||||
for (let attempt = 0; attempt < maxRetries; attempt++) {
|
||||
let timeoutId: ReturnType<typeof setTimeout> | null = null;
|
||||
@@ -186,7 +188,7 @@ export const getIpInfo = async (): Promise<IpInfo> => {
|
||||
if (timeoutId) clearTimeout(timeoutId);
|
||||
|
||||
if (data && data.ip) {
|
||||
console.log(`IP检测成功,使用服务: ${service.url}`);
|
||||
debugLog(`IP检测成功,使用服务: ${service.url}`);
|
||||
return service.mapping(data);
|
||||
} else {
|
||||
throw new Error(`无效的响应格式 from ${service.url}`);
|
||||
|
||||
@@ -3,6 +3,7 @@ import dayjs from "dayjs";
|
||||
import { getProxies, getProxyProviders } from "tauri-plugin-mihomo-api";
|
||||
|
||||
import { showNotice } from "@/services/noticeService";
|
||||
import { debugLog } from "@/utils/debug";
|
||||
|
||||
export async function copyClashEnv() {
|
||||
return invoke<void>("copy_clash_env");
|
||||
@@ -264,12 +265,12 @@ export async function getSystemProxy() {
|
||||
|
||||
export async function getAutotemProxy() {
|
||||
try {
|
||||
console.log("[API] 开始调用 get_auto_proxy");
|
||||
debugLog("[API] 开始调用 get_auto_proxy");
|
||||
const result = await invoke<{
|
||||
enable: boolean;
|
||||
url: string;
|
||||
}>("get_auto_proxy");
|
||||
console.log("[API] get_auto_proxy 调用成功:", result);
|
||||
debugLog("[API] get_auto_proxy 调用成功:", result);
|
||||
return result;
|
||||
} catch (error) {
|
||||
console.error("[API] get_auto_proxy 调用失败:", error);
|
||||
|
||||
+11
-11
@@ -1,5 +1,7 @@
|
||||
import { delayProxyByName, ProxyDelay } from "tauri-plugin-mihomo-api";
|
||||
|
||||
import { debugLog } from "@/utils/debug";
|
||||
|
||||
const hashKey = (name: string, group: string) => `${group ?? ""}::${name}`;
|
||||
|
||||
export interface DelayUpdate {
|
||||
@@ -108,13 +110,13 @@ class DelayManager {
|
||||
}
|
||||
|
||||
setUrl(group: string, url: string) {
|
||||
console.log(`[DelayManager] 设置测试URL,组: ${group}, URL: ${url}`);
|
||||
debugLog(`[DelayManager] 设置测试URL,组: ${group}, URL: ${url}`);
|
||||
this.urlMap.set(group, url);
|
||||
}
|
||||
|
||||
getUrl(group: string) {
|
||||
const url = this.urlMap.get(group);
|
||||
console.log(
|
||||
debugLog(
|
||||
`[DelayManager] 获取测试URL,组: ${group}, URL: ${url || "未设置"}`,
|
||||
);
|
||||
// 如果未设置URL,返回默认URL
|
||||
@@ -150,7 +152,7 @@ class DelayManager {
|
||||
meta?: { elapsed?: number },
|
||||
): DelayUpdate {
|
||||
const key = hashKey(name, group);
|
||||
console.log(
|
||||
debugLog(
|
||||
`[DelayManager] 设置延迟,代理: ${name}, 组: ${group}, 延迟: ${delay}`,
|
||||
);
|
||||
const update: DelayUpdate = {
|
||||
@@ -212,7 +214,7 @@ class DelayManager {
|
||||
group: string,
|
||||
timeout: number,
|
||||
): Promise<DelayUpdate> {
|
||||
console.log(
|
||||
debugLog(
|
||||
`[DelayManager] 开始测试延迟,代理: ${name}, 组: ${group}, 超时: ${timeout}ms`,
|
||||
);
|
||||
|
||||
@@ -226,7 +228,7 @@ class DelayManager {
|
||||
|
||||
try {
|
||||
const url = this.getUrl(group);
|
||||
console.log(`[DelayManager] 调用API测试延迟,代理: ${name}, URL: ${url}`);
|
||||
debugLog(`[DelayManager] 调用API测试延迟,代理: ${name}, URL: ${url}`);
|
||||
|
||||
// 设置超时处理, delay = 0 为超时
|
||||
const timeoutPromise = new Promise<ProxyDelay>((resolve) => {
|
||||
@@ -247,9 +249,7 @@ class DelayManager {
|
||||
|
||||
delay = result.delay;
|
||||
elapsed = elapsedTime;
|
||||
console.log(
|
||||
`[DelayManager] 延迟测试完成,代理: ${name}, 结果: ${delay}ms`,
|
||||
);
|
||||
debugLog(`[DelayManager] 延迟测试完成,代理: ${name}, 结果: ${delay}ms`);
|
||||
} catch (error) {
|
||||
// 确保至少显示500ms的加载动画
|
||||
await new Promise((resolve) => setTimeout(resolve, 500));
|
||||
@@ -267,7 +267,7 @@ class DelayManager {
|
||||
timeout: number,
|
||||
concurrency = 36,
|
||||
) {
|
||||
console.log(
|
||||
debugLog(
|
||||
`[DelayManager] 批量测试延迟开始,组: ${group}, 数量: ${nameList.length}, 并发数: ${concurrency}`,
|
||||
);
|
||||
const names = nameList.filter(Boolean);
|
||||
@@ -312,7 +312,7 @@ class DelayManager {
|
||||
|
||||
// 限制并发数,避免发送太多请求
|
||||
const actualConcurrency = Math.min(concurrency, names.length, 10);
|
||||
console.log(`[DelayManager] 实际并发数: ${actualConcurrency}`);
|
||||
debugLog(`[DelayManager] 实际并发数: ${actualConcurrency}`);
|
||||
|
||||
const promiseList: Promise<void>[] = [];
|
||||
for (let i = 0; i < actualConcurrency; i++) {
|
||||
@@ -321,7 +321,7 @@ class DelayManager {
|
||||
|
||||
await Promise.all(promiseList);
|
||||
const totalTime = Date.now() - startTime;
|
||||
console.log(
|
||||
debugLog(
|
||||
`[DelayManager] 批量测试延迟完成,组: ${group}, 总耗时: ${totalTime}ms`,
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user