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:
33 files changed
+543
-72
No files matched your search
@@ -4,9 +4,11 @@
|
||||
- 实现归属仓库与关联的跨仓提交或运行时版本(纯本仓改动可填无)
|
||||
- 旧版或缺失运行时下的兼容与降级表现(不涉及运行时可填不适用)
|
||||
|
||||
## 模型与 Agent 申报
|
||||
## 模型与编程工具申报
|
||||
|
||||
<!-- 请逐行填写参与代码编写的实际模型和 Agent。模型格式为 model: 提供方/模型名称,Agent 格式为 agent: 名称。 -->
|
||||
<!-- 请逐行填写参与代码编写的实际模型与编程工具,不要放在代码块或 HTML 注释内。
|
||||
模型格式:model: 提供方/模型名称(例如 model: deepseek/deepseek-R1 或 model: google/Gemini 4 Neon)
|
||||
编程工具格式:tool: 名称(例如 tool: Cursor、tool: Claude Code、tool: WorkBuddy、tool: 豆包;兼容旧的 agent: 写法) -->
|
||||
|
||||
## 验证记录
|
||||
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
import { readFile } from "node:fs/promises";
|
||||
import { pathToFileURL } from "node:url";
|
||||
|
||||
const MODEL_LINE_RE = /^ {0,3}model:[ \t]+[\p{L}\p{N}][\p{L}\p{N}_.+() -]*\/[\p{L}\p{N}][\p{L}\p{N}_.+() -]*$/u;
|
||||
const TOOL_LINE_RE = /^ {0,3}(?:tool|agent):[ \t]+[\p{L}\p{N}][\p{L}\p{N}_.+() /-]*$/u;
|
||||
|
||||
export function missingDeclarations(body) {
|
||||
const missing = new Set(["model", "agent"]);
|
||||
const missing = new Set(["model", "tool"]);
|
||||
if (typeof body !== "string") return [...missing];
|
||||
let fence = null;
|
||||
for (const line of body.replace(/<!--[^]*?(?:-->|$)/g, "").split(/\r?\n/)) {
|
||||
@@ -11,10 +14,13 @@ export function missingDeclarations(body) {
|
||||
if (delimiter && delimiter[1][0] === fence[0] && delimiter[1].length >= fence.length && !delimiter[2].trim()) fence = null;
|
||||
} else if (delimiter) {
|
||||
fence = delimiter[1];
|
||||
} else if (/^ {0,3}model:[ \t]+[\p{L}\p{N}_.-]+\/[\p{L}\p{N}_.-]+[ \t]*$/u.test(line)) {
|
||||
missing.delete("model");
|
||||
} else if (/^ {0,3}agent:[ \t]+[\p{L}\p{N}][\p{L}\p{N}_.+() /-]*$/u.test(line.trimEnd())) {
|
||||
missing.delete("agent");
|
||||
} else {
|
||||
const trimmed = line.trimEnd();
|
||||
if (MODEL_LINE_RE.test(trimmed)) {
|
||||
missing.delete("model");
|
||||
} else if (TOOL_LINE_RE.test(trimmed)) {
|
||||
missing.delete("tool");
|
||||
}
|
||||
}
|
||||
if (missing.size === 0) break;
|
||||
}
|
||||
@@ -52,7 +58,7 @@ if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href)
|
||||
token: process.env.GITHUB_TOKEN,
|
||||
});
|
||||
if (result.status === "closed") {
|
||||
console.error(`::error::PR closed because its description is missing ${result.missing.join(" and ")}. Declare the actual model and agent used (format examples: model: deepseek/deepseek-R1 and agent: WorkBuddy).`);
|
||||
console.error(`::error::PR closed because its description is missing ${result.missing.join(" and ")}. Declare the actual model and coding tool used (format examples: model: deepseek/deepseek-R1 and tool: Cursor).`);
|
||||
process.exitCode = 1;
|
||||
}
|
||||
}
|
||||
@@ -6,23 +6,29 @@ const declaration = "model: deepseek/deepseek-R1";
|
||||
const opened = { action: "opened", pull_request: { number: 42, base: { ref: "main" } } };
|
||||
const options = { apiUrl: "https://api.example.invalid", repository: "owner/repo", token: "test" };
|
||||
|
||||
test("requires visible model and agent declarations", () => {
|
||||
for (const agent of ["WorkBuddy", "豆包", "OpenAI Codex"]) {
|
||||
assert.deepEqual(missingDeclarations(`${declaration}\r\nagent: ${agent}`), []);
|
||||
test("requires visible model and coding tool declarations", () => {
|
||||
for (const model of ["deepseek/deepseek-R1", "google/Gemini 4 Neon", "anthropic/Claude 4.5 Sonnet"]) {
|
||||
for (const tool of ["tool: Cursor", "tool: WorkBuddy", "tool: 豆包", "tool: OpenAI Codex", "agent: WorkBuddy"]) {
|
||||
assert.deepEqual(missingDeclarations(`model: ${model}\r\n${tool}`), []);
|
||||
}
|
||||
}
|
||||
assert.deepEqual(missingDeclarations(declaration), ["agent"]);
|
||||
assert.deepEqual(missingDeclarations("agent: 豆包"), ["model"]);
|
||||
assert.deepEqual(missingDeclarations(`${declaration}\nagent: `), ["agent"]);
|
||||
assert.deepEqual(missingDeclarations(`${declaration}\n<!-- agent: WorkBuddy -->`), ["agent"]);
|
||||
assert.deepEqual(missingDeclarations("```\n" + declaration + "\nagent: 豆包\n```"), ["model", "agent"]);
|
||||
assert.deepEqual(missingDeclarations(null), ["model", "agent"]);
|
||||
assert.deepEqual(missingDeclarations(declaration), ["tool"]);
|
||||
assert.deepEqual(missingDeclarations("tool: 豆包"), ["model"]);
|
||||
assert.deepEqual(missingDeclarations("model: google/\ntool: Cursor"), ["model"]);
|
||||
assert.deepEqual(missingDeclarations("model: /gemini\ntool: Cursor"), ["model"]);
|
||||
assert.deepEqual(missingDeclarations("model: gemini\ntool: Cursor"), ["model"]);
|
||||
assert.deepEqual(missingDeclarations(`${declaration}\ntool: `), ["tool"]);
|
||||
assert.deepEqual(missingDeclarations(`${declaration}\n<!-- tool: WorkBuddy -->`), ["tool"]);
|
||||
assert.deepEqual(missingDeclarations("```\n" + declaration + "\ntool: 豆包\n```"), ["model", "tool"]);
|
||||
assert.deepEqual(missingDeclarations(null), ["model", "tool"]);
|
||||
});
|
||||
|
||||
test("closes a new PR when either declaration is missing from its current description", async () => {
|
||||
const cases = [
|
||||
["", ["model", "agent"]],
|
||||
[declaration, ["agent"]],
|
||||
["agent: 豆包", ["model"]],
|
||||
["", ["model", "tool"]],
|
||||
[declaration, ["tool"]],
|
||||
["tool: 豆包", ["model"]],
|
||||
[`${declaration}\ntool: WorkBuddy`, []],
|
||||
[`${declaration}\nagent: WorkBuddy`, []],
|
||||
];
|
||||
for (const [body, missing] of cases) {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
name: PR Model and Agent Declaration
|
||||
name: PR Model and Coding Tool Declaration
|
||||
|
||||
on:
|
||||
pull_request_target:
|
||||
@@ -21,7 +21,7 @@ jobs:
|
||||
persist-credentials: false
|
||||
sparse-checkout-cone-mode: false
|
||||
sparse-checkout: /.github/scripts/pr-model.mjs
|
||||
- name: Check the model and agent declarations
|
||||
- name: Check the model and coding tool declarations
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ github.token }}
|
||||
run: node .github/scripts/pr-model.mjs
|
||||
@@ -40,11 +40,11 @@ Reims-Go 发布的便携运行时基于团队独立维护的 `reims-go/reims-vgp
|
||||
7. 捕获异常后必须执行上报错误、记录诊断告警或回退状态等明确处理,前端测试会自动拦截空异常捕获块。
|
||||
8. `docs/` 只存放当前生效且删掉会影响编码的文档,采用主谓清晰的简单句说明现状,不写本机路径、排期历史、内部变量函数名或「粗体标题加冒号」的口号句式。
|
||||
|
||||
## PR 模型与 Agent 申报
|
||||
## PR 模型与编程工具申报
|
||||
|
||||
提交新 PR 时,请在描述中逐行如实申报参与代码编写的模型和 Agent。模型使用 `model: 提供方/模型名称`,例如 `model: deepseek/deepseek-R1`。Agent 使用 `agent: 名称`,例如 `agent: WorkBuddy` 或 `agent: 豆包`。请填写实际使用的名称。
|
||||
提交新 PR 时,请在描述正文(不要放在代码块或 HTML 注释内)逐行如实申报参与代码编写的模型和编程工具。模型使用 `model: 提供方/模型名称`,例如 `model: deepseek/deepseek-R1` 或 `model: google/Gemini 4 Neon`。编程工具使用 `tool: 名称`,例如 `tool: Cursor`、`tool: Claude Code`、`tool: WorkBuddy` 或 `tool: 豆包`(校验脚本同时兼容旧的 `agent:` 写法)。请填写实际使用的名称。
|
||||
|
||||
缺少模型或 Agent 申报的 PR 直接关闭。纯人工编写的提交不予合并。此规则仅适用于生效后新建的 PR,已创建的 PR 继续按原规则处理。
|
||||
缺少模型或编程工具申报的 PR 直接关闭。纯人工编写的提交不予合并。此规则仅适用于生效后新建的 PR,已创建的 PR 继续按原规则处理。
|
||||
|
||||
## 版本变更与开源合规
|
||||
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"group": "improvements",
|
||||
"order": 0,
|
||||
"authors": ["Nwflower"],
|
||||
"zh": "插件支持在清单中声明颜色令牌与 SVG 前景图标并迁移全部内置插件,插件页新增「上架插件」入口,市场卡片展示 GitHub Star 数与下载量,语言包脚手架默认仅生成目标语言标题与精简描述。",
|
||||
"en": "Support custom icon tone tokens and monochrome SVG foregrounds in plugin manifests (migrating all built-in plugins), add a Submit plugin button to the Plugins page, display GitHub star and download counts on market cards, and scaffold language packs with concise native-locale metadata."
|
||||
}
|
||||
@@ -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
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -350,10 +350,17 @@ export function joinNotices(locale: Locale, items: string[]): string {
|
||||
|
||||
export function locText(lt: LocalizedText | undefined, locale: Locale, fallback = ''): string {
|
||||
if (!lt) return fallback
|
||||
const firstExtra = () => {
|
||||
if (!lt.extra) return ''
|
||||
for (const k of Object.keys(lt.extra).sort()) {
|
||||
if (lt.extra[k]) return lt.extra[k]
|
||||
}
|
||||
return ''
|
||||
}
|
||||
const chain = buildFallbackChain(locale)
|
||||
for (const step of chain) {
|
||||
if (step === 'en-XA') {
|
||||
const base = lt['en-US'] || lt['zh-CN'] || fallback
|
||||
const base = lt['en-US'] || lt['zh-CN'] || firstExtra() || fallback
|
||||
return base ? pseudoLocalizeICU(base) : fallback
|
||||
}
|
||||
if (step === 'zh-CN' && lt['zh-CN']) return lt['zh-CN']
|
||||
@@ -361,7 +368,7 @@ export function locText(lt: LocalizedText | undefined, locale: Locale, fallback
|
||||
const hit = lt.extra?.[step]
|
||||
if (hit) return hit
|
||||
}
|
||||
return lt['en-US'] || lt['zh-CN'] || fallback
|
||||
return lt['en-US'] || lt['zh-CN'] || firstExtra() || fallback
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -108,6 +108,7 @@ export const pluginsZh: Record<string, string> = {
|
||||
"pluginStateDegraded": "已降级",
|
||||
"pluginStateFailed": "故障",
|
||||
"pluginStatePending": "等待依赖",
|
||||
"pluginSubmitBtn": "上架插件",
|
||||
"pluginSurfaceSeed": "画布种子色(可选)",
|
||||
"pluginTabInstalled": "已安装",
|
||||
"pluginTabMarket": "市场",
|
||||
@@ -230,6 +231,7 @@ export const pluginsEn: Record<string, string> = {
|
||||
"pluginStateDegraded": "Degraded",
|
||||
"pluginStateFailed": "Failed",
|
||||
"pluginStatePending": "Pending",
|
||||
"pluginSubmitBtn": "Submit plugin",
|
||||
"pluginSurfaceSeed": "Surface seed (optional)",
|
||||
"pluginTabInstalled": "Installed",
|
||||
"pluginTabMarket": "Market",
|
||||
|
||||
@@ -844,6 +844,7 @@ export type I18nKey =
|
||||
| "pluginStateDegraded"
|
||||
| "pluginStateFailed"
|
||||
| "pluginStatePending"
|
||||
| "pluginSubmitBtn"
|
||||
| "pluginSurfaceSeed"
|
||||
| "pluginTabInstalled"
|
||||
| "pluginTabMarket"
|
||||
|
||||
@@ -1791,6 +1791,12 @@ button.status-issue + .status-metric { margin-left: 6px; }
|
||||
}
|
||||
.plugin-app-icon.is-md { width: 34px; height: 34px; border-radius: 9px; }
|
||||
.plugin-app-icon.is-sm { width: 30px; height: 30px; border-radius: 8px; }
|
||||
.plugin-app-icon-svg {
|
||||
display: inline-block; flex-shrink: 0; background-color: currentColor;
|
||||
-webkit-mask-repeat: no-repeat; mask-repeat: no-repeat;
|
||||
-webkit-mask-position: center; mask-position: center;
|
||||
-webkit-mask-size: contain; mask-size: contain;
|
||||
}
|
||||
.plugin-app-icon.tone-indigo { background: linear-gradient(145deg, #6e7cf0 0%, #4d5be0 100%); }
|
||||
.plugin-app-icon.tone-purple { background: linear-gradient(145deg, #bf5af2 0%, #8944ab 100%); }
|
||||
.plugin-app-icon.tone-sky { background: linear-gradient(145deg, #32a0ff 0%, #007aff 100%); }
|
||||
@@ -1856,6 +1862,10 @@ button.status-issue + .status-metric { margin-left: 6px; }
|
||||
}
|
||||
.market-card-dot { flex-shrink: 0; }
|
||||
.market-card-version { flex-shrink: 0; font-variant-numeric: tabular-nums; }
|
||||
.market-card-stat {
|
||||
display: inline-flex; align-items: center; gap: 3px; flex-shrink: 0;
|
||||
font-variant-numeric: tabular-nums;
|
||||
}
|
||||
.market-card-action { flex-shrink: 0; }
|
||||
.market-card-action .btn.market-btn { height: 28px; padding: 0 12px; font-size: var(--fs-12); }
|
||||
.market-card-desc {
|
||||
|
||||
@@ -150,6 +150,7 @@ export type LocalizedText = plugin.LocalizedText
|
||||
export type PermissionSpec = plugin.PermissionSpec
|
||||
export type SettingProperty = plugin.SettingProperty
|
||||
export type SettingsSchema = plugin.SettingsSchema
|
||||
export type PluginIcon = plugin.PluginIcon
|
||||
export type PluginInfo = plugin.PluginInfo
|
||||
export type ScanReport = plugin.ScanReport
|
||||
export type MarketCatalogItem = plugin.MarketCatalogItem
|
||||
|
||||
@@ -2082,6 +2082,7 @@ export namespace plugin {
|
||||
trust: string;
|
||||
kind?: string;
|
||||
tier?: string;
|
||||
icon?: PluginIcon;
|
||||
homepage?: string;
|
||||
readme_url?: string;
|
||||
engines: Engines;
|
||||
@@ -2094,6 +2095,8 @@ export namespace plugin {
|
||||
changelog?: LocalizedText;
|
||||
tags?: string[];
|
||||
locales?: string[];
|
||||
stars?: number;
|
||||
downloads?: number;
|
||||
updated_at?: string;
|
||||
|
||||
static createFrom(source: any = {}) {
|
||||
@@ -2112,6 +2115,7 @@ export namespace plugin {
|
||||
this.trust = source["trust"];
|
||||
this.kind = source["kind"];
|
||||
this.tier = source["tier"];
|
||||
this.icon = this.convertValues(source["icon"], PluginIcon);
|
||||
this.homepage = source["homepage"];
|
||||
this.readme_url = source["readme_url"];
|
||||
this.engines = this.convertValues(source["engines"], Engines);
|
||||
@@ -2124,6 +2128,8 @@ export namespace plugin {
|
||||
this.changelog = this.convertValues(source["changelog"], LocalizedText);
|
||||
this.tags = source["tags"];
|
||||
this.locales = source["locales"];
|
||||
this.stars = source["stars"];
|
||||
this.downloads = source["downloads"];
|
||||
this.updated_at = source["updated_at"];
|
||||
}
|
||||
|
||||
@@ -2423,6 +2429,20 @@ export namespace plugin {
|
||||
return a;
|
||||
}
|
||||
}
|
||||
export class PluginIcon {
|
||||
tone?: string;
|
||||
svg?: string;
|
||||
|
||||
static createFrom(source: any = {}) {
|
||||
return new PluginIcon(source);
|
||||
}
|
||||
|
||||
constructor(source: any = {}) {
|
||||
if ('string' === typeof source) source = JSON.parse(source);
|
||||
this.tone = source["tone"];
|
||||
this.svg = source["svg"];
|
||||
}
|
||||
}
|
||||
export class PluginInfo {
|
||||
id: string;
|
||||
version: string;
|
||||
@@ -2431,6 +2451,7 @@ export namespace plugin {
|
||||
publisher?: string;
|
||||
license?: string;
|
||||
homepage?: string;
|
||||
icon?: PluginIcon;
|
||||
source: string;
|
||||
trust: string;
|
||||
tier: string;
|
||||
@@ -2470,6 +2491,7 @@ export namespace plugin {
|
||||
this.publisher = source["publisher"];
|
||||
this.license = source["license"];
|
||||
this.homepage = source["homepage"];
|
||||
this.icon = this.convertValues(source["icon"], PluginIcon);
|
||||
this.source = source["source"];
|
||||
this.trust = source["trust"];
|
||||
this.tier = source["tier"];
|
||||
|
||||
@@ -63,6 +63,10 @@ func Definition(ver string, cb builtin.HostCallbacks, desired bool) plugin.Plugi
|
||||
},
|
||||
Publisher: "Reims-Go",
|
||||
License: "Apache-2.0",
|
||||
Icon: &plugin.PluginIcon{
|
||||
Tone: "indigo",
|
||||
SVG: `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="2" y="3" width="20" height="14" rx="2"/><line x1="8" y1="21" x2="16" y2="21"/><line x1="12" y1="17" x2="12" y2="21"/></svg>`,
|
||||
},
|
||||
Permissions: []string{"driver:vm", "vm:control", "vm:intent", "qmp:write"},
|
||||
DefaultEnabled: true,
|
||||
Contributes: plugin.Contributes{GuestDrivers: []plugin.GuestDriverContribution{{
|
||||
|
||||
@@ -23,6 +23,10 @@ func ImagesDefinition(ver string, desired bool) plugin.PluginDef {
|
||||
},
|
||||
Publisher: "Reims-Go",
|
||||
License: "Apache-2.0",
|
||||
Icon: &plugin.PluginIcon{
|
||||
Tone: "teal",
|
||||
SVG: `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="9"/><circle cx="12" cy="12" r="2.5"/><path d="M6.5 8.5a6.5 6.5 0 0 1 5.5-3"/></svg>`,
|
||||
},
|
||||
Permissions: []string{"ui:slot"},
|
||||
DefaultEnabled: true,
|
||||
Contributes: plugin.Contributes{
|
||||
|
||||
@@ -30,6 +30,7 @@ func defAppWindow(ver string, cb HostCallbacks, desiredFn func(string, bool) boo
|
||||
},
|
||||
Publisher: "Reims-Go",
|
||||
License: "Apache-2.0",
|
||||
Icon: iconAppWindow,
|
||||
Platforms: []string{"windows-x64"},
|
||||
Requires: []plugin.ServiceRequirement{
|
||||
{Service: ServiceGuestToolsTransport, Version: "^1.0.0"},
|
||||
|
||||
@@ -116,6 +116,7 @@ func defGuestTools(ver string, cb HostCallbacks, desiredFn func(string, bool) bo
|
||||
},
|
||||
Publisher: "Reims-Go",
|
||||
License: "Apache-2.0",
|
||||
Icon: iconGuestTools,
|
||||
Provides: []plugin.ServiceProvision{{Service: ServiceGuestToolsTransport, Version: "1.0.0"}},
|
||||
Permissions: []string{"vm:intent", "fs:shared", "ui:slot"},
|
||||
DefaultEnabled: true,
|
||||
@@ -236,6 +237,7 @@ func defClipboard(ver string, desiredFn func(string, bool) bool) plugin.PluginDe
|
||||
},
|
||||
Publisher: "Reims-Go",
|
||||
License: "Apache-2.0",
|
||||
Icon: iconClipboard,
|
||||
Requires: []plugin.ServiceRequirement{{Service: ServiceGuestToolsTransport, Version: "^1.0.0"}},
|
||||
Permissions: []string{"host:clipboard", "ui:slot"},
|
||||
DefaultEnabled: true,
|
||||
@@ -373,6 +375,7 @@ func defInput(ver string, cb HostCallbacks, desiredFn func(string, bool) bool) p
|
||||
},
|
||||
Publisher: "Reims-Go",
|
||||
License: "Apache-2.0",
|
||||
Icon: iconInput,
|
||||
Provides: []plugin.ServiceProvision{{Service: ServiceHostInput, Version: "1.0.0"}},
|
||||
Permissions: []string{"input:filter"},
|
||||
DefaultEnabled: true,
|
||||
@@ -409,6 +412,7 @@ func defNpcapBridge(ver string, cb HostCallbacks, desiredFn func(string, bool) b
|
||||
},
|
||||
Publisher: "Reims-Go",
|
||||
License: "Apache-2.0",
|
||||
Icon: iconNpcap,
|
||||
Provides: []plugin.ServiceProvision{{Service: ServiceNpcapBridge, Version: "1.0.0"}},
|
||||
Permissions: []string{"vm:intent"},
|
||||
DefaultEnabled: true,
|
||||
|
||||
@@ -44,6 +44,7 @@ func defComputerUse(ver string, desiredFn func(string, bool) bool) plugin.Plugin
|
||||
},
|
||||
Publisher: "Reims-Go",
|
||||
License: "Apache-2.0",
|
||||
Icon: iconComputerUse,
|
||||
Provides: []plugin.ServiceProvision{{Service: ServiceComputerUse, Version: "1.0.0"}},
|
||||
Permissions: []string{"vm:screen", "qmp:write"},
|
||||
DefaultEnabled: true,
|
||||
|
||||
@@ -16,6 +16,7 @@ func defCore(ver string) plugin.PluginDef {
|
||||
Description: plugin.LocalizedText{ZhCN: "宿主默认外观与基础能力,始终启用", EnUS: "Default host appearance and foundation; always on"},
|
||||
Publisher: "Reims-Go",
|
||||
License: "Apache-2.0",
|
||||
Icon: iconCore,
|
||||
DefaultEnabled: true,
|
||||
Contributes: plugin.Contributes{Themes: []plugin.ThemeContribution{{
|
||||
ID: IDThemeDefault,
|
||||
|
||||
@@ -33,6 +33,7 @@ func defDownloaderParallel(ver string, cb HostCallbacks, desiredFn func(string,
|
||||
},
|
||||
Publisher: "Reims-Go",
|
||||
License: "Apache-2.0",
|
||||
Icon: iconDownloader,
|
||||
Permissions: []string{"net:download"},
|
||||
DefaultEnabled: true,
|
||||
Contributes: plugin.Contributes{
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
package builtin
|
||||
|
||||
import "github.com/Nwflower/reims-go/internal/plugin"
|
||||
|
||||
var (
|
||||
iconCore = &plugin.PluginIcon{
|
||||
Tone: "indigo",
|
||||
SVG: `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polygon points="12 3 20 7.5 20 16.5 12 21 4 16.5 4 7.5"/><line x1="12" y1="12" x2="20" y2="7.5"/><line x1="12" y1="12" x2="12" y2="21"/><line x1="12" y1="12" x2="4" y2="7.5"/></svg>`,
|
||||
}
|
||||
iconGuestTools = &plugin.PluginIcon{
|
||||
Tone: "teal",
|
||||
SVG: `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M9 17H6a4 4 0 0 1 0-8h3"/><path d="M15 9h3a4 4 0 0 1 0 8h-3"/><line x1="8" y1="13" x2="16" y2="13"/></svg>`,
|
||||
}
|
||||
iconClipboard = &plugin.PluginIcon{
|
||||
Tone: "sky",
|
||||
SVG: `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="8" y="3" width="8" height="4" rx="1"/><path d="M16 5h2a2 2 0 0 1 2 2v13a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2V7a2 2 0 0 1 2-2h2"/></svg>`,
|
||||
}
|
||||
iconInput = &plugin.PluginIcon{
|
||||
Tone: "rose",
|
||||
SVG: `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="2" y="5" width="20" height="14" rx="2"/><line x1="6" y1="9" x2="6.01" y2="9"/><line x1="10" y1="9" x2="10.01" y2="9"/><line x1="14" y1="9" x2="14.01" y2="9"/><line x1="18" y1="9" x2="18.01" y2="9"/><line x1="7" y1="15" x2="17" y2="15"/></svg>`,
|
||||
}
|
||||
iconNpcap = &plugin.PluginIcon{
|
||||
Tone: "emerald",
|
||||
SVG: `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="9" y="3" width="6" height="5" rx="1"/><rect x="3" y="16" width="6" height="5" rx="1"/><rect x="15" y="16" width="6" height="5" rx="1"/><line x1="12" y1="8" x2="12" y2="12"/><path d="M6 16v-2a2 2 0 0 1 2-2h8a2 2 0 0 1 2 2v2"/></svg>`,
|
||||
}
|
||||
iconComputerUse = &plugin.PluginIcon{
|
||||
Tone: "amber",
|
||||
SVG: `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="3" y="4" width="18" height="14" rx="2"/><polyline points="7 10 10 12 7 14"/><line x1="12" y1="14" x2="16" y2="14"/><line x1="8" y1="21" x2="16" y2="21"/></svg>`,
|
||||
}
|
||||
iconAppWindow = &plugin.PluginIcon{
|
||||
Tone: "purple",
|
||||
SVG: `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="3" y="4" width="18" height="16" rx="2"/><line x1="3" y1="9" x2="21" y2="9"/><line x1="7" y1="6.5" x2="7.01" y2="6.5"/><line x1="10.5" y1="6.5" x2="10.51" y2="6.5"/></svg>`,
|
||||
}
|
||||
iconDownloader = &plugin.PluginIcon{
|
||||
Tone: "sky",
|
||||
SVG: `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="12" y1="4" x2="12" y2="15"/><polyline points="7 11 12 16 17 11"/><path d="M4 17v2a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2v-2"/></svg>`,
|
||||
}
|
||||
)
|
||||
@@ -0,0 +1,134 @@
|
||||
package plugin
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"path"
|
||||
"strings"
|
||||
)
|
||||
|
||||
const maxPluginIconSVGBytes = 32 << 10 // 32 KiB ceiling for monochrome foreground icon SVG
|
||||
|
||||
// PluginIconTones lists the allowed background color tokens for plugin icons.
|
||||
var PluginIconTones = []string{
|
||||
"indigo",
|
||||
"purple",
|
||||
"sky",
|
||||
"rose",
|
||||
"emerald",
|
||||
"amber",
|
||||
"teal",
|
||||
"slate",
|
||||
}
|
||||
|
||||
// PluginIcon declares a plugin's custom squircle color token and monochrome SVG foreground icon.
|
||||
// In external plugin.json manifests, SVG is a relative path to an .svg file inside the package.
|
||||
// In resolved PluginInfo, MarketEntry, and built-in plugins, SVG holds the sanitized inline <svg> markup.
|
||||
type PluginIcon struct {
|
||||
Tone string `json:"tone,omitempty"`
|
||||
SVG string `json:"svg,omitempty"`
|
||||
}
|
||||
|
||||
// IsValidPluginIconTone reports whether tone is one of the allowed color tokens.
|
||||
func IsValidPluginIconTone(tone string) bool {
|
||||
t := strings.ToLower(strings.TrimSpace(tone))
|
||||
for _, allowed := range PluginIconTones {
|
||||
if t == allowed {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// IsInlineSVG reports whether raw looks like inline SVG markup rather than a file path.
|
||||
func IsInlineSVG(raw string) bool {
|
||||
s := strings.TrimSpace(raw)
|
||||
return strings.HasPrefix(strings.ToLower(s), "<svg")
|
||||
}
|
||||
|
||||
// ValidatePluginIcon checks tone token and SVG path/markup constraints.
|
||||
func ValidatePluginIcon(icon *PluginIcon, isBuiltin bool) error {
|
||||
if icon == nil {
|
||||
return nil
|
||||
}
|
||||
tone := strings.TrimSpace(icon.Tone)
|
||||
if tone != "" && !IsValidPluginIconTone(tone) {
|
||||
return fmt.Errorf("invalid icon.tone %q (allowed: %s)", icon.Tone, strings.Join(PluginIconTones, ", "))
|
||||
}
|
||||
svg := strings.TrimSpace(icon.SVG)
|
||||
if svg == "" {
|
||||
return nil
|
||||
}
|
||||
if isBuiltin {
|
||||
if _, err := SanitizePluginIconSVG([]byte(svg)); err != nil {
|
||||
return fmt.Errorf("invalid builtin icon.svg: %w", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
if IsInlineSVG(svg) {
|
||||
return errors.New("external plugin icon.svg must be a relative .svg file path inside the package, not inline markup")
|
||||
}
|
||||
if err := validateSafeManifestAsset(svg, ""); err != nil {
|
||||
return fmt.Errorf("invalid icon.svg %q: %w", icon.SVG, err)
|
||||
}
|
||||
if !strings.EqualFold(path.Ext(svg), ".svg") {
|
||||
return fmt.Errorf("invalid icon.svg %q: must be a .svg file", icon.SVG)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// SanitizePluginIconSVG validates size and active content, then returns sanitized inline <svg> markup.
|
||||
func SanitizePluginIconSVG(raw []byte) (string, error) {
|
||||
if len(raw) == 0 {
|
||||
return "", errors.New("empty svg")
|
||||
}
|
||||
if len(raw) > maxPluginIconSVGBytes {
|
||||
return "", fmt.Errorf("svg exceeds %d bytes", maxPluginIconSVGBytes)
|
||||
}
|
||||
text := string(raw)
|
||||
if reason := scanSVGActiveContent(text); reason != "" {
|
||||
return "", fmt.Errorf("svg contains forbidden active content (%s)", reason)
|
||||
}
|
||||
cleaned := strings.TrimSpace(string(SanitizeSVG(raw)))
|
||||
low := strings.ToLower(cleaned)
|
||||
start := strings.Index(low, "<svg")
|
||||
end := strings.LastIndex(low, "</svg>")
|
||||
if start < 0 || end < start {
|
||||
return "", errors.New("missing <svg>...</svg> root element")
|
||||
}
|
||||
return strings.TrimSpace(cleaned[start : end+len("</svg>")]), nil
|
||||
}
|
||||
|
||||
// ResolvePluginIcon produces a sanitized PluginIcon ready for UI rendering.
|
||||
func ResolvePluginIcon(icon *PluginIcon, installDir string, isBuiltin bool) *PluginIcon {
|
||||
if icon == nil {
|
||||
return nil
|
||||
}
|
||||
out := &PluginIcon{}
|
||||
if tone := strings.ToLower(strings.TrimSpace(icon.Tone)); IsValidPluginIconTone(tone) {
|
||||
out.Tone = tone
|
||||
}
|
||||
svg := strings.TrimSpace(icon.SVG)
|
||||
if svg != "" {
|
||||
if isBuiltin || IsInlineSVG(svg) {
|
||||
if cleaned, err := SanitizePluginIconSVG([]byte(svg)); err == nil {
|
||||
out.SVG = cleaned
|
||||
}
|
||||
} else if installDir != "" {
|
||||
if full, err := safeJoin(installDir, svg); err == nil {
|
||||
if info, err := os.Stat(full); err == nil && !info.IsDir() && info.Size() <= maxPluginIconSVGBytes {
|
||||
if data, err := os.ReadFile(full); err == nil {
|
||||
if cleaned, err := SanitizePluginIconSVG(data); err == nil {
|
||||
out.SVG = cleaned
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if out.Tone == "" && out.SVG == "" {
|
||||
return nil
|
||||
}
|
||||
return out
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
package plugin
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestValidatePluginIcon(t *testing.T) {
|
||||
validSVG := `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><circle cx="12" cy="12" r="8"/></svg>`
|
||||
|
||||
if err := ValidatePluginIcon(nil, false); err != nil {
|
||||
t.Fatalf("nil icon should be valid: %v", err)
|
||||
}
|
||||
if err := ValidatePluginIcon(&PluginIcon{Tone: "sky", SVG: "assets/icon.svg"}, false); err != nil {
|
||||
t.Fatalf("external icon path should be valid: %v", err)
|
||||
}
|
||||
if err := ValidatePluginIcon(&PluginIcon{Tone: "indigo", SVG: validSVG}, true); err != nil {
|
||||
t.Fatalf("builtin inline svg should be valid: %v", err)
|
||||
}
|
||||
if err := ValidatePluginIcon(&PluginIcon{Tone: "magenta"}, false); err == nil {
|
||||
t.Fatal("expected invalid tone error")
|
||||
}
|
||||
if err := ValidatePluginIcon(&PluginIcon{Tone: "sky", SVG: validSVG}, false); err == nil {
|
||||
t.Fatal("expected external inline svg error")
|
||||
}
|
||||
if err := ValidatePluginIcon(&PluginIcon{Tone: "sky", SVG: "icon.png"}, false); err == nil {
|
||||
t.Fatal("expected non-svg extension error")
|
||||
}
|
||||
if err := ValidatePluginIcon(&PluginIcon{Tone: "sky", SVG: `<svg><script>alert(1)</script></svg>`}, true); err == nil {
|
||||
t.Fatal("expected active svg content error")
|
||||
}
|
||||
}
|
||||
|
||||
func TestResolvePluginIconFromPackageDir(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
svg := `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><rect x="4" y="4" width="16" height="16"/></svg>`
|
||||
if err := os.WriteFile(filepath.Join(dir, "icon.svg"), []byte(svg), 0o644); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
got := ResolvePluginIcon(&PluginIcon{Tone: "TEAL", SVG: "icon.svg"}, dir, false)
|
||||
if got == nil {
|
||||
t.Fatal("expected resolved icon")
|
||||
}
|
||||
if got.Tone != "teal" {
|
||||
t.Fatalf("tone = %q, want teal", got.Tone)
|
||||
}
|
||||
if !strings.HasPrefix(got.SVG, "<svg") || !strings.Contains(got.SVG, "<rect") {
|
||||
t.Fatalf("unexpected resolved svg: %q", got.SVG)
|
||||
}
|
||||
}
|
||||
|
||||
func TestScanBlocksOversizedAndMalformedIconSVG(t *testing.T) {
|
||||
manifest := `{"schema":1,"id":"test.icon.check","version":"1.0.0","name":"Icon","description":"Icon","icon":{"tone":"sky","svg":"icon.svg"}}`
|
||||
|
||||
t.Run("oversized", func(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
_ = os.WriteFile(filepath.Join(dir, "plugin.json"), []byte(manifest), 0o644)
|
||||
big := `<svg xmlns="http://www.w3.org/2000/svg"><!--` + strings.Repeat("a", maxPluginIconSVGBytes+64) + `--></svg>`
|
||||
_ = os.WriteFile(filepath.Join(dir, "icon.svg"), []byte(big), 0o644)
|
||||
rep := ScanDirectory(dir, "0.2.12", ScanOptions{})
|
||||
if !rep.HardBlocked {
|
||||
t.Fatalf("expected oversized icon.svg to be hard-blocked, got passed=%v", rep.Passed)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("malformed", func(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
_ = os.WriteFile(filepath.Join(dir, "plugin.json"), []byte(manifest), 0o644)
|
||||
_ = os.WriteFile(filepath.Join(dir, "icon.svg"), []byte("not an svg"), 0o644)
|
||||
rep := ScanDirectory(dir, "0.2.12", ScanOptions{})
|
||||
if !rep.HardBlocked {
|
||||
t.Fatalf("expected malformed icon.svg to be hard-blocked, got passed=%v", rep.Passed)
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -161,20 +161,26 @@ func InitLocalePack(opts LocaleInitOptions) error {
|
||||
}
|
||||
}
|
||||
|
||||
const defaultLocaleIconSVG = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="9"/><ellipse cx="12" cy="12" rx="4" ry="9"/><line x1="3" y1="12" x2="21" y2="12"/></svg>` + "\n"
|
||||
if err := os.WriteFile(filepath.Join(outDir, "icon.svg"), []byte(defaultLocaleIconSVG), 0o644); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var nameText, descText LocalizedText
|
||||
nameText.Set(string(canon), defaultNativeLocalePackName(string(canon), lc.Label))
|
||||
descText.Set(string(canon), defaultNativeLocalePackDesc(string(canon), lc.Label))
|
||||
|
||||
man := Manifest{
|
||||
Schema: ManifestSchemaVersion,
|
||||
ID: pluginID,
|
||||
Version: "0.1.0",
|
||||
Name: LocalizedText{
|
||||
ZhCN: string(canon) + " 语言包",
|
||||
EnUS: string(canon) + " Language Pack",
|
||||
Extra: map[string]string{string(canon): lc.Label},
|
||||
Schema: ManifestSchemaVersion,
|
||||
ID: pluginID,
|
||||
Version: "0.1.0",
|
||||
Name: nameText,
|
||||
Description: descText,
|
||||
License: "Apache-2.0",
|
||||
Icon: &PluginIcon{
|
||||
Tone: "sky",
|
||||
SVG: "icon.svg",
|
||||
},
|
||||
Description: LocalizedText{
|
||||
ZhCN: fmt.Sprintf("为 Reims-Go 提供 %s 界面与命令行本地化支持", lc.Label),
|
||||
EnUS: fmt.Sprintf("Provides %s UI and CLI localization for Reims-Go", lc.Label),
|
||||
},
|
||||
License: "Apache-2.0",
|
||||
Engines: Engines{
|
||||
PluginAPI: "^1.0.0",
|
||||
},
|
||||
@@ -185,6 +191,60 @@ func InitLocalePack(opts LocaleInitOptions) error {
|
||||
return writeIndentedJSON(filepath.Join(outDir, "plugin.json"), man)
|
||||
}
|
||||
|
||||
func defaultNativeLocalePackName(tag, label string) string {
|
||||
switch tag {
|
||||
case "zh-CN":
|
||||
return "简体中文语言包"
|
||||
case "zh-TW":
|
||||
return "繁體中文語言包"
|
||||
case "zh-HK":
|
||||
return "繁體中文(香港)語言包"
|
||||
case "ja-JP":
|
||||
return "日本語言語パック"
|
||||
case "ko-KR":
|
||||
return "한국어 언어 팩"
|
||||
case "de-DE":
|
||||
return "Deutsch Sprachpaket"
|
||||
case "fr-FR":
|
||||
return "Pack de langue français"
|
||||
case "es-ES":
|
||||
return "Paquete de idioma español"
|
||||
case "ru-RU":
|
||||
return "Русский языковой пакет"
|
||||
case "ar-SA":
|
||||
return "حزمة اللغة العربية"
|
||||
default:
|
||||
return label
|
||||
}
|
||||
}
|
||||
|
||||
func defaultNativeLocalePackDesc(tag, label string) string {
|
||||
switch tag {
|
||||
case "zh-CN":
|
||||
return "为 Reims-Go 提供简体中文界面。"
|
||||
case "zh-TW":
|
||||
return "為 Reims-Go 提供繁體中文介面。"
|
||||
case "zh-HK":
|
||||
return "為 Reims-Go 提供香港繁體中文介面。"
|
||||
case "ja-JP":
|
||||
return "Reims-Go に日本語インターフェースを提供します。"
|
||||
case "ko-KR":
|
||||
return "Reims-Go에 한국어 인터페이스를 제공합니다."
|
||||
case "de-DE":
|
||||
return "Stellt die deutsche Oberfläche für Reims-Go bereit."
|
||||
case "fr-FR":
|
||||
return "Fournit l'interface en français pour Reims-Go."
|
||||
case "es-ES":
|
||||
return "Proporciona la interfaz en español para Reims-Go."
|
||||
case "ru-RU":
|
||||
return "Предоставляет русский интерфейс для Reims-Go."
|
||||
case "ar-SA":
|
||||
return "يوفر واجهة باللغة العربية لـ Reims-Go."
|
||||
default:
|
||||
return fmt.Sprintf("Provides a %s interface for Reims-Go.", label)
|
||||
}
|
||||
}
|
||||
|
||||
func defaultNativeLocaleLabel(tag string) string {
|
||||
switch tag {
|
||||
case "zh-CN":
|
||||
|
||||
@@ -56,6 +56,7 @@ type MarketEntry struct {
|
||||
Trust TrustLevel `json:"trust"`
|
||||
Kind string `json:"kind,omitempty"` // "theme" | "locale" | "driver" | "tool" | "template" | "runtime"
|
||||
Tier Tier `json:"tier,omitempty"`
|
||||
Icon *PluginIcon `json:"icon,omitempty"`
|
||||
Homepage string `json:"homepage,omitempty"`
|
||||
ReadmeURL string `json:"readme_url,omitempty"`
|
||||
Engines Engines `json:"engines"`
|
||||
@@ -70,6 +71,8 @@ type MarketEntry struct {
|
||||
// Locales lists the UI languages a locale pack provides. When absent,
|
||||
// they are inferred from tags and translated names (MarketEntryLocales).
|
||||
Locales []string `json:"locales,omitempty"`
|
||||
Stars int `json:"stars,omitempty"`
|
||||
Downloads int `json:"downloads,omitempty"`
|
||||
UpdatedAt string `json:"updated_at,omitempty"`
|
||||
}
|
||||
|
||||
|
||||
@@ -237,6 +237,9 @@ func ValidateManifest(m Manifest, hostVersion string, isBuiltinOrBundled bool) e
|
||||
return err
|
||||
}
|
||||
}
|
||||
if err := ValidatePluginIcon(m.Icon, isBuiltinOrBundled); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := validateUIContract(m); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -1599,6 +1599,7 @@ func (r *Registry) entryToInfoLocked(e *pluginEntry) PluginInfo {
|
||||
Publisher: m.Publisher,
|
||||
License: m.License,
|
||||
Homepage: m.Homepage,
|
||||
Icon: ResolvePluginIcon(m.Icon, e.def.InstallDir, e.def.Source == SourceBuiltin),
|
||||
Source: e.def.Source,
|
||||
Trust: e.def.Trust,
|
||||
Tier: tier,
|
||||
|
||||
@@ -308,6 +308,27 @@ func (s *packageScan) checkEntries() {
|
||||
fmt.Sprintf("Declared %s %q is a directory, expected a file", label, rel))
|
||||
}
|
||||
}
|
||||
if s.m.Icon != nil && strings.TrimSpace(s.m.Icon.SVG) != "" && !IsInlineSVG(s.m.Icon.SVG) {
|
||||
rel := s.m.Icon.SVG
|
||||
checkEntryFile("icon.svg", rel, false)
|
||||
if full, jErr := safeJoin(s.dir, rel); jErr == nil {
|
||||
if st, sErr := os.Stat(full); sErr == nil && !st.IsDir() {
|
||||
if st.Size() > maxPluginIconSVGBytes {
|
||||
s.hard("invalid-icon", rel, fmt.Sprintf("icon.svg exceeds %d bytes (%d bytes)", maxPluginIconSVGBytes, st.Size()),
|
||||
fmt.Sprintf("插件图标 %s 超过 %d 字节上限", rel, maxPluginIconSVGBytes),
|
||||
fmt.Sprintf("Plugin icon %q exceeds the %d-byte limit", rel, maxPluginIconSVGBytes))
|
||||
} else if data, rErr := os.ReadFile(full); rErr != nil {
|
||||
s.hard("invalid-icon", rel, fmt.Sprintf("failed to read icon.svg: %v", rErr),
|
||||
fmt.Sprintf("无法读取插件图标 %s:%v", rel, rErr),
|
||||
fmt.Sprintf("Failed to read plugin icon %q: %v", rel, rErr))
|
||||
} else if _, vErr := SanitizePluginIconSVG(data); vErr != nil {
|
||||
s.hard("invalid-icon", rel, fmt.Sprintf("invalid icon.svg: %v", vErr),
|
||||
fmt.Sprintf("插件图标 %s 格式无效:%v", rel, vErr),
|
||||
fmt.Sprintf("Plugin icon %q is invalid: %v", rel, vErr))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
checkEntryFile("entry.sidecar", s.m.Entry.Sidecar, false)
|
||||
checkEntryFile("entry.script", s.m.Entry.Script, false)
|
||||
checkEntryFile("entry.uiScript", s.m.Entry.UIScript, false)
|
||||
|
||||
@@ -267,6 +267,7 @@ type Manifest struct {
|
||||
Publisher string `json:"publisher,omitempty"`
|
||||
License string `json:"license,omitempty"`
|
||||
Homepage string `json:"homepage,omitempty"`
|
||||
Icon *PluginIcon `json:"icon,omitempty"`
|
||||
Engines Engines `json:"engines,omitempty"`
|
||||
Platforms []string `json:"platforms,omitempty"`
|
||||
L10n string `json:"l10n,omitempty"` // relative directory holding <locale>.json bundles for plugin:<id>:*
|
||||
@@ -807,6 +808,7 @@ type PluginInfo struct {
|
||||
Publisher string `json:"publisher,omitempty"`
|
||||
License string `json:"license,omitempty"`
|
||||
Homepage string `json:"homepage,omitempty"`
|
||||
Icon *PluginIcon `json:"icon,omitempty"`
|
||||
Source SourceKind `json:"source"`
|
||||
Trust TrustLevel `json:"trust"`
|
||||
Tier Tier `json:"tier"`
|
||||
|
||||
@@ -42,6 +42,7 @@
|
||||
"pluginDeleteScheme": "Delete scheme",
|
||||
"pluginExternalSection": "Installed plugins",
|
||||
"pluginLinkDevBtn": "Link plugin dev folder",
|
||||
"pluginSubmitBtn": "Submit plugin",
|
||||
"pluginImportBtn": "Import plugin",
|
||||
"pluginBuiltinSection": "Built-in plugins",
|
||||
"pluginPanelsSection": "Plugin panels",
|
||||
|
||||
@@ -42,6 +42,7 @@
|
||||
"pluginDeleteScheme": "删除方案",
|
||||
"pluginExternalSection": "已安装插件",
|
||||
"pluginLinkDevBtn": "链接插件开发目录",
|
||||
"pluginSubmitBtn": "上架插件",
|
||||
"pluginImportBtn": "导入插件",
|
||||
"pluginBuiltinSection": "内置插件",
|
||||
"pluginPanelsSection": "插件面板",
|
||||
|
||||
Reference in new issue
Block a user