Files
yaak/src-web/hooks/useWindowFocus.ts
Gregory Schier 0f86c3a731 Fix bundle parts
2023-03-29 14:00:34 -07:00

21 lines
451 B
TypeScript

import { appWindow } from '@tauri-apps/api/window';
import { useEffect, useState } from 'react';
export function useWindowFocus() {
const [visible, setVisible] = useState(true);
useEffect(() => {
let unsub: undefined | (() => void) = undefined;
appWindow
.onFocusChanged((e) => {
setVisible(e.payload);
})
.then((fn) => {
unsub = fn;
});
return () => unsub?.();
}, []);
return visible;
}