mirror of
https://github.com/labring/sealos.git
synced 2026-10-29 17:25:58 +08:00
fix(desktop): do not try closing the page in app running prompt (#5870)
fix(desktop): scripts may close only the windows that were opened by them Signed-off-by: Nixieboluo <me@sagirii.me>
This commit is contained in:
@@ -38,9 +38,9 @@ import {
|
||||
} from 'lucide-react';
|
||||
import AccountCenter from './AccountCenter';
|
||||
import { useLanguageSwitcher } from '@/hooks/useLanguageSwitcher';
|
||||
import { CopyIcon } from '@sealos/ui';
|
||||
import { useGuideModalStore } from '@/stores/guideModal';
|
||||
import SecondaryLinks from '../SecondaryLinks';
|
||||
import { useAppsRunningPromptStore } from '@/stores/appsRunningPrompt';
|
||||
|
||||
const baseItemStyle = {
|
||||
minW: '36px',
|
||||
@@ -65,6 +65,7 @@ export default function Account() {
|
||||
const showDisclosure = useDisclosure();
|
||||
const [notificationAmount, setNotificationAmount] = useState(0);
|
||||
const { installedApps, openApp, openDesktopApp } = useAppStore();
|
||||
const { setBlockingPageUnload } = useAppsRunningPromptStore();
|
||||
const { colorMode, toggleColorMode } = useColorMode();
|
||||
const { openGuideModal, setInitGuide, initGuide } = useGuideModalStore();
|
||||
const { toggleLanguage, currentLanguage } = useLanguageSwitcher();
|
||||
@@ -73,6 +74,8 @@ export default function Account() {
|
||||
|
||||
const logout = (e: React.MouseEvent<HTMLElement>) => {
|
||||
e.preventDefault();
|
||||
// We clear session data before unloading the page, running apps data can not be fetched at that time.
|
||||
setBlockingPageUnload(false);
|
||||
delSession();
|
||||
queryclient.clear();
|
||||
router.replace('/signin');
|
||||
|
||||
@@ -37,20 +37,21 @@ const AppsRunningPrompt = () => {
|
||||
const { isOpen, onOpen, onClose } = useDisclosure();
|
||||
const { dontShowAgain, setDontShowAgain, blockingPageUnload } = useAppsRunningPromptStore();
|
||||
const cancelRef = React.useRef<HTMLButtonElement>(null);
|
||||
const [allowClose, setAllowClose] = useState(false);
|
||||
|
||||
const runningApps = useQuery({
|
||||
queryKey: ['getRunningApps'],
|
||||
queryFn: getRunningApps,
|
||||
enabled: false, // We fetch manually
|
||||
refetchOnWindowFocus: false
|
||||
refetchOnWindowFocus: false,
|
||||
refetchOnMount: false,
|
||||
refetchOnReconnect: false
|
||||
});
|
||||
|
||||
const checkRunningApps = useCallback(async (): Promise<boolean> => {
|
||||
try {
|
||||
const result = await runningApps.refetch();
|
||||
|
||||
if (result.isError) {
|
||||
if (!result.isSuccess) {
|
||||
// On error, assume no running apps to avoid blocking page close
|
||||
return false;
|
||||
}
|
||||
@@ -71,7 +72,7 @@ const AppsRunningPrompt = () => {
|
||||
|
||||
useEffect(() => {
|
||||
const handleBeforeUnload = (event: BeforeUnloadEvent) => {
|
||||
if (dontShowAgain || !blockingPageUnload || allowClose) {
|
||||
if (dontShowAgain || !blockingPageUnload) {
|
||||
return; // Don't prevent unload
|
||||
}
|
||||
|
||||
@@ -85,23 +86,10 @@ const AppsRunningPrompt = () => {
|
||||
if (hasRunningApps) {
|
||||
// Show dialog if there are running apps
|
||||
setTimeout(() => onOpen(), 100);
|
||||
} else {
|
||||
// No running apps, allow future closes
|
||||
setAllowClose(true);
|
||||
// Trigger close again
|
||||
setTimeout(() => {
|
||||
window.close();
|
||||
}, 100);
|
||||
}
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error('Error checking running apps:', error);
|
||||
// On error, allow future closes
|
||||
setAllowClose(true);
|
||||
// Trigger close again
|
||||
setTimeout(() => {
|
||||
window.close();
|
||||
}, 100);
|
||||
});
|
||||
};
|
||||
|
||||
@@ -110,7 +98,7 @@ const AppsRunningPrompt = () => {
|
||||
return () => {
|
||||
window.removeEventListener('beforeunload', handleBeforeUnload);
|
||||
};
|
||||
}, [dontShowAgain, allowClose, onOpen, checkRunningApps, setAllowClose, blockingPageUnload]);
|
||||
}, [dontShowAgain, onOpen, checkRunningApps, blockingPageUnload]);
|
||||
|
||||
const appsToCheck: RunningApp[] = [
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user