feat(plugin): custom SVG icons, market stats, submit link, and native locale scaffold (#170)

* feat(plugin): custom SVG icons, market stats, submit link, and native locale scaffold

* chore(ci): allow spaces in PR model names and rename agent declaration to tool

* fix(plugin): validate icon.svg size and markup during static scan
This commit is contained in:
千川白浪 authored and GitHub committed 2026-12-04 22:34:12 +08:00
1 parent 4053ffb60c
commit 781f129fc1
33 files changed
+543 -72

No files matched your search

+49 -31
View File
@@ -1,15 +1,15 @@
import {
Boxes, Clipboard, Compass, Cpu, Disc3, Globe, Keyboard,
Layers, Monitor, Palette, Puzzle, RotateCcw,
Boxes, Globe, Layers, Monitor, Palette, Puzzle,
} from 'lucide-react'
import React from 'react'
import { PermissionSpec } from '../types'
import { PermissionSpec, PluginIcon } from '../types'
export interface PluginVisualSource {
id?: string
kind?: string
system?: boolean
tier?: string
icon?: PluginIcon
locales?: string[]
permissions?: Array<PermissionSpec | string>
}
@@ -21,12 +21,25 @@ export interface PluginVisual {
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 {
const PLUGIN_ICON_TONES = new Set([
'indigo', 'purple', 'sky', 'rose', 'emerald', 'amber', 'teal', 'slate',
])
function normalizeTone(tone?: string): string {
const t = (tone ?? '').trim().toLowerCase()
return PLUGIN_ICON_TONES.has(t) ? t : ''
}
function toSafeSvgMaskUrl(raw?: string): string {
const s = (raw ?? '').trim()
if (!s) return ''
const lower = s.toLowerCase()
if (!lower.startsWith('<svg') || !lower.includes('</svg>')) return ''
if (/<script\b|\bon[a-z]+\s*=|javascript:|<foreignobject\b/i.test(s)) return ''
return `url("data:image/svg+xml,${encodeURIComponent(s)}")`
}
function fallbackVisual(src: PluginVisualSource, iconSize: number): 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" /> }
@@ -34,41 +47,46 @@ export function resolvePluginVisual(src: PluginVisualSource, iconSize = 20): Plu
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')) {
if ((src.locales?.length ?? 0) > 0) {
return { tone: 'sky', icon: <Globe size={iconSize} aria-hidden="true" /> }
}
if (id.includes('theme') || perms.has('ui:script')) {
if (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')) {
if (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" /> }
}
/**
* Single visual resolver for both installed plugins (PluginInfo) and market
* entries (MarketEntry), prioritizing declared icon tone + monochrome SVG
* foreground with a kind-based fallback for legacy plugins.
*/
export function resolvePluginVisual(src: PluginVisualSource, iconSize = 20): PluginVisual {
const fb = fallbackVisual(src, iconSize)
const tone = normalizeTone(src.icon?.tone) || fb.tone
const maskUrl = toSafeSvgMaskUrl(src.icon?.svg)
if (maskUrl) {
const style: React.CSSProperties = {
width: iconSize,
height: iconSize,
WebkitMaskImage: maskUrl,
maskImage: maskUrl,
}
return {
tone,
icon: <span className="plugin-app-icon-svg" style={style} aria-hidden="true" />,
}
}
return { tone, icon: fb.icon }
}
/** App Store-inspired squircle icon tile shared by Market, Installed and Setup. */
export const PluginAppIcon: React.FC<{
plugin?: PluginVisualSource
+25 -1
View File
@@ -1,4 +1,4 @@
import { AlertTriangle, Check, Download, ShieldAlert } from 'lucide-react'
import { AlertTriangle, Check, Download, ShieldAlert, Star } from 'lucide-react'
import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react'
import '../i18n/domains/plugins.gen'
import { I18nKey, locText, t } from '../i18n'
@@ -25,6 +25,12 @@ const KIND_LABELS: Record<string, I18nKey> = {
runtime: 'pluginMarketKindRuntime',
}
function formatCompactCount(n: number): string {
if (n >= 10000) return `${(n / 1000).toFixed(0)}k`
if (n >= 1000) return `${(n / 1000).toFixed(1).replace(/\.0$/, '')}k`
return String(n)
}
interface Props {
locale: Locale
safeMode?: boolean
@@ -370,6 +376,24 @@ export const PluginMarket: React.FC<Props> = ({
<PluginTrustBadge locale={locale} trust={e.trust} publisher={e.publisher} />
<span className="market-card-dot" aria-hidden="true">·</span>
<span className="market-card-version">v{e.version}</span>
{(e.stars ?? 0) > 0 && (
<>
<span className="market-card-dot" aria-hidden="true">·</span>
<span className="market-card-stat" title={`${e.stars} stars`}>
<Star size={11} aria-hidden="true" />
{formatCompactCount(e.stars!)}
</span>
</>
)}
{(e.downloads ?? 0) > 0 && (
<>
<span className="market-card-dot" aria-hidden="true">·</span>
<span className="market-card-stat" title={`${e.downloads} downloads`}>
<Download size={11} aria-hidden="true" />
{formatCompactCount(e.downloads!)}
</span>
</>
)}
</div>
</div>
<div className="market-card-action">{action(item)}</div>
+8 -1
View File
@@ -1,5 +1,5 @@
import {
AlertTriangle, CheckCircle2, FolderOpen, PackagePlus, Palette,
AlertTriangle, CheckCircle2, ExternalLink, FolderOpen, PackagePlus, Palette,
RefreshCw, Settings2, Shield, ShieldAlert, Sparkles, Terminal, Trash2,
} from 'lucide-react'
import React, { useEffect, useMemo, useRef, useState } from 'react'
@@ -22,6 +22,7 @@ import { SchemaForm } from './SchemaForm'
const SEARCH_THRESHOLD = 12
// A manual refresh spins at least this long so the click visibly lands.
const MIN_SPIN_MS = 500
const PLUGIN_MARKET_SUBMIT_URL = 'https://github.com/reims-go/plugins#如何上架插件'
interface Props {
locale: Locale
@@ -626,6 +627,12 @@ export const PluginsPage: React.FC<Props> = ({
onClick={() => activeTab === 'market' ? setMarketRefresh((n) => n + 1) : void manualReload()}
/>
<IconButton label={tr('pluginLinkDevBtn')} icon={<FolderOpen size={16} />} onClick={linkDevDir} />
<Button
icon={<ExternalLink size={14} aria-hidden="true" />}
onClick={() => void api.OpenURL(PLUGIN_MARKET_SUBMIT_URL).catch((e) => onError(tr('failGeneric'), e))}
>
{tr('pluginSubmitBtn')}
</Button>
<Button variant="primary" disabled={scanBusy} icon={<PackagePlus size={14} aria-hidden="true" />} onClick={importLocalZip}>
{tr('pluginImportBtn')}
</Button>