Merge branch 'main' into fix/account-switch-task-running

This commit is contained in:
Wendong-Fan 2025-09-16 15:08:01 +08:00 committed by GitHub
commit 596d876df4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 66 additions and 0 deletions

View file

@ -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 <Dialog open={open} onOpenChange={onOpenChange}>
{trigger && <DialogTrigger asChild>{trigger}</DialogTrigger>}
<DialogContent className="sm:max-w-[600px] p-0 !bg-popup-surface gap-0 !rounded-xl border border-zinc-300 shadow-sm">
<DialogHeader className="!bg-popup-surface !rounded-t-xl p-md">
<DialogTitle className="m-0">
Close notice
</DialogTitle>
</DialogHeader>
<div className="flex flex-col gap-md bg-popup-bg p-md">
A task is currently running. Exiting will terminate it. Are you sure you want to exit?
</div>
<DialogFooter className="bg-white-100% !rounded-b-xl p-md">
<DialogClose asChild>
<Button variant="ghost" size="md">
Cancel
</Button>
</DialogClose>
<Button size="md" onClick={onSubmit} variant="primary">
Yes
</Button>
</DialogFooter>
</DialogContent>
</Dialog>
}

View file

@ -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 (
<div className="h-full flex flex-col">
@ -46,6 +69,10 @@ const Layout = () => {
)}
<Outlet />
<HistorySidebar />
<CloseNoticeDialog
onOpenChange={setNoticeOpen}
open={noticeOpen}
/>
</div>
</div>
);