2025-03-24 09:17:09 +08:00
|
|
|
import { useEffect } from "react";
|
2025-03-17 16:24:18 +08:00
|
|
|
|
2025-03-24 09:17:09 +08:00
|
|
|
import { useAppStore } from "@/stores/appStore";
|
|
|
|
|
import platformAdapter from "@/utils/platformAdapter";
|
2025-03-17 16:24:18 +08:00
|
|
|
|
|
|
|
|
export function useWindowEvents() {
|
|
|
|
|
const isPinned = useAppStore((state) => state.isPinned);
|
2025-03-24 09:17:09 +08:00
|
|
|
const visible = useAppStore((state) => state.visible);
|
2025-03-17 16:24:18 +08:00
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
const handleBlur = async () => {
|
|
|
|
|
console.log("Window blurred");
|
2025-03-24 09:17:09 +08:00
|
|
|
if (isPinned || visible) {
|
2025-03-17 16:24:18 +08:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
await platformAdapter.hideWindow();
|
|
|
|
|
console.log("Hide Coco");
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
window.addEventListener("blur", handleBlur);
|
|
|
|
|
|
|
|
|
|
// Clean up event listeners on component unmount
|
|
|
|
|
return () => {
|
|
|
|
|
window.removeEventListener("blur", handleBlur);
|
|
|
|
|
};
|
2025-03-24 09:17:09 +08:00
|
|
|
}, [isPinned, visible]);
|
|
|
|
|
}
|