Files
yaak/src-web/hooks/useWindowFocus.ts
2024-07-28 13:44:50 -07:00

21 lines
488 B
TypeScript

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