From ae9e4faa7bce9401504f68f9b9b1248eb232b2cb Mon Sep 17 00:00:00 2001 From: oomeow Date: Wed, 1 Oct 2025 10:17:08 +0800 Subject: [PATCH] chore: todo --- src-tauri/src/cmd/clash.rs | 2 +- src-tauri/src/cmd/proxy.rs | 2 +- src-tauri/src/core/core.rs | 4 ++++ src-tauri/src/core/handle.rs | 1 + src-tauri/src/core/tray/mod.rs | 11 ++++++++--- src-tauri/src/lib.rs | 1 + src-tauri/src/utils/format.rs | 1 + src-tauri/src/utils/logging.rs | 4 ++-- src/components/proxy/proxy-groups.tsx | 8 +++++++- src/pages/_layout.tsx | 2 -- src/providers/app-data-provider.tsx | 2 +- 11 files changed, 27 insertions(+), 11 deletions(-) diff --git a/src-tauri/src/cmd/clash.rs b/src-tauri/src/cmd/clash.rs index 61ef253d..88c44bff 100644 --- a/src-tauri/src/cmd/clash.rs +++ b/src-tauri/src/cmd/clash.rs @@ -106,7 +106,7 @@ pub async fn restart_core() -> CmdResult { result } -/// 获取代理延迟 +// 获取代理延迟 // #[tauri::command] // pub async fn clash_api_get_proxy_delay( // name: String, diff --git a/src-tauri/src/cmd/proxy.rs b/src-tauri/src/cmd/proxy.rs index be83c07d..6ae3fc56 100644 --- a/src-tauri/src/cmd/proxy.rs +++ b/src-tauri/src/cmd/proxy.rs @@ -31,7 +31,7 @@ use crate::{ // Ok((*value).clone()) // } -/// 强制刷新代理缓存用于profile切换 +// 强制刷新代理缓存用于profile切换 // #[tauri::command] // pub async fn force_refresh_proxies() -> CmdResult { // let cache = CacheProxy::global(); diff --git a/src-tauri/src/core/core.rs b/src-tauri/src/core/core.rs index a3ef55d6..4ae10993 100644 --- a/src-tauri/src/core/core.rs +++ b/src-tauri/src/core/core.rs @@ -25,6 +25,10 @@ use std::{ }; use tauri_plugin_shell::{ShellExt, process::CommandChild}; +// TODO: +// - 重构,提升模式切换速度 +// - 内核启动添加启动 IPC 启动参数, `-ext-ctl-unix` / `-ext-ctl-pipe`, 运行时配置需要删除相关配置项 + #[derive(Debug)] pub struct CoreManager { running: Arc>, diff --git a/src-tauri/src/core/handle.rs b/src-tauri/src/core/handle.rs index a85f225b..0a014d06 100644 --- a/src-tauri/src/core/handle.rs +++ b/src-tauri/src/core/handle.rs @@ -284,6 +284,7 @@ impl Handle { } /// 获取 AppHandle + #[allow(clippy::expect_used)] pub fn app_handle() -> &'static AppHandle { APP_HANDLE.get().expect("failed to get global app handle") } diff --git a/src-tauri/src/core/tray/mod.rs b/src-tauri/src/core/tray/mod.rs index 909ed19e..7b5ec2c7 100644 --- a/src-tauri/src/core/tray/mod.rs +++ b/src-tauri/src/core/tray/mod.rs @@ -31,6 +31,11 @@ use tauri::{ tray::{MouseButton, MouseButtonState, TrayIconEvent}, }; +// TODO: +// - 定时更新代理菜单(5s) +// - 前端选择节点/代理组测速后,发送 event 事件,Tray 监听此事件 +// - 是否需要将可变菜单抽离存储起来,后续直接更新对应菜单实例,无需重新创建菜单(待考虑) + #[derive(Clone)] struct TrayState {} @@ -187,7 +192,7 @@ singleton_lazy!(Tray, TRAY, Tray::default); impl Tray { pub async fn init(&self) -> Result<()> { let app_handle = handle::Handle::app_handle(); - self.create_tray_from_handle(&app_handle).await?; + self.create_tray_from_handle(app_handle).await?; Ok(()) } @@ -238,7 +243,7 @@ impl Tray { // 设置更新状态 self.menu_updating.store(true, Ordering::Release); - let result = self.update_menu_internal(&app_handle).await; + let result = self.update_menu_internal(app_handle).await; { let mut last_update = self.last_menu_update.lock(); @@ -658,7 +663,7 @@ async fn create_tray_menu( _ => { current_profile_selected .iter() - .any(|s| s.name.as_deref() == Some(&group_name)) + .any(|s| s.name.as_deref() == Some(group_name)) && !now_proxy.is_empty() } }; diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index b3276f09..6fc1502a 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -314,6 +314,7 @@ pub fn run() { .setup(|app| { logging!(info, Type::Setup, true, "开始应用初始化..."); + #[allow(clippy::expect_used)] APP_HANDLE .set(app.app_handle().clone()) .expect("failed to set global app handle"); diff --git a/src-tauri/src/utils/format.rs b/src-tauri/src/utils/format.rs index 270206c3..86437a49 100644 --- a/src-tauri/src/utils/format.rs +++ b/src-tauri/src/utils/format.rs @@ -1,4 +1,5 @@ /// Format bytes into human readable string (B, KB, MB, GB) +#[allow(unused)] pub fn fmt_bytes(bytes: u64) -> String { const UNITS: &[&str] = &["B", "KB", "MB", "GB"]; let (mut val, mut unit) = (bytes as f64, 0); diff --git a/src-tauri/src/utils/logging.rs b/src-tauri/src/utils/logging.rs index 1390ca0e..7f95b9b4 100644 --- a/src-tauri/src/utils/logging.rs +++ b/src-tauri/src/utils/logging.rs @@ -28,7 +28,7 @@ pub enum Type { Lightweight, Network, ProxyMode, - Ipc, + // Ipc, // Cache, ClashVergeRev, } @@ -51,7 +51,7 @@ impl fmt::Display for Type { Type::Lightweight => write!(f, "[Lightweight]"), Type::Network => write!(f, "[Network]"), Type::ProxyMode => write!(f, "[ProxMode]"), - Type::Ipc => write!(f, "[IPC]"), + // Type::Ipc => write!(f, "[IPC]"), // Type::Cache => write!(f, "[Cache]"), Type::ClashVergeRev => write!(f, "[ClashVergeRev]"), } diff --git a/src/components/proxy/proxy-groups.tsx b/src/components/proxy/proxy-groups.tsx index b848a450..57258766 100644 --- a/src/components/proxy/proxy-groups.tsx +++ b/src/components/proxy/proxy-groups.tsx @@ -17,7 +17,10 @@ import { Virtuoso, type VirtuosoHandle } from "react-virtuoso"; import { useProxySelection } from "@/hooks/use-proxy-selection"; import { useVerge } from "@/hooks/use-verge"; import { useAppData } from "@/providers/app-data-provider"; -import { updateProxyChainConfigInRuntime } from "@/services/cmds"; +import { + getRuntimeConfig, + updateProxyChainConfigInRuntime, +} from "@/services/cmds"; import delayManager from "@/services/delay"; import { BaseEmpty } from "../base"; @@ -28,6 +31,8 @@ import { ProxyRender } from "./proxy-render"; import { ProxyGroupNavigator } from "./proxy-group-navigator"; import { useRenderList } from "./use-render-list"; import { delayGroup, healthcheckProxyProvider } from "tauri-plugin-mihomo-api"; +import useSWR from "swr"; +import { useMemo } from "react"; interface Props { mode: string; @@ -209,6 +214,7 @@ export const ProxyGroups = (props: Props) => { const currentGroup = getCurrentGroup(); const availableGroups = getAvailableGroups(); + // TODO: 频繁点击切换代理节点,导致应用卡死 const handleChangeProxy = useCallback( (group: IProxyGroupItem, proxy: IProxyItem) => { if (isChainMode) { diff --git a/src/pages/_layout.tsx b/src/pages/_layout.tsx index 039ca9b2..d9a26b48 100644 --- a/src/pages/_layout.tsx +++ b/src/pages/_layout.tsx @@ -2,7 +2,6 @@ import { List, Paper, ThemeProvider, SvgIcon } from "@mui/material"; import { getCurrentWebviewWindow } from "@tauri-apps/api/webviewWindow"; import dayjs from "dayjs"; import relativeTime from "dayjs/plugin/relativeTime"; -import { useLocalStorage } from "foxact/use-local-storage"; import { useEffect, useCallback, useState, useRef } from "react"; import React from "react"; import { useTranslation } from "react-i18next"; @@ -37,7 +36,6 @@ import { invoke } from "@tauri-apps/api/core"; import { showNotice } from "@/services/noticeService"; import { NoticeManager } from "@/components/base/NoticeManager"; -import { LogLevel } from "@/hooks/use-log-data"; import { useMemoryData } from "@/hooks/use-memory-data"; import { useTrafficData } from "@/hooks/use-traffic-data"; import { useConnectionData } from "@/hooks/use-connection-data"; diff --git a/src/providers/app-data-provider.tsx b/src/providers/app-data-provider.tsx index 56be8bd6..f0d73d60 100644 --- a/src/providers/app-data-provider.tsx +++ b/src/providers/app-data-provider.tsx @@ -334,7 +334,7 @@ export const AppDataProvider = ({ // 高频率更新数据 (2秒) const { data: uptimeData } = useSWR("appUptime", getAppUptime, { // TODO: 运行时间 - refreshInterval: 20000, + refreshInterval: 2000, revalidateOnFocus: false, suspense: false, });