import { invoke } from '@tauri-apps/api/core' import { getCurrentWindow } from '@tauri-apps/api/window' import { APP_COMMAND_MENU_SECTIONS } from '../hooks/appCommandCatalog' import { Button } from './ui/button' import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuSeparator, DropdownMenuShortcut, DropdownMenuSub, DropdownMenuSubContent, DropdownMenuSubTrigger, DropdownMenuTrigger, } from './ui/dropdown-menu' type MenuItem = | { kind: 'separator' } | { kind: 'command' commandId: string label: string menuItemId: string shortcut?: string } | { kind: 'action'; action: () => void; label: string; shortcut?: string } type MenuSection = { items: ReadonlyArray label: string } const MENU_SECTIONS: ReadonlyArray = [ ...APP_COMMAND_MENU_SECTIONS, { label: 'Window', items: [ { kind: 'action', label: 'Minimize', action: () => void getCurrentWindow().minimize().catch(() => {}) }, { kind: 'action', label: 'Maximize', action: () => void getCurrentWindow().toggleMaximize().catch(() => {}) }, { kind: 'separator' }, { kind: 'action', label: 'Close', action: () => void getCurrentWindow().close().catch(() => {}) }, ], }, ] function triggerMenuCommand(menuItemId: string): void { void invoke('trigger_menu_command', { id: menuItemId }).catch(() => {}) } function HamburgerIcon() { return ( ) } export function LinuxMenuButton() { return ( {MENU_SECTIONS.map((section) => ( {section.label} {section.items.map((item, index) => { if (item.kind === 'separator') { return } if (item.kind === 'command') { return ( triggerMenuCommand(item.menuItemId)} > {item.label} {item.shortcut && ( {item.shortcut} )} ) } return ( {item.label} {item.shortcut && {item.shortcut}} ) })} ))} ) }