diff --git a/src/components/controller/window-controller.tsx b/src/components/controller/window-controller.tsx index 5e0fb638..07b7ab37 100644 --- a/src/components/controller/window-controller.tsx +++ b/src/components/controller/window-controller.tsx @@ -1,5 +1,5 @@ import { Close, CropSquare, FilterNone, Minimize } from "@mui/icons-material"; -import { IconButton } from "@mui/material"; +import { Box, IconButton } from "@mui/material"; import { forwardRef, useImperativeHandle } from "react"; import { useWindowControls } from "@/hooks/use-window"; @@ -40,7 +40,16 @@ export const WindowControls = forwardRef(function WindowControls(props, ref) { // 这可能是上游缺陷,保险起见跨平台以窗口的最大化翻转为准 return ( -
+ button": { + cursor: "default", + }, + }} + > {OS === "macos" && ( <> {/* macOS 风格:关闭 → 最小化 → 全屏 */} @@ -67,22 +76,26 @@ export const WindowControls = forwardRef(function WindowControls(props, ref) { {OS === "windows" && ( <> {/* Windows 风格:最小化 → 最大化 → 关闭 */} - - + + {maximized ? ( - + ) : ( - + )} - - + + )} @@ -90,25 +103,29 @@ export const WindowControls = forwardRef(function WindowControls(props, ref) { {OS === "linux" && ( <> {/* Linux 桌面常见布局(GNOME/KDE 多为:最小化 → 最大化 → 关闭) */} - - + + {maximized ? ( - + ) : ( - + )} - - + + )} -
+ ); }); diff --git a/src/hooks/use-window.tsx b/src/hooks/use-window.tsx index 47377b28..56e3a97c 100644 --- a/src/hooks/use-window.tsx +++ b/src/hooks/use-window.tsx @@ -1,4 +1,5 @@ import { getCurrentWindow } from "@tauri-apps/api/window"; +import { debounce } from "lodash-es"; import React, { createContext, useCallback, @@ -31,6 +32,20 @@ export const WindowProvider: React.FC<{ children: React.ReactNode }> = ({ const close = useCallback(() => currentWindow.close(), [currentWindow]); const minimize = useCallback(() => currentWindow.minimize(), [currentWindow]); + useEffect(() => { + const checkMaximized = debounce(async () => { + const value = await currentWindow.isMaximized(); + if (maximized !== value) { + setMaximized(value); + } + }, 100); + const unlistenResize = currentWindow.onResized(checkMaximized); + + return () => { + unlistenResize.then((fn) => fn()); + }; + }, [currentWindow, maximized]); + const toggleMaximize = useCallback(async () => { if (await currentWindow.isMaximized()) { await currentWindow.unmaximize(); diff --git a/src/pages/_layout.tsx b/src/pages/_layout.tsx index e109f0c0..321f696f 100644 --- a/src/pages/_layout.tsx +++ b/src/pages/_layout.tsx @@ -552,16 +552,15 @@ const Layout = () => { borderTopRightRadius: "0px", }} onContextMenu={(e) => { - // TODO: 禁止右键菜单 - // if ( - // OS === "windows" && - // !["input", "textarea"].includes( - // e.currentTarget.tagName.toLowerCase(), - // ) && - // !e.currentTarget.isContentEditable - // ) { - // e.preventDefault(); - // } + if ( + OS === "windows" && + !["input", "textarea"].includes( + e.currentTarget.tagName.toLowerCase(), + ) && + !e.currentTarget.isContentEditable + ) { + e.preventDefault(); + } }} sx={[ ({ palette }) => ({ bgcolor: palette.background.paper }),