securityos/components/system/Taskbar/useTaskbarContextMenu.ts

70 lines
2.1 KiB
TypeScript

import { useMenu } from "contexts/menu";
import type {
ContextMenuCapture,
MenuItem,
} from "contexts/menu/useMenuContextState";
import { useProcesses } from "contexts/process";
import { useProcessesRef } from "hooks/useProcessesRef";
import { useMemo } from "react";
import { MENU_SEPERATOR } from "utils/constants";
import { toggleFullScreen, toggleShowDesktop } from "utils/functions";
const useTaskbarContextMenu = (onStartButton = false): ContextMenuCapture => {
const { contextMenu } = useMenu();
const { minimize, open } = useProcesses();
const processesRef = useProcessesRef();
return useMemo(
() =>
contextMenu?.(() => {
const processArray = Object.entries(processesRef.current);
const allWindowsMinimized =
processArray.length > 0 &&
!processArray.some(([, { minimized }]) => !minimized);
const toggleLabel = allWindowsMinimized
? "Mostrar Janelas Abertas"
: "Mostrar o Desktop";
const menuItems: MenuItem[] = [
{
action: () => toggleShowDesktop(processesRef.current, minimize),
label: onStartButton ? "Desktop" : toggleLabel,
},
];
if (onStartButton) {
menuItems.unshift(
{
action: () => open("Terminal"),
label: "Terminal",
},
MENU_SEPERATOR,
{
action: () => open("FileExplorer"),
label: "Explorer",
},
{
action: () => open("Run"),
label: "Executar",
},
MENU_SEPERATOR
);
} else {
menuItems.unshift(
{
action: toggleFullScreen,
label: document.fullscreenElement
? "Sair da Tela Cheia"
: "Entrar na Tela Cheia",
},
MENU_SEPERATOR
);
}
return menuItems;
}),
[contextMenu, minimize, onStartButton, open, processesRef]
);
};
export default useTaskbarContextMenu;