Browse Source

fix: #730 icon not change when the window is opened maximized (#924)

Co-authored-by: tyliu9 <tyliu9@toycloud.com>
LiuTianYu 1 year ago
parent
commit
0e82426ea1
1 changed files with 16 additions and 5 deletions
  1. 16 5
      src/components/layout/layout-control.tsx

+ 16 - 5
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 (
     <ButtonGroup