import { Show, type JSX } from "solid-js" import { DropdownMenu } from "@opencode-ai/ui/dropdown-menu" import { Icon } from "@opencode-ai/ui/icon" import { IconButton } from "@opencode-ai/ui/icon-button" import { IconButtonV2 } from "@opencode-ai/ui/v2/icon-button-v2" import { Icon as IconV2 } from "@opencode-ai/ui/v2/icon" import { useCommand } from "@/context/command" import { DESKTOP_MENU, desktopMenuVisible, type DesktopMenuAction, type DesktopMenuEntry } from "@/desktop-menu" import { usePlatform } from "@/context/platform" export function WindowsAppMenu(props: { command: ReturnType platform: ReturnType variant?: "legacy" | "v2" }) { let lastFocused: HTMLElement | undefined const rememberFocus = () => { const active = document.activeElement lastFocused = active instanceof HTMLElement ? active : undefined } const commandDisabled = (id: string) => { const option = props.command.options.find((option) => option.id === id) if (!option) return true return option.disabled ?? false } const runCommand = (id: string) => { if (commandDisabled(id)) return props.command.trigger(id) } const runAction = (action: DesktopMenuAction) => { if (action.startsWith("edit.") && lastFocused?.isConnected) lastFocused.focus({ preventScroll: true }) void props.platform.runDesktopMenuAction?.(action) } const runEntry = (entry: DesktopMenuEntry) => { if (entry.type === "separator") return if (entry.command) { runCommand(entry.command) return } if (entry.action) { runAction(entry.action) return } if (entry.href) props.platform.openExternal(entry.href) } return ( {props.variant === "v2" ? (
} aria-label="OpenCode menu" onPointerDown={rememberFocus} onKeyDown={rememberFocus} />
) : ( )} OpenCode {DESKTOP_MENU.filter((menu) => desktopMenuVisible(menu, "windows")).map((menu) => ( {menu.items ?.filter((entry) => desktopMenuVisible(entry, "windows")) .map((entry) => entry.type === "separator" ? ( ) : ( runEntry(entry)} /> ), )} ))}
) } function DesktopMenuSubmenu(props: { label: string; children: JSX.Element }) { return ( {props.label} {props.children} ) } function DesktopMenuItem(props: { label: string; keybind?: string; disabled?: boolean; onSelect: () => void }) { return ( {props.label} {props.keybind} ) }