Files
buzz/desktop/src/shared/lib/useIsFullscreen.ts
Tyler b3b0704efb Fix nav chrome offset in fullscreen (#1192)
Signed-off-by: npub1t2tgm7d8f995uqvmnm8h88sg3wnpp9a5xysjf6dg3tjmgt3ltulqdp8ehr <5a968df9a7494b4e019b9ecf739e088ba61097b4312124e9a88ae5b42e3f5f3e@sprout-oss.stage.blox.sqprod.co>
Co-authored-by: npub1t2tgm7d8f995uqvmnm8h88sg3wnpp9a5xysjf6dg3tjmgt3ltulqdp8ehr <5a968df9a7494b4e019b9ecf739e088ba61097b4312124e9a88ae5b42e3f5f3e@sprout-oss.stage.blox.sqprod.co>
2026-06-23 10:58:02 -04:00

51 lines
1.2 KiB
TypeScript

import { getCurrentWindow } from "@tauri-apps/api/window";
import * as React from "react";
/**
* Returns whether the current Tauri window is in fullscreen mode.
*
* Initial value resolves from `isFullscreen()`; subsequent updates come from
* `onResized` (macOS native fullscreen, Windows F11, and Linux fullscreen all
* fire a resize on transition). Each consumer owns one listener cleaned up on
* unmount.
*/
export function useIsFullscreen(): boolean {
const [isFullscreen, setIsFullscreen] = React.useState(false);
React.useEffect(() => {
let unlisten: (() => void) | undefined;
let cancelled = false;
const appWindow = getCurrentWindow();
void appWindow.isFullscreen().then((value) => {
if (!cancelled) {
setIsFullscreen(value);
}
});
void appWindow
.onResized(() => {
void appWindow.isFullscreen().then((value) => {
if (!cancelled) {
setIsFullscreen(value);
}
});
})
.then((fn) => {
if (cancelled) {
fn();
} else {
unlisten = fn;
}
});
return () => {
cancelled = true;
unlisten?.();
};
}, []);
return isFullscreen;
}