Skip to content

Commit

Permalink
fix: minimize icon is wrong while resize window (#394)
Browse files Browse the repository at this point in the history
* fix: minimize icon is wrong while resize window

* fix: use lodash-es instead
  • Loading branch information
greenhat616 authored Feb 7, 2024
1 parent 7cb2b5c commit 3517d87
Showing 1 changed file with 23 additions and 3 deletions.
26 changes: 23 additions & 3 deletions src/components/layout/layout-control.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { NotificationType, useNotification } from "@/hooks/use-notification";
import { save_window_size_state } from "@/services/cmds";
import {
CloseRounded,
Expand All @@ -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<Platform>("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 (
<>
Expand Down

0 comments on commit 3517d87

Please sign in to comment.