diff --git a/src-tauri/src/core/timer.rs b/src-tauri/src/core/timer.rs index f3f01c6b..07d1b70f 100644 --- a/src-tauri/src/core/timer.rs +++ b/src-tauri/src/core/timer.rs @@ -139,6 +139,24 @@ impl Timer { Ok(()) } + // pub async fn add_update_tray_menu_task(&self) -> Result<()> { + // let tid = self.timer_count.fetch_add(1, Ordering::SeqCst); + // let delay_timer = self.delay_timer.write(); + // let task = TaskBuilder::default() + // .set_task_id(tid) + // .set_maximum_parallel_runnable_num(1) + // .set_frequency_repeated_by_seconds(5) + // .spawn_async_routine(|| async move { + // logging!(info, Type::Timer, "Updating tray menu"); + // core::tray::Tray::global().update_tray_display().await + // }) + // .context("failed to create update tray menu timer task")?; + // delay_timer + // .add_task(task) + // .context("failed to add update tray menu timer task")?; + // Ok(()) + // } + /// Refresh timer tasks with better error handling pub async fn refresh(&self) -> Result<()> { // Generate diff outside of lock to minimize lock contention diff --git a/src-tauri/src/core/tray/mod.rs b/src-tauri/src/core/tray/mod.rs index a1dcad3e..b79417dc 100644 --- a/src-tauri/src/core/tray/mod.rs +++ b/src-tauri/src/core/tray/mod.rs @@ -1,5 +1,5 @@ use once_cell::sync::OnceCell; -use tauri::Emitter; +use tauri::{Emitter}; use tauri::tray::TrayIconBuilder; #[cfg(target_os = "macos")] pub mod speed_rate; @@ -193,6 +193,7 @@ impl Tray { pub async fn init(&self) -> Result<()> { let app_handle = handle::Handle::app_handle(); self.create_tray_from_handle(app_handle).await?; + // core::timer::Timer::global().add_update_tray_menu_task().await?; Ok(()) } diff --git a/src/pages/_layout.tsx b/src/pages/_layout.tsx index 52a03930..93672790 100644 --- a/src/pages/_layout.tsx +++ b/src/pages/_layout.tsx @@ -524,6 +524,7 @@ const Layout = () => { borderTopRightRadius: "0px", }} onContextMenu={(e) => { + // TODO: 禁止右键菜单 // if ( // OS === "windows" && // !["input", "textarea"].includes( diff --git a/src/providers/app-data-provider.tsx b/src/providers/app-data-provider.tsx index f0d73d60..d45ffe46 100644 --- a/src/providers/app-data-provider.tsx +++ b/src/providers/app-data-provider.tsx @@ -1,29 +1,23 @@ import { listen } from "@tauri-apps/api/event"; -import React, { - createContext, - useContext, - useEffect, - useMemo, - useRef, -} from "react"; +import React, { createContext, use, useEffect, useMemo, useRef } from "react"; import useSWR from "swr"; - -import { useClashInfo } from "@/hooks/use-clash"; -import { useVerge } from "@/hooks/use-verge"; -import { useVisibility } from "@/hooks/use-visibility"; -import { - getAppUptime, - calcuProxies, - calcuProxyProviders, - getRunningMode, - getSystemProxy, -} from "@/services/cmds"; import { getBaseConfig, getRuleProviders, getRules, } from "tauri-plugin-mihomo-api"; +import { useClashInfo } from "@/hooks/use-clash"; +import { useVerge } from "@/hooks/use-verge"; +import { useVisibility } from "@/hooks/use-visibility"; +import { + calcuProxies, + calcuProxyProviders, + getAppUptime, + getRunningMode, + getSystemProxy, +} from "@/services/cmds"; + // 连接速度计算接口 interface ConnectionSpeedData { id: string; @@ -536,7 +530,7 @@ export const AppDataProvider = ({ // 自定义Hook访问全局数据 export const useAppData = () => { - const context = useContext(AppDataContext); + const context = use(AppDataContext); if (!context) { throw new Error("useAppData必须在AppDataProvider内使用");