diff --git a/src/components/layout/layout-control.tsx b/src/components/layout/layout-control.tsx index d50986807e..d9dbf419a8 100644 --- a/src/components/layout/layout-control.tsx +++ b/src/components/layout/layout-control.tsx @@ -1,3 +1,4 @@ +import { NotificationType, useNotification } from "@/hooks/use-notification"; import { save_window_size_state } from "@/services/cmds"; import { CloseRounded, @@ -8,19 +9,38 @@ import { import { Button } from "@mui/material"; import { platform, type Platform } from "@tauri-apps/api/os"; import { appWindow } from "@tauri-apps/api/window"; +import { debounce } from "lodash-es"; import { useEffect, useState } from "react"; export const LayoutControl = () => { const minWidth = 40; const [isMaximized, setIsMaximized] = useState(false); const [platfrom, setPlatform] = useState("win32"); - useEffect(() => { - appWindow.isMaximized().then((isMaximized) => { + const updateMaximized = async () => { + try { + const isMaximized = await appWindow.isMaximized(); setIsMaximized(() => isMaximized); - }); + } catch (error) { + useNotification({ + type: NotificationType.Error, + title: "Error", + body: typeof error === "string" ? error : (error as Error).message, + }); + } + }; + useEffect(() => { + // Update the maximized state + updateMaximized(); + // Get the platform platform().then((platform) => { setPlatform(() => platform); }); + // Add a resize handler to update the maximized state + const resizeHandler = debounce(updateMaximized, 1000); + window.addEventListener("resize", resizeHandler); + return () => { + window.removeEventListener("resize", resizeHandler); + }; }, []); return ( <>