mirror of
https://github.com/fofolee/uTools-quickcommand.git
synced 2025-12-20 19:20:37 +08:00
重构命令输出变量系统:新增OutputEditor组件,支持更灵活的变量配置和回调函数创建
This commit is contained in:
@@ -7,8 +7,6 @@ export const codingCommands = {
|
||||
value: "quickcomposer.coding.base64Encode",
|
||||
label: "编解码",
|
||||
icon: "code",
|
||||
outputVariable: "processedText",
|
||||
saveOutput: true,
|
||||
config: [
|
||||
{
|
||||
label: "要编解码的文本",
|
||||
@@ -63,22 +61,16 @@ export const codingCommands = {
|
||||
value: "quickcomposer.coding.symmetricCrypto",
|
||||
label: "对称加解密",
|
||||
component: "SymmetricCryptoEditor",
|
||||
outputVariable: "processedText",
|
||||
saveOutput: true,
|
||||
},
|
||||
{
|
||||
value: "quickcomposer.coding.asymmetricCrypto",
|
||||
label: "非对称加解密",
|
||||
component: "AsymmetricCryptoEditor",
|
||||
outputVariable: "processedText",
|
||||
saveOutput: true,
|
||||
},
|
||||
{
|
||||
value: "quickcomposer.coding.md5Hash",
|
||||
label: "哈希计算",
|
||||
icon: "enhanced_encryption",
|
||||
outputVariable: "hashValue",
|
||||
saveOutput: true,
|
||||
config: [
|
||||
{
|
||||
label: "要计算哈希的文本",
|
||||
|
||||
@@ -355,8 +355,6 @@ export const dataCommands = {
|
||||
componentProps: {
|
||||
inputLabel: "要处理的文本",
|
||||
},
|
||||
outputVariable: "processedText",
|
||||
saveOutput: true,
|
||||
},
|
||||
{
|
||||
value: "quickcomposer.data.buffer.from",
|
||||
|
||||
@@ -13,6 +13,33 @@ export const macosCommands = {
|
||||
value: "quickcomposer.macos.app.getFrontmost",
|
||||
label: "获取前台应用",
|
||||
icon: "front_hand",
|
||||
outputs: {
|
||||
label: "前台应用信息",
|
||||
name: { label: "应用名称" },
|
||||
displayedName: { label: "应用显示名称" },
|
||||
path: { label: "应用路径" },
|
||||
version: { label: "应用版本" },
|
||||
pid: { label: "应用进程ID" },
|
||||
backgroundOnly: { label: "是否后台运行" },
|
||||
visible: { label: "是否可见" },
|
||||
frontmost: { label: "是否前台运行" },
|
||||
window: {
|
||||
label: "窗口信息",
|
||||
name: { label: "窗口名称" },
|
||||
title: { label: "窗口标题" },
|
||||
index: { label: "窗口索引" },
|
||||
position: {
|
||||
label: "窗口位置",
|
||||
placeholder: "数组, 第一个元素是 x 坐标,第二个元素是 y 坐标",
|
||||
},
|
||||
size: {
|
||||
label: "窗口大小",
|
||||
placeholder: "数组, 第一个元素是宽度,第二个元素是高度",
|
||||
},
|
||||
minimized: { label: "是否最小化" },
|
||||
fullscreen: { label: "是否全屏" },
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
value: "quickcomposer.macos.app.getRunningApps",
|
||||
|
||||
@@ -43,8 +43,6 @@ export const networkCommands = {
|
||||
component: "AxiosConfigEditor",
|
||||
isAsync: true,
|
||||
icon: "http",
|
||||
outputVariable: "{data}",
|
||||
saveOutput: true,
|
||||
},
|
||||
{
|
||||
value: "quickcomposer.network.url.parse",
|
||||
|
||||
@@ -73,8 +73,6 @@ export const screenCommands = {
|
||||
value: "utools.getPrimaryDisplay",
|
||||
label: "获取显示器信息",
|
||||
icon: "monitor",
|
||||
outputVariable: "display",
|
||||
saveOutput: true,
|
||||
subCommands: [
|
||||
{
|
||||
value: "utools.getPrimaryDisplay",
|
||||
@@ -104,8 +102,6 @@ export const screenCommands = {
|
||||
value: "utools.screenToDipPoint",
|
||||
label: "物理/DIP坐标转换",
|
||||
icon: "transform",
|
||||
outputVariable: "{x,y}",
|
||||
saveOutput: true,
|
||||
config: [XY_DICT_EDITOR],
|
||||
subCommands: [
|
||||
{
|
||||
@@ -124,8 +120,6 @@ export const screenCommands = {
|
||||
value: "utools.screenToDipRect",
|
||||
label: "物理/DIP区域转换",
|
||||
icon: "transform",
|
||||
outputVariable: "{x,y,width,height}",
|
||||
saveOutput: true,
|
||||
config: [RECT_DICT_EDITOR],
|
||||
subCommands: [
|
||||
{
|
||||
|
||||
@@ -223,16 +223,12 @@ export const simulateCommands = {
|
||||
label: "屏幕取色",
|
||||
icon: "colorize",
|
||||
isAsync: true,
|
||||
outputVariable: "{hex,rgb}",
|
||||
saveOutput: true,
|
||||
},
|
||||
{
|
||||
value: "quickcomposer.simulate.captureScreen",
|
||||
label: "屏幕截图",
|
||||
icon: "screenshot_monitor",
|
||||
isAsync: true,
|
||||
outputVariable: "base64Data",
|
||||
saveOutput: true,
|
||||
config: [
|
||||
{
|
||||
label: "截图范围",
|
||||
|
||||
@@ -7,40 +7,30 @@ export const statusCommands = {
|
||||
label: "获取当前文件管理器路径",
|
||||
icon: "folder",
|
||||
isAsync: true,
|
||||
outputVariable: "currentFolderPath",
|
||||
saveOutput: true,
|
||||
},
|
||||
{
|
||||
value: "utools.readCurrentBrowserUrl",
|
||||
label: "获取当前浏览器地址",
|
||||
icon: "language",
|
||||
isAsync: true,
|
||||
outputVariable: "currentBrowserUrl",
|
||||
saveOutput: true,
|
||||
},
|
||||
{
|
||||
value: "quickcomposer.status.getSelectedText",
|
||||
label: "获取选中文本",
|
||||
icon: "text_fields",
|
||||
isAsync: true,
|
||||
outputVariable: "selectedText",
|
||||
saveOutput: true,
|
||||
},
|
||||
{
|
||||
value: "quickcomposer.status.getSelectedImage",
|
||||
label: "获取选中的图片",
|
||||
icon: "image",
|
||||
isAsync: true,
|
||||
outputVariable: "selectedImage",
|
||||
saveOutput: true,
|
||||
},
|
||||
{
|
||||
value: "quickcomposer.status.getSelectedFiles",
|
||||
label: "获取选中的文件",
|
||||
icon: "file_present",
|
||||
isAsync: true,
|
||||
outputVariable: "selectedFiles",
|
||||
saveOutput: true,
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
@@ -72,8 +72,6 @@ export const systemCommands = {
|
||||
{
|
||||
value: "electron.clipboard.readText",
|
||||
label: "读取剪贴板",
|
||||
outputVariable: "clipboardContent",
|
||||
saveOutput: true,
|
||||
subCommands: [
|
||||
{
|
||||
value: "electron.clipboard.readText",
|
||||
@@ -112,8 +110,6 @@ export const systemCommands = {
|
||||
{
|
||||
value: "utools.getPath",
|
||||
label: "获取系统路径",
|
||||
outputVariable: "systemPath",
|
||||
saveOutput: true,
|
||||
defaultValue: "home",
|
||||
config: [
|
||||
{
|
||||
|
||||
@@ -169,8 +169,9 @@ export const uiCommands = {
|
||||
value: "quickcommand.showConfirmBox",
|
||||
label: "确认框",
|
||||
isAsync: true,
|
||||
outputVariable: "confirmed",
|
||||
saveOutput: true,
|
||||
outputs: {
|
||||
label: "是否确认",
|
||||
},
|
||||
config: [
|
||||
{
|
||||
label: "提示内容",
|
||||
@@ -219,8 +220,6 @@ export const uiCommands = {
|
||||
value: "quickcommand.showButtonBox",
|
||||
label: "按钮组",
|
||||
isAsync: true,
|
||||
outputVariable: "{id,text}",
|
||||
saveOutput: true,
|
||||
width: 12,
|
||||
config: [
|
||||
{
|
||||
@@ -256,8 +255,6 @@ export const uiCommands = {
|
||||
value: "quickcommand.showInputBox",
|
||||
label: "输入框",
|
||||
isAsync: true,
|
||||
outputVariable: "[inputValue1]",
|
||||
saveOutput: true,
|
||||
config: [
|
||||
{
|
||||
label: "输入框",
|
||||
@@ -302,8 +299,6 @@ export const uiCommands = {
|
||||
value: "quickcommand.showTextArea",
|
||||
label: "文本框",
|
||||
isAsync: true,
|
||||
outputVariable: "textareaValue",
|
||||
saveOutput: true,
|
||||
config: [
|
||||
{
|
||||
label: "文本框占位符",
|
||||
@@ -372,8 +367,6 @@ export const uiCommands = {
|
||||
{
|
||||
value: "utools.showOpenDialog",
|
||||
label: "文件选择框",
|
||||
outputVariable: "filePaths",
|
||||
saveOutput: true,
|
||||
subCommands: [
|
||||
{
|
||||
value: "utools.showOpenDialog",
|
||||
|
||||
@@ -14,15 +14,11 @@ export const userdataCommands = {
|
||||
icon: "title",
|
||||
},
|
||||
],
|
||||
outputVariable: "userData",
|
||||
saveOutput: true,
|
||||
},
|
||||
{
|
||||
value: "quickcommand.userData.all",
|
||||
label: "获取所有用户数据",
|
||||
icon: "database",
|
||||
outputVariable: "userDatas",
|
||||
saveOutput: true,
|
||||
},
|
||||
{
|
||||
value: "quickcommand.userData.put",
|
||||
|
||||
@@ -47,15 +47,11 @@ export const utoolsCommands = {
|
||||
value: "utools.isDarkColors",
|
||||
label: "是否深色模式",
|
||||
icon: "dark_mode",
|
||||
outputVariable: "isDark",
|
||||
saveOutput: true,
|
||||
},
|
||||
{
|
||||
value: "utools.getUser",
|
||||
label: "获取用户信息",
|
||||
icon: "person",
|
||||
outputVariable: "{avatar,nickname,type}",
|
||||
saveOutput: true,
|
||||
},
|
||||
{
|
||||
value: "utools.redirect",
|
||||
@@ -163,20 +159,14 @@ export const utoolsCommands = {
|
||||
value: "utools.getWindowType",
|
||||
label: "获取当前窗口类型",
|
||||
icon: "window",
|
||||
outputVariable: "windowType",
|
||||
saveOutput: true,
|
||||
},
|
||||
{
|
||||
value: "utools.getNativeId",
|
||||
label: "获取本地ID",
|
||||
outputVariable: "nativeId",
|
||||
saveOutput: true,
|
||||
},
|
||||
{
|
||||
value: "utools.getAppVersion",
|
||||
label: "获取uTools版本",
|
||||
outputVariable: "appVersion",
|
||||
saveOutput: true,
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
@@ -207,8 +207,6 @@ export const windowsCommands = {
|
||||
value: "quickcomposer.windows.window.getWindowInfo",
|
||||
label: "搜索窗口",
|
||||
icon: "search",
|
||||
outputVariable: "windowInfo",
|
||||
saveOutput: true,
|
||||
},
|
||||
{
|
||||
value: "quickcomposer.windows.automation.inspect",
|
||||
@@ -451,7 +449,6 @@ export const windowsCommands = {
|
||||
value: "quickcomposer.windows.automation.getvalue",
|
||||
label: "获取值",
|
||||
icon: "content_paste",
|
||||
outputVariable: "elementValue",
|
||||
},
|
||||
{
|
||||
value: "quickcomposer.windows.automation.select",
|
||||
@@ -621,8 +618,6 @@ export const windowsCommands = {
|
||||
value: "quickcomposer.windows.sendmessage.listControls",
|
||||
label: "获取控件树",
|
||||
icon: "account_tree",
|
||||
outputVariable: "controlsTree",
|
||||
saveOutput: true,
|
||||
config: [
|
||||
{
|
||||
component: "OptionEditor",
|
||||
@@ -810,8 +805,6 @@ export const windowsCommands = {
|
||||
label: "剪贴板/文件监控",
|
||||
icon: "monitor_heart",
|
||||
isAsync: true,
|
||||
outputVariable: "monitorEvent",
|
||||
saveOutput: true,
|
||||
showLoading: true,
|
||||
subCommands: [
|
||||
{
|
||||
@@ -879,8 +872,6 @@ export const windowsCommands = {
|
||||
value: "quickcomposer.windows.process.listProcesses",
|
||||
label: "进程列表",
|
||||
icon: "list",
|
||||
outputVariable: "processList",
|
||||
saveOutput: true,
|
||||
},
|
||||
{
|
||||
value: "quickcomposer.windows.process.killProcess",
|
||||
@@ -956,8 +947,6 @@ export const windowsCommands = {
|
||||
value: "quickcomposer.windows.registry.listKeys",
|
||||
label: "列出项",
|
||||
icon: "list",
|
||||
outputVariable: "registryKeys",
|
||||
saveOutput: true,
|
||||
},
|
||||
{
|
||||
value: "quickcomposer.windows.registry.getValue",
|
||||
@@ -983,8 +972,6 @@ export const windowsCommands = {
|
||||
placeholder: "要获取的值名称",
|
||||
},
|
||||
],
|
||||
outputVariable: "registryValue",
|
||||
saveOutput: true,
|
||||
},
|
||||
{
|
||||
value: "quickcomposer.windows.registry.setValue",
|
||||
@@ -1072,8 +1059,6 @@ export const windowsCommands = {
|
||||
value: "quickcomposer.windows.service.listServices",
|
||||
label: "服务列表",
|
||||
icon: "list",
|
||||
outputVariable: "serviceList",
|
||||
saveOutput: true,
|
||||
},
|
||||
{
|
||||
value: "quickcomposer.windows.service.controlService",
|
||||
@@ -1116,8 +1101,6 @@ export const windowsCommands = {
|
||||
value: "quickcomposer.windows.software.listSoftware",
|
||||
label: "软件列表",
|
||||
icon: "list",
|
||||
outputVariable: "softwareList",
|
||||
saveOutput: true,
|
||||
},
|
||||
{
|
||||
value: "quickcomposer.windows.software.uninstallSoftware",
|
||||
|
||||
@@ -2,8 +2,7 @@ export function generateCode(flow) {
|
||||
const { commands, name, label, customVariables = [] } = flow;
|
||||
|
||||
const params = customVariables.filter((v) => v.type === "param") || [];
|
||||
const manualVars =
|
||||
customVariables.filter((v) => v.type === "var") || [];
|
||||
const manualVars = customVariables.filter((v) => v.type === "var") || [];
|
||||
// 检查是否包含异步函数
|
||||
const hasAsyncFunction = commands.some((cmd) => cmd.isAsync);
|
||||
|
||||
@@ -25,15 +24,41 @@ export function generateCode(flow) {
|
||||
// 跳过禁用的命令
|
||||
if (cmd.disabled) return;
|
||||
if (!cmd.code) return;
|
||||
let line = indent;
|
||||
|
||||
let cmdCode = cmd.code;
|
||||
// 处理输出变量
|
||||
if (cmd.outputVariable) {
|
||||
line += `let ${cmd.outputVariable} = `;
|
||||
const { name, details } = cmd.outputVariable;
|
||||
if (cmd.isAsync) {
|
||||
if (cmd.callbackFunc) {
|
||||
// 使用回调函数模式
|
||||
cmdCode = `${cmdCode}.then(${cmd.callbackFunc})`;
|
||||
} else {
|
||||
// 使用 await 模式
|
||||
cmdCode = `const ${name} = await ${cmdCode}`;
|
||||
code.push(indent + cmdCode);
|
||||
// 处理详细变量
|
||||
if (details) {
|
||||
Object.entries(details).forEach(([path, varName]) => {
|
||||
code.push(`${indent}let ${varName} = ${name}.${path};`);
|
||||
});
|
||||
}
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
cmdCode = `const ${name} = ${cmdCode}`;
|
||||
code.push(indent + cmdCode);
|
||||
// 处理详细变量
|
||||
if (details) {
|
||||
Object.entries(details).forEach(([path, varName]) => {
|
||||
code.push(`${indent}let ${varName} = ${name}.${path};`);
|
||||
});
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
let awaitCmd = cmd.isAsync ? "await " : "";
|
||||
line += `${awaitCmd} ${cmd.code}`;
|
||||
code.push(line);
|
||||
code.push(indent + cmdCode);
|
||||
});
|
||||
|
||||
code.push("}"); // Close the function
|
||||
|
||||
Reference in New Issue
Block a user