mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-01-15 08:13:27 +01:00
21 lines
488 B
TypeScript
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;
|
|
}
|