From 892cf892f09e4e0e4b69ce843e0f1db0c73cce05 Mon Sep 17 00:00:00 2001 From: coso Date: Fri, 16 Jan 2026 16:35:49 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E7=A7=BB=E9=99=A4=20Flow=20Monitor=20?= =?UTF-8?q?=E7=AA=97=E5=8F=A3=E5=B0=BA=E5=AF=B8=E9=80=89=E9=A1=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 从 WindowSize 移除 flow_monitor()、ultra_wide()、four_k() 方法 - 从 WindowSizeOption::all_options() 移除 Flow Monitor 等选项,保留 4 个选项 - 移除 resize_for_flow_monitor 和 toggle_window_size 命令 - 更新 runner.rs 移除已删除命令的注册 - 更新 window.ts 移除相关 API 方法 - 更新 constants.ts 移除 flow_monitor 窗口尺寸偏好 - FlowMonitorPage 已在之前移除窗口尺寸菜单 Closes #126 --- src-tauri/src/app/runner.rs | 2 - src-tauri/src/commands/window_cmd.rs | 106 +------------------- src/components/onboarding/constants.ts | 7 -- src/lib/api/window.ts | 36 ------- src/pages/FlowMonitorPage.tsx | 130 +------------------------ 5 files changed, 3 insertions(+), 278 deletions(-) diff --git a/src-tauri/src/app/runner.rs b/src-tauri/src/app/runner.rs index 7ae04e998..0135f495c 100644 --- a/src-tauri/src/app/runner.rs +++ b/src-tauri/src/app/runner.rs @@ -989,9 +989,7 @@ pub fn run() { // Window control commands commands::window_cmd::get_window_size, commands::window_cmd::set_window_size, - commands::window_cmd::resize_for_flow_monitor, commands::window_cmd::restore_window_size, - commands::window_cmd::toggle_window_size, commands::window_cmd::center_window, commands::window_cmd::get_window_size_options, commands::window_cmd::set_window_size_by_option, diff --git a/src-tauri/src/commands/window_cmd.rs b/src-tauri/src/commands/window_cmd.rs index 54e69b68c..9690ecfc1 100644 --- a/src-tauri/src/commands/window_cmd.rs +++ b/src-tauri/src/commands/window_cmd.rs @@ -22,14 +22,6 @@ impl WindowSize { } } - /// Flow Monitor 优化大小(更宽更高,适合数据展示) - pub fn flow_monitor() -> Self { - Self { - width: 1600, - height: 1000, - } - } - /// 紧凑模式 pub fn compact() -> Self { Self { @@ -53,22 +45,6 @@ impl WindowSize { height: 1440, } } - - /// 4K 模式 - pub fn ultra_wide() -> Self { - Self { - width: 3440, - height: 1440, - } - } - - /// 4K 标准模式 - pub fn four_k() -> Self { - Self { - width: 3840, - height: 2160, - } - } } /// 窗口大小选项 @@ -96,12 +72,6 @@ impl WindowSizeOption { description: "1200×800 - 日常使用".to_string(), size: WindowSize::default(), }, - Self { - id: "flow_monitor".to_string(), - name: "Flow Monitor".to_string(), - description: "1600×1000 - 数据展示优化".to_string(), - size: WindowSize::flow_monitor(), - }, Self { id: "large".to_string(), name: "大屏模式".to_string(), @@ -114,18 +84,6 @@ impl WindowSizeOption { description: "2560×1440 - 超大屏幕".to_string(), size: WindowSize::extra_large(), }, - Self { - id: "ultra_wide".to_string(), - name: "超宽屏模式".to_string(), - description: "3440×1440 - 超宽屏显示".to_string(), - size: WindowSize::ultra_wide(), - }, - Self { - id: "four_k".to_string(), - name: "4K 模式".to_string(), - description: "3840×2160 - 4K 显示器".to_string(), - size: WindowSize::four_k(), - }, ] } } @@ -256,26 +214,6 @@ pub async fn set_window_size(app: AppHandle, size: WindowSize) -> Result<(), Str Ok(()) } -/// 切换到 Flow Monitor 优化大小 -/// -/// # Arguments -/// * `app` - Tauri AppHandle -/// -/// # Returns -/// * `Ok(WindowSize)` - 成功时返回之前的窗口大小 -/// * `Err(String)` - 失败时返回错误消息 -#[tauri::command] -pub async fn resize_for_flow_monitor(app: AppHandle) -> Result { - // 先获取当前大小,用于恢复 - let current_size = get_window_size(app.clone()).await?; - - // 设置为 Flow Monitor 优化大小 - let flow_monitor_size = WindowSize::flow_monitor(); - set_window_size(app, flow_monitor_size).await?; - - Ok(current_size) -} - /// 恢复窗口到指定大小 /// /// # Arguments @@ -290,36 +228,6 @@ pub async fn restore_window_size(app: AppHandle, size: WindowSize) -> Result<(), set_window_size(app, size).await } -/// 切换窗口大小(在默认大小和 Flow Monitor 大小之间切换) -/// -/// # Arguments -/// * `app` - Tauri AppHandle -/// -/// # Returns -/// * `Ok(bool)` - 成功时返回是否切换到了 Flow Monitor 大小 -/// * `Err(String)` - 失败时返回错误消息 -#[tauri::command] -pub async fn toggle_window_size(app: AppHandle) -> Result { - let current_size = get_window_size(app.clone()).await?; - let flow_monitor_size = WindowSize::flow_monitor(); - let default_size = WindowSize::default(); - - // 判断当前是否接近 Flow Monitor 大小(允许一些误差) - let is_flow_monitor_size = (current_size.width as i32 - flow_monitor_size.width as i32).abs() - < 50 - && (current_size.height as i32 - flow_monitor_size.height as i32).abs() < 50; - - if is_flow_monitor_size { - // 当前是 Flow Monitor 大小,切换到默认大小 - set_window_size(app, default_size).await?; - Ok(false) - } else { - // 当前不是 Flow Monitor 大小,切换到 Flow Monitor 大小 - set_window_size(app, flow_monitor_size).await?; - Ok(true) - } -} - /// 居中窗口 /// /// # Arguments @@ -349,10 +257,6 @@ mod tests { assert_eq!(default.width, 1200); assert_eq!(default.height, 800); - let flow_monitor = WindowSize::flow_monitor(); - assert_eq!(flow_monitor.width, 1600); - assert_eq!(flow_monitor.height, 1000); - let compact = WindowSize::compact(); assert_eq!(compact.width, 1000); assert_eq!(compact.height, 700); @@ -364,20 +268,12 @@ mod tests { let extra_large = WindowSize::extra_large(); assert_eq!(extra_large.width, 2560); assert_eq!(extra_large.height, 1440); - - let ultra_wide = WindowSize::ultra_wide(); - assert_eq!(ultra_wide.width, 3440); - assert_eq!(ultra_wide.height, 1440); - - let four_k = WindowSize::four_k(); - assert_eq!(four_k.width, 3840); - assert_eq!(four_k.height, 2160); } #[test] fn test_window_size_options() { let options = WindowSizeOption::all_options(); - assert_eq!(options.len(), 7); + assert_eq!(options.len(), 4); // 验证每个选项都有有效的 ID 和名称 for option in &options { diff --git a/src/components/onboarding/constants.ts b/src/components/onboarding/constants.ts index 60848e5fb..7db549a52 100644 --- a/src/components/onboarding/constants.ts +++ b/src/components/onboarding/constants.ts @@ -122,7 +122,6 @@ export const STORAGE_KEYS = { export type WindowSizePreference = | "compact" | "default" - | "flow_monitor" | "large" | "fullscreen"; @@ -152,12 +151,6 @@ export const windowSizeOptions: WindowSizeOptionConfig[] = [ description: "1200×800 - 日常使用", icon: Monitor, }, - { - id: "flow_monitor", - name: "Flow Monitor", - description: "1600×1000 - 数据展示优化", - icon: Activity, - }, { id: "large", name: "大屏模式", diff --git a/src/lib/api/window.ts b/src/lib/api/window.ts index 7cf03af34..35724ebd3 100644 --- a/src/lib/api/window.ts +++ b/src/lib/api/window.ts @@ -83,33 +83,6 @@ export const windowApi = { return safeInvoke("is_fullscreen"); }, - /** - * 切换到 Flow Monitor 优化大小 - * - * @returns 之前的窗口大小(用于恢复) - */ - async resizeForFlowMonitor(): Promise { - return safeInvoke("resize_for_flow_monitor"); - }, - - /** - * 恢复窗口到指定大小 - * - * @param size - 要恢复的窗口大小 - */ - async restoreWindowSize(size: WindowSize): Promise { - return safeInvoke("restore_window_size", { size }); - }, - - /** - * 切换窗口大小(在默认大小和 Flow Monitor 大小之间切换) - * - * @returns 是否切换到了 Flow Monitor 大小 - */ - async toggleWindowSize(): Promise { - return safeInvoke("toggle_window_size"); - }, - /** * 居中窗口 */ @@ -128,20 +101,11 @@ export const WindowSizes = { /** 默认窗口大小 */ default: { width: 1200, height: 800 } as WindowSize, - /** Flow Monitor 优化大小 */ - flowMonitor: { width: 1600, height: 1000 } as WindowSize, - /** 大屏模式 */ large: { width: 1920, height: 1200 } as WindowSize, /** 超大屏模式 */ extraLarge: { width: 2560, height: 1440 } as WindowSize, - - /** 超宽屏模式 */ - ultraWide: { width: 3440, height: 1440 } as WindowSize, - - /** 4K 模式 */ - fourK: { width: 3840, height: 2160 } as WindowSize, }; export default windowApi; diff --git a/src/pages/FlowMonitorPage.tsx b/src/pages/FlowMonitorPage.tsx index 6acb2d0e4..8be034494 100644 --- a/src/pages/FlowMonitorPage.tsx +++ b/src/pages/FlowMonitorPage.tsx @@ -1,14 +1,5 @@ -import { useState, useCallback, useEffect } from "react"; -import { - Activity, - Download, - BarChart3, - List, - ChevronDown, - Monitor, - Maximize, - Trash2, -} from "lucide-react"; +import { useState, useCallback } from "react"; +import { Activity, Download, BarChart3, List, Trash2 } from "lucide-react"; import { FlowList, FlowFilters, @@ -22,7 +13,6 @@ import { type FlowFilter, type ExportFormat, } from "@/lib/api/flowMonitor"; -import { windowApi, type WindowSizeOption } from "@/lib/api/window"; import { cn } from "@/lib/utils"; type ViewMode = "list" | "stats"; @@ -47,48 +37,6 @@ export function FlowMonitorPage() { // 刷新计数器(用于触发子组件刷新) const [refreshKey, setRefreshKey] = useState(0); - // 窗口大小状态 - const [windowSizeOptions, setWindowSizeOptions] = useState< - WindowSizeOption[] - >([]); - const [isFullscreen, setIsFullscreen] = useState(false); - const [showWindowMenu, setShowWindowMenu] = useState(false); - - // 初始化窗口大小选项 - useEffect(() => { - const loadWindowOptions = async () => { - try { - const options = await windowApi.getWindowSizeOptions(); - setWindowSizeOptions(options); - - // 检查是否处于全屏模式 - const fullscreen = await windowApi.isFullscreen(); - setIsFullscreen(fullscreen); - } catch (error) { - console.error("加载窗口选项失败:", error); - } - }; - - loadWindowOptions(); - }, []); - - // 点击外部关闭窗口菜单 - useEffect(() => { - const handleClickOutside = (event: MouseEvent) => { - if (showWindowMenu) { - const target = event.target as Element; - if (!target.closest(".window-menu-container")) { - setShowWindowMenu(false); - } - } - }; - - document.addEventListener("mousedown", handleClickOutside); - return () => { - document.removeEventListener("mousedown", handleClickOutside); - }; - }, [showWindowMenu]); - // 处理 Flow 选择 const handleFlowSelect = useCallback((flow: LLMFlow) => { setSelectedFlow(flow); @@ -125,27 +73,6 @@ export function FlowMonitorPage() { setRefreshKey((prev) => prev + 1); }, []); - // 设置窗口大小 - const handleSetWindowSize = useCallback(async (optionId: string) => { - try { - await windowApi.setWindowSizeByOption(optionId); - setShowWindowMenu(false); - } catch (error) { - console.error("设置窗口大小失败:", error); - } - }, []); - - // 切换全屏模式 - const handleToggleFullscreen = useCallback(async () => { - try { - const newFullscreenState = await windowApi.toggleFullscreen(); - setIsFullscreen(newFullscreenState); - setShowWindowMenu(false); - } catch (error) { - console.error("切换全屏模式失败:", error); - } - }, []); - return (
{/* 页面头部 */} @@ -188,59 +115,6 @@ export function FlowMonitorPage() {
- {/* 窗口大小调整下拉菜单 */} -
- - - {showWindowMenu && ( -
- {/* 窗口大小选项 */} -
- 窗口大小 -
- {windowSizeOptions.map((option) => ( - - ))} - - {/* 分隔线 */} -
- - {/* 全屏选项 */} - -
- )} -
- {/* 导出按钮 */}