From 75cfeec6af0089a4ff9554663a436e2b1fb141f2 Mon Sep 17 00:00:00 2001 From: Wendong-Fan Date: Sat, 6 Sep 2025 06:53:15 +0800 Subject: [PATCH] enhance: Notification about closing windows PR275 --- src/components/Layout/index.tsx | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/src/components/Layout/index.tsx b/src/components/Layout/index.tsx index eb00b8541..daf160305 100644 --- a/src/components/Layout/index.tsx +++ b/src/components/Layout/index.tsx @@ -3,7 +3,7 @@ import { Outlet } from "react-router-dom"; import HistorySidebar from "../HistorySidebar"; import { InstallDependencies } from "@/components/InstallStep/InstallDependencies"; import { useAuthStore } from "@/store/authStore"; -import { useCallback, useEffect, useMemo, useState } from "react"; +import { useEffect, useState } from "react"; import { AnimationJson } from "@/components/AnimationJson"; import animationData from "@/assets/animation/onboarding_success.json"; import CloseNoticeDialog from "../Dialog/CloseNotice"; @@ -14,7 +14,23 @@ const Layout = () => { const [isInstalling, setIsInstalling] = useState(false); const [noticeOpen, setNoticeOpen] = useState(false); const chatStore = useChatStore(); - const messageStatus = useMemo(() => chatStore.tasks[chatStore.activeTaskId as string]?.status, [chatStore?.tasks[chatStore.activeTaskId as string]?.status]); + + 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 () => { @@ -30,19 +46,8 @@ const Layout = () => { } }; checkToolInstalled(); - checkClose() }, []); - - const checkClose = useCallback(() => { - window.ipcRenderer.on("before-close", () => { - if(["pending", "running", "pause"].includes(messageStatus)) { - return setNoticeOpen(true) - } - return window.electronAPI.closeWindow(true) - }) - }, []) - return (