82 lines
3.3 KiB
TypeScript
82 lines
3.3 KiB
TypeScript
import {
|
|
Boxes, Clipboard, Compass, Cpu, Disc3, Globe, Keyboard,
|
|
Layers, Monitor, Palette, Puzzle, RotateCcw,
|
|
} from 'lucide-react'
|
|
import React from 'react'
|
|
import { PermissionSpec } from '../types'
|
|
|
|
export interface PluginVisualSource {
|
|
id?: string
|
|
kind?: string
|
|
system?: boolean
|
|
tier?: string
|
|
locales?: string[]
|
|
permissions?: Array<PermissionSpec | string>
|
|
}
|
|
|
|
export interface PluginVisual {
|
|
tone: string
|
|
icon: React.ReactNode
|
|
}
|
|
|
|
const ICON_SIZES = { sm: 16, md: 18, lg: 20 } as const
|
|
|
|
/**
|
|
* Single visual resolver for both installed plugins (PluginInfo) and market
|
|
* entries (MarketEntry), so a plugin keeps the same icon and colour across
|
|
* Market, Installed and first-run setup.
|
|
*/
|
|
export function resolvePluginVisual(src: PluginVisualSource, iconSize = 20): PluginVisual {
|
|
if (src.system) return { tone: 'indigo', icon: <Boxes size={iconSize} aria-hidden="true" /> }
|
|
switch (src.kind) {
|
|
case 'theme': return { tone: 'purple', icon: <Palette size={iconSize} aria-hidden="true" /> }
|
|
case 'locale': return { tone: 'sky', icon: <Globe size={iconSize} aria-hidden="true" /> }
|
|
case 'driver':
|
|
case 'runtime': return { tone: 'indigo', icon: <Monitor size={iconSize} aria-hidden="true" /> }
|
|
}
|
|
const id = (src.id ?? '').toLowerCase()
|
|
const perms = new Set((src.permissions ?? []).map((x) => (typeof x === 'string' ? x : x.name)))
|
|
if ((src.locales?.length ?? 0) > 0 || id.includes('lang') || id.includes('locale')) {
|
|
return { tone: 'sky', icon: <Globe size={iconSize} aria-hidden="true" /> }
|
|
}
|
|
if (id.includes('theme') || perms.has('ui:script')) {
|
|
return { tone: 'purple', icon: <Palette size={iconSize} aria-hidden="true" /> }
|
|
}
|
|
if (id.includes('driver') || perms.has('driver:vm') || perms.has('runtime:provider')) {
|
|
return { tone: 'indigo', icon: <Monitor size={iconSize} aria-hidden="true" /> }
|
|
}
|
|
if (id.includes('clipboard') || perms.has('host:clipboard')) {
|
|
return { tone: 'sky', icon: <Clipboard size={iconSize} aria-hidden="true" /> }
|
|
}
|
|
if (id.includes('ime') || id.includes('input') || id.includes('wheel') || perms.has('input:filter')) {
|
|
return { tone: 'rose', icon: <Keyboard size={iconSize} aria-hidden="true" /> }
|
|
}
|
|
if (id.includes('reboot')) {
|
|
return { tone: 'amber', icon: <RotateCcw size={iconSize} aria-hidden="true" /> }
|
|
}
|
|
if (id.includes('whpx') || id.includes('irq')) {
|
|
return { tone: 'emerald', icon: <Cpu size={iconSize} aria-hidden="true" /> }
|
|
}
|
|
if (id.includes('guide')) {
|
|
return { tone: 'teal', icon: <Compass size={iconSize} aria-hidden="true" /> }
|
|
}
|
|
if (id.includes('offline') || id.includes('installer') || id.includes('helper') || id.includes('image')) {
|
|
return { tone: 'teal', icon: <Disc3 size={iconSize} aria-hidden="true" /> }
|
|
}
|
|
if (src.tier === 'L3') {
|
|
return { tone: 'slate', icon: <Layers size={iconSize} aria-hidden="true" /> }
|
|
}
|
|
return { tone: 'teal', icon: <Puzzle size={iconSize} aria-hidden="true" /> }
|
|
}
|
|
|
|
/** App Store-inspired squircle icon tile shared by Market, Installed and Setup. */
|
|
export const PluginAppIcon: React.FC<{
|
|
plugin?: PluginVisualSource
|
|
kind?: string
|
|
size?: 'sm' | 'md' | 'lg'
|
|
}> = ({ plugin, kind, size = 'lg' }) => {
|
|
const vis = resolvePluginVisual(plugin ?? { kind }, ICON_SIZES[size])
|
|
const sizeCls = size === 'lg' ? '' : ` is-${size}`
|
|
return <div className={`plugin-app-icon tone-${vis.tone}${sizeCls}`}>{vis.icon}</div>
|
|
}
|