import * as Ctx from '@radix-ui/react-context-menu' import { AppWindow, Camera, CopyPlus, Cpu, Download, FolderOpen, Info, Maximize2, Pause, Play, Plus, Power, Puzzle, RotateCw, Settings, Square, Trash } from 'lucide-react' import React, { useRef } from 'react' import { I18nKey, localeDir, t } from '../i18n' import { guestFamilyOf, vmFeatures } from '../lib/endpoints' import { Locale, VMAction, VMBusyAction, VMListItem } from '../types' import { hasVisibleDialog } from '../lib/dialogState' import { vmRefKey } from '../lib/vmRef' import { IconButton, StatusShape, Tip, statusKind } from '../ui/controls' import { VersionArt } from '../macos/VersionArt' import { BrandMark, HostIcon } from '../ui/themeVisuals' import { GuestArt, hasGuestArt } from './GuestIcon' export const HOST_ID = '__host__' export const INSTALLERS_ID = '__installers__' export const PLUGINS_ID = '__plugins__' export const SETTINGS_ID = '__settings__' export const ABOUT_ID = '__about__' /** Pages that are not VMs; everything else selectable in the sidebar is a VM name. */ export const PAGE_IDS: readonly string[] = [HOST_ID, INSTALLERS_ID, PLUGINS_ID, SETTINGS_ID, ABOUT_ID] interface Props { locale: Locale vms: VMListItem[] transitions: Record /** VM reference key (`vmRefKey`) → currently running action (disables conflicting context menu actions). */ busyActions?: Record selected: string hostReady: boolean /** Whether the active runtime supports VM suspend/resume (macOS VMs; other VMs use their `suspend` capability). */ canSuspend: boolean onSelect: (id: string) => void /** VM reference key → display name (its note); empty or missing shows the name. */ displayNames?: Record /** VM reference key → macOS major version for its icon; null shows the name's initial. */ macosMajors?: Record /** Double-click on a VM: its main action (start, or show its window). */ onActivate?: (name: string) => void onNew: () => void onVMContextAction?: (name: string, action: VMAction | 'settings') => void /** An installer download is running (busy dot on the Installers entry). */ downloading?: boolean /** Safe mode is active (third-party plugins skipped). */ safeMode?: boolean /** Update capsule card shown under the brand (null when nothing to show). */ updateCard?: React.ReactNode /** A newer release exists: dot on the About entry. */ updateDot?: boolean /** Declared plugin pages shown after the built-in Plugins entry. */ pluginViews?: { id: string; title: string; badge?: string; icon?: string }[] } export const Sidebar: React.FC = ({ locale, vms, transitions, busyActions = {}, selected, hostReady, canSuspend, onSelect, displayNames = {}, macosMajors = {}, onActivate, onNew, onVMContextAction, downloading, safeMode, updateCard, updateDot, pluginViews = [], }) => { const tr = (k: I18nKey) => t(locale, k) const listRef = useRef(null) const ctxOpenedByPointerRef = useRef(false) const ids = [...vms.map((v) => vmRefKey(v)), INSTALLERS_ID, PLUGINS_ID, ...pluginViews.map((view) => view.id), HOST_ID, SETTINGS_ID, ABOUT_ID] // Listbox keyboard model: ↑/↓/Home/End move selection and focus together. const onKeyDown = (e: React.KeyboardEvent) => { const idx = ids.indexOf(selected) let next = -1 if (e.key === 'ArrowDown') next = Math.min(ids.length - 1, idx + 1) else if (e.key === 'ArrowUp') next = Math.max(0, idx - 1) else if (e.key === 'Home') next = 0 else if (e.key === 'End') next = ids.length - 1 if (next < 0) return e.preventDefault() onSelect(ids[next]) listRef.current?.querySelector(`[data-id="${CSS.escape(ids[next])}"]`)?.focus() } const hasSelectedInList = ids.includes(selected) const navBtn = ( id: string, label: string, icon: React.ReactNode, badgeClass: string, stateLabel: string, kind: ReturnType | null, onDoubleClick?: () => void, dot?: boolean, vm?: { state: string; driver: string; busy: boolean; family: string }, badgeText?: string, ) => ( ) return (
) }