From 0e82426ea1a82a473a51c240243842f8de55fd10 Mon Sep 17 00:00:00 2001 From: LiuTianYu Date: Wed, 24 Apr 2024 22:36:15 +0800 Subject: [PATCH] fix: #730 icon not change when the window is opened maximized (#924) Co-authored-by: tyliu9 --- src/components/layout/layout-control.tsx | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/src/components/layout/layout-control.tsx b/src/components/layout/layout-control.tsx index fe79a53a..ad72693b 100644 --- a/src/components/layout/layout-control.tsx +++ b/src/components/layout/layout-control.tsx @@ -8,18 +8,29 @@ import { PushPinOutlined, PushPinRounded, } from "@mui/icons-material"; -import { useState } from "react"; +import { useEffect, useState } from "react"; export const LayoutControl = () => { const minWidth = 40; const [isMaximized, setIsMaximized] = useState(false); const [isPined, setIsPined] = useState(false); - appWindow.onResized(() => { - appWindow.isMaximized().then((isMaximized) => { - setIsMaximized(() => isMaximized); + + useEffect(() => { + const unlistenResized = appWindow.onResized(() => { + appWindow.isMaximized().then((maximized) => { + setIsMaximized(() => maximized); + }); }); - }); + + appWindow.isMaximized().then((maximized) => { + setIsMaximized(() => maximized); + }); + + return () => { + unlistenResized.then((fn) => fn()); + }; + }, []); return (