From e34af4434b63003c60d5ed498ff7476702ec131c Mon Sep 17 00:00:00 2001 From: Waleed Alzarooni Date: Mon, 8 Sep 2025 16:43:11 +0100 Subject: [PATCH] fixed closing notification functionality --- src/components/Dialog/CloseNotice.tsx | 39 +++++++++++++++++++++++++++ src/components/Layout/index.tsx | 27 +++++++++++++++++++ 2 files changed, 66 insertions(+) create mode 100644 src/components/Dialog/CloseNotice.tsx 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 + {trigger && {trigger}} + + + + Close notice + + +
+ A task is currently running. Exiting will terminate it. Are you sure you want to exit? +
+ + + + + + +
+
+} \ 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 (
@@ -46,6 +69,10 @@ const Layout = () => { )} +
);