Files
yaak/src-web/hooks/useWindowFocus.ts
2024-05-04 14:14:19 -07:00

21 lines
462 B
TypeScript

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