fix: incorrect maximize status on custom windows controller (#5033)
* fix: windows controller * chore: update style * chore: update style
This commit is contained in:
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user