From f2abe34dacb01f3441f1983ebde62ea1e0235c6c Mon Sep 17 00:00:00 2001 From: Mango Date: Tue, 13 Oct 2026 01:38:05 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=BB=BA=E5=91=BD=E4=BB=A4=E6=97=B6?= =?UTF-8?q?=E6=8C=89=E6=89=A7=E8=A1=8C=E6=96=B9=E5=BC=8F=E5=A1=AB=E4=B8=8A?= =?UTF-8?q?=E9=BB=98=E8=AE=A4=E5=9B=BE=E6=A0=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit MCP 建出来的命令 features.icon 是空的,命令卡片上就是个空位。现在 icon 留空时 按 program 填对应语言的默认图标(shell -> logo/shell.png、python -> logo/python.png,编排用内置图标),显式传了 icon 就用传入的。 --- plugin/lib/commandSchema.js | 2 +- plugin/lib/commandStore.js | 25 +++++++++++++++++++++++++ plugin/plugin.json | 2 +- test/commandStore.test.js | 16 ++++++++++++++++ 4 files changed, 43 insertions(+), 2 deletions(-) diff --git a/plugin/lib/commandSchema.js b/plugin/lib/commandSchema.js index 99e7253..2d1a204 100644 --- a/plugin/lib/commandSchema.js +++ b/plugin/lib/commandSchema.js @@ -46,7 +46,7 @@ module.exports = `# 快捷命令数据结构 - 多种类型混用时会自动变成 "professional" - platform:命令生效的系统,默认三个平台都生效 - mainPush:为 true 时命令出现在 uTools 主输入框的推送列表里(输出类型会被限制) -- icon:data URL 或相对路径,**建议留空**(超过 32KB 会报错),用户可以在界面里自己设置 +- icon:data URL 或相对路径。**建议留空**,留空时会自动用该执行方式的默认图标(如 shell 命令用 logo/shell.png),用户可以在界面里改成自己喜欢的。自己传的话超过 32KB 会报错 ## output(输出方式) diff --git a/plugin/lib/commandStore.js b/plugin/lib/commandStore.js index dce9cd4..2230249 100644 --- a/plugin/lib/commandStore.js +++ b/plugin/lib/commandStore.js @@ -46,6 +46,26 @@ const CMD_TYPES = [ ]; const ICON_MAX_LENGTH = 32 * 1024; +// 各执行方式的默认图标,与 src/js/options/programs.js 保持一致(那边是 webpack 模块,preload 引不到) +const DEFAULT_ICONS = { + quickcommand: "logo/quickcommand.png", + quickcomposer: "logo/quickcommand.png", + html: "logo/html.png", + shell: "logo/shell.png", + applescript: "logo/applescript.png", + cmd: "logo/cmd.png", + powershell: "logo/powershell.png", + python: "logo/python.png", + javascript: "logo/javascript.png", + ruby: "logo/ruby.png", + php: "logo/php.png", + c: "logo/c.png", + csharp: "logo/csharp.png", + lua: "logo/lua.png", + perl: "logo/perl.png", + custom: "logo/custom.png", +}; + const getUniqueId = (options = {}) => { const { short = false } = options; const uuid = "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (c) => { @@ -179,6 +199,11 @@ const normalizeCommand = (command) => { normalized.features.mainHide = outPluginOutputs.includes(normalized.output); normalized.features.code = normalized.features.code || getFeatureCode(normalized.features.cmds); + // 图标留空时用该类型的默认图标,否则命令卡片上是个空位 + if (!normalized.features.icon) { + normalized.features.icon = + DEFAULT_ICONS[normalized.program] || DEFAULT_ICONS.quickcommand; + } if (!Array.isArray(normalized.tags)) normalized.tags = []; if (normalized.output === undefined) normalized.output = "text"; return normalized; diff --git a/plugin/plugin.json b/plugin/plugin.json index fca120e..097155b 100644 --- a/plugin/plugin.json +++ b/plugin/plugin.json @@ -124,7 +124,7 @@ "properties": { "explain": { "type": "string", "description": "命令名称,不能为空" }, "cmds": { "type": "array", "description": "触发方式数组:关键词字符串,或 {type, match} 形式的匹配规则" }, - "icon": { "type": "string", "description": "建议留空,用户可以在界面里自己设置图标" }, + "icon": { "type": "string", "description": "建议留空,留空时自动用该执行方式的默认图标" }, "platform": { "type": "array", "items": { "type": "string" }, "description": "生效平台,默认三个平台都生效" } }, "required": ["explain", "cmds"] diff --git a/test/commandStore.test.js b/test/commandStore.test.js index 51c5444..f42cdc5 100644 --- a/test/commandStore.test.js +++ b/test/commandStore.test.js @@ -45,6 +45,22 @@ const code = command.features.code; assert.match(code, /^key_[0-9a-f]{8}$/); assert.strictEqual(command.features.cmds[0], "测试命令"); assert.strictEqual(command.features.mainHide, false); +// 不带图标时用该执行方式的默认图标 +assert.strictEqual(command.features.icon, "logo/quickcommand.png"); +const pyCommand = store.create({ + program: "python", + cmd: "print(1)", + features: { explain: "py", cmds: ["py"] }, +}).command; +assert.strictEqual(pyCommand.features.icon, "logo/python.png"); +const customCommand = store.create({ + program: "custom", + cmd: "x", + features: { explain: "自定义", cmds: ["自定义"], icon: "data:image/png;base64,xxx" }, +}).command; +assert.strictEqual(customCommand.features.icon, "data:image/png;base64,xxx"); +store.remove(pyCommand.features.code); +store.remove(customCommand.features.code); assert.ok(db.has("qc_" + code)); assert.ok(features.has(code));