diff --git a/src/components/Dialog/CloseNotice.tsx b/src/components/Dialog/CloseNotice.tsx new file mode 100644 index 000000000..2e19ef298 --- /dev/null +++ b/src/components/Dialog/CloseNotice.tsx @@ -0,0 +1,39 @@ +import { useCallback } from "react"; +import { Button } from "../ui/button"; +import { Dialog, DialogClose, DialogContent, DialogFooter, DialogHeader, DialogTitle, DialogTrigger } from "../ui/dialog"; + +interface Props { + open: boolean; + onOpenChange: (open: boolean) => void; + trigger?: React.ReactNode; +} +export default function CloseNoticeDialog({open, onOpenChange, trigger}: Props) { + + const onSubmit = useCallback(() => { + window.electronAPI.closeWindow(true) + }, []) + + return +} \ No newline at end of file diff --git a/src/components/Layout/index.tsx b/src/components/Layout/index.tsx index 260b72ce5..685531bfe 100644 --- a/src/components/Layout/index.tsx +++ b/src/components/Layout/index.tsx @@ -6,10 +6,32 @@ import { useAuthStore } from "@/store/authStore"; import { useEffect, useState } from "react"; import { AnimationJson } from "@/components/AnimationJson"; import animationData from "@/assets/animation/onboarding_success.json"; +import CloseNoticeDialog from "../Dialog/CloseNotice"; +import { useChatStore } from "@/store/chatStore"; const Layout = () => { const { initState, setInitState, isFirstLaunch, setIsFirstLaunch } = useAuthStore(); const [isInstalling, setIsInstalling] = useState(false); + const [noticeOpen, setNoticeOpen] = useState(false); + const chatStore = useChatStore(); + + useEffect(() => { + const handleBeforeClose = () => { + const currentStatus = chatStore.tasks[chatStore.activeTaskId as string]?.status; + if(["pending", "running", "pause"].includes(currentStatus)) { + setNoticeOpen(true); + } else { + window.electronAPI.closeWindow(true); + } + }; + + window.ipcRenderer.on("before-close", handleBeforeClose); + + return () => { + window.ipcRenderer.removeAllListeners("before-close"); + }; + }, [chatStore.tasks, chatStore.activeTaskId]); + useEffect(() => { const checkToolInstalled = async () => { // in render process @@ -25,6 +47,7 @@ const Layout = () => { }; checkToolInstalled(); }, []); + return (