import { useMemo } from "react"; import { useMenu } from "@/contexts/menu"; import { type ContextMenuCapture, type MenuItem, } from "@/contexts/menu/useMenuContextState"; import { useWindows } from "@/contexts/windows"; import { useSession } from "@/contexts/session"; import { useViewport } from "@/contexts/viewport"; import { useWindowsRef } from "@/hooks/useWindowsRef"; import { MENU_SEPERATOR } from "@/utils/constants"; import { toggleShowDesktop } from "@/utils/functions"; const useTaskbarContextMenu = (onStartButton = false): ContextMenuCapture => { const { contextMenu } = useMenu(); const { minimize } = useWindows(); const { stackOrder } = useSession(); const windowsRef = useWindowsRef(); const { fullscreenElement, toggleFullscreen } = useViewport(); // eslint-disable-next-line @typescript-eslint/no-unused-vars const open = (..._args) => {}; // noop temp return useMemo( () => contextMenu?.(() => { const processArray = Object.entries(windowsRef.current); const allWindowsMinimized = processArray.length > 0 && !processArray.some(([, { minimized }]) => !minimized); const toggleLabel = allWindowsMinimized ? "Show open windows" : "Show the desktop"; const menuItems: MenuItem[] = [ { action: () => toggleShowDesktop(windowsRef.current, stackOrder, minimize), label: onStartButton ? "Desktop" : toggleLabel, }, ]; if (onStartButton) { menuItems.unshift( { action: () => open("Terminal"), label: "Terminal", }, MENU_SEPERATOR, { action: () => open("FileExplorer"), label: "File Explorer", }, { action: () => open("Run"), label: "Run", }, MENU_SEPERATOR ); } else { menuItems.unshift( { action: () => toggleFullscreen(), label: fullscreenElement === document.documentElement ? "Exit full screen" : "Enter full screen", }, MENU_SEPERATOR ); } return menuItems; }), [ contextMenu, fullscreenElement, minimize, onStartButton, open, windowsRef, stackOrder, toggleFullscreen, ] ); }; export default useTaskbarContextMenu;