mirror of
https://github.com/fofolee/uTools-quickcommand.git
synced 2025-06-07 21:46:12 +08:00
去除CommandTypes启用的属性,运行命令不再需要配置名称
This commit is contained in:
parent
0dc695277e
commit
61c75a899b
@ -81,7 +81,7 @@ const CodeEditor = defineAsyncComponent({
|
|||||||
timeout: 3000,
|
timeout: 3000,
|
||||||
});
|
});
|
||||||
|
|
||||||
// TODO: 对称加密声明,运行命令不需要设置,commandTypes调整
|
// TODO: 对称加密声明
|
||||||
export default {
|
export default {
|
||||||
components: {
|
components: {
|
||||||
CodeEditor,
|
CodeEditor,
|
||||||
|
@ -76,7 +76,6 @@ import commandTypes from "js/options/commandTypes.js";
|
|||||||
import ResultArea from "components/ResultArea.vue";
|
import ResultArea from "components/ResultArea.vue";
|
||||||
import ResultMenu from "components/popup/ResultMenu.vue";
|
import ResultMenu from "components/popup/ResultMenu.vue";
|
||||||
import { generateFlowsCode } from "js/composer/generateCode";
|
import { generateFlowsCode } from "js/composer/generateCode";
|
||||||
import { getValidCommand } from "js/commandManager";
|
|
||||||
import { dbManager } from "js/utools.js";
|
import { dbManager } from "js/utools.js";
|
||||||
import programs from "js/options/programs.js";
|
import programs from "js/options/programs.js";
|
||||||
|
|
||||||
@ -132,16 +131,13 @@ export default {
|
|||||||
// 运行命令
|
// 运行命令
|
||||||
async runCurrentCommand(currentCommand) {
|
async runCurrentCommand(currentCommand) {
|
||||||
let command = window.lodashM.cloneDeep(currentCommand);
|
let command = window.lodashM.cloneDeep(currentCommand);
|
||||||
|
if (!command.output) command.output = "text";
|
||||||
// 如果是composer命令,则动态生成cmd
|
// 如果是composer命令,则动态生成cmd
|
||||||
if (command.program === "quickcomposer") {
|
if (command.program === "quickcomposer") {
|
||||||
command.cmd = generateFlowsCode(command.flows);
|
command.cmd = generateFlowsCode(command.flows);
|
||||||
}
|
}
|
||||||
this.$root.isRunningCommand = true;
|
this.$root.isRunningCommand = true;
|
||||||
try {
|
this.needTempPayload && (await this.getTempPayload(command));
|
||||||
await this.getTempPayload(command);
|
|
||||||
} catch (error) {
|
|
||||||
return quickcommand.showMessageBox(error.toString(), "error");
|
|
||||||
}
|
|
||||||
// 如果命令包含子输入框,则设置子输入框
|
// 如果命令包含子输入框,则设置子输入框
|
||||||
if (command.cmd.includes("{{subinput")) return this.setSubInput(command);
|
if (command.cmd.includes("{{subinput")) return this.setSubInput(command);
|
||||||
this.fire(command);
|
this.fire(command);
|
||||||
@ -291,16 +287,18 @@ export default {
|
|||||||
},
|
},
|
||||||
// payload 临时赋值
|
// payload 临时赋值
|
||||||
async getTempPayload(currentCommand) {
|
async getTempPayload(currentCommand) {
|
||||||
if (!this.needTempPayload) return;
|
const firstCmd = currentCommand.features?.cmds?.[0];
|
||||||
currentCommand = getValidCommand(currentCommand);
|
if (!firstCmd) return;
|
||||||
const firstCmd = currentCommand.features.cmds[0];
|
|
||||||
const type = firstCmd.type || "text";
|
const type = firstCmd.type || "text";
|
||||||
|
const getPayload = async () => {
|
||||||
|
if (type === "text") return firstCmd;
|
||||||
|
const cmdType = commandTypes[type];
|
||||||
|
if (!cmdType.tempPayload) return {};
|
||||||
|
return await cmdType.tempPayload();
|
||||||
|
};
|
||||||
this.$root.enterData = {
|
this.$root.enterData = {
|
||||||
type,
|
type,
|
||||||
payload:
|
payload: await getPayload(),
|
||||||
type === "text"
|
|
||||||
? firstCmd
|
|
||||||
: (await commandTypes[type]?.tempPayload?.()) || {},
|
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
handleResult(stdout, stderr, options) {
|
handleResult(stdout, stderr, options) {
|
||||||
|
@ -305,7 +305,6 @@ export default defineComponent({
|
|||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
ruleTypeOptions: Object.values(commandTypes)
|
ruleTypeOptions: Object.values(commandTypes)
|
||||||
.filter((type) => type.name !== "professional")
|
|
||||||
.map((type) => ({
|
.map((type) => ({
|
||||||
label: type.label,
|
label: type.label,
|
||||||
value: type.name,
|
value: type.name,
|
||||||
|
@ -44,7 +44,7 @@ const getLabeledCmds = (cmds, explain) => {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getValidCommand = (command) => {
|
const getValidCommand = (command) => {
|
||||||
const { cmds, explain } = command.features;
|
const { cmds, explain } = command.features;
|
||||||
if (!explain) throw "名称不能为空";
|
if (!explain) throw "名称不能为空";
|
||||||
if (!Array.isArray(cmds)) throw "匹配规则格式错误";
|
if (!Array.isArray(cmds)) throw "匹配规则格式错误";
|
||||||
|
@ -1,145 +1,49 @@
|
|||||||
/**
|
/**
|
||||||
* 所有的匹配类型
|
* 所有的匹配类型
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const jsonSample = [
|
|
||||||
"关键词1",
|
|
||||||
"关键词2",
|
|
||||||
{
|
|
||||||
type: "img",
|
|
||||||
label: "图片匹配",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type: "files",
|
|
||||||
label: "文件匹配",
|
|
||||||
fileType: "file",
|
|
||||||
match: "/aaa/",
|
|
||||||
minLength: 1,
|
|
||||||
maxLength: 99,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type: "regex",
|
|
||||||
label: "文本正则匹配",
|
|
||||||
match: "/bbb/i",
|
|
||||||
minLength: 1,
|
|
||||||
maxLength: 99,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type: "over",
|
|
||||||
label: "无匹配时",
|
|
||||||
exclude: "/ccc/i",
|
|
||||||
minLength: 1,
|
|
||||||
maxLength: 99,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type: "window",
|
|
||||||
label: "窗口动作",
|
|
||||||
match: {
|
|
||||||
app: ["ddd.app", "eee.exe"],
|
|
||||||
title: "/fff/",
|
|
||||||
class: ["ggg"],
|
|
||||||
},
|
|
||||||
},
|
|
||||||
];
|
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
key: {
|
key: {
|
||||||
name: "key",
|
name: "key",
|
||||||
label: "关键词",
|
label: "关键词",
|
||||||
icon: "font_download",
|
icon: "font_download",
|
||||||
color: "blue",
|
color: "blue",
|
||||||
matchLabel: "关键词",
|
|
||||||
desc: "直接在主输入框输入对应关键字,最通用的一种模式,关键字可以设置多个",
|
desc: "直接在主输入框输入对应关键字,最通用的一种模式,关键字可以设置多个",
|
||||||
valueType: "array",
|
|
||||||
disabledSpecialVars:
|
|
||||||
/{{input}}|{{SelectFile}}|{{pwd}}|{{WindowInfo.*?}}|{{MatchedFiles.*?}}/g,
|
|
||||||
matchToCmds: (rules, desc) => rules,
|
|
||||||
verify: (rules) => !window.lodashM.isEmpty(rules) || "关键词不能为空",
|
|
||||||
},
|
},
|
||||||
regex: {
|
regex: {
|
||||||
name: "regex",
|
name: "regex",
|
||||||
label: "正则",
|
label: "正则",
|
||||||
icon: "rule",
|
icon: "rule",
|
||||||
color: "cyan",
|
color: "cyan",
|
||||||
matchLabel: "正则",
|
|
||||||
desc: "匹配主输入框或超级面板选中的文本,可以获取输入框文本或选中文本作为变量",
|
desc: "匹配主输入框或超级面板选中的文本,可以获取输入框文本或选中文本作为变量",
|
||||||
valueType: "regex",
|
|
||||||
disabledSpecialVars:
|
|
||||||
/{{SelectFile}}|{{MatchImage}}|{{WindowInfo.*?}}|{{pwd}}|{{MatchedFiles.*?}}/g,
|
|
||||||
matchToCmds: (rules, desc) => [
|
|
||||||
{
|
|
||||||
label: desc,
|
|
||||||
type: "regex",
|
|
||||||
match: rules,
|
|
||||||
minNum: 1,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
verify: (rules) => !!rules > 0 || "正则不能为空",
|
|
||||||
tempPayload: async () => {
|
tempPayload: async () => {
|
||||||
let values = await quickcommand.showInputBox(["需要处理的文本"]);
|
let [payload] = await quickcommand.showInputBox(["需要处理的文本"]);
|
||||||
return values[0];
|
return payload;
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
over: {
|
over: {
|
||||||
name: "over",
|
name: "over",
|
||||||
label: "所有文本",
|
label: "所有文本",
|
||||||
matchLabel: "无需配置",
|
|
||||||
icon: "emergency",
|
icon: "emergency",
|
||||||
color: "light-green",
|
color: "light-green",
|
||||||
desc: "匹配主输入框的所有文本,但只有在该文本未设置对应的插件或功能时才生效",
|
desc: "匹配主输入框的所有文本,但只有在该文本未设置对应的插件或功能时才生效",
|
||||||
valueType: null,
|
|
||||||
disabledSpecialVars:
|
|
||||||
/{{SelectFile}}|{{MatchImage}}|{{WindowInfo.*?}}|{{pwd}}|{{MatchedFiles.*?}}/g,
|
|
||||||
matchToCmds: (rules, desc) => [
|
|
||||||
{
|
|
||||||
label: desc,
|
|
||||||
type: "over",
|
|
||||||
minNum: 1,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
verify: (rules) => true,
|
|
||||||
tempPayload: async () => {
|
tempPayload: async () => {
|
||||||
let values = await quickcommand.showInputBox(["需要处理的文本"]);
|
let [payload] = await quickcommand.showInputBox(["需要处理的文本"]);
|
||||||
return values[0];
|
return payload;
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
window: {
|
window: {
|
||||||
name: "window",
|
name: "window",
|
||||||
label: "窗口",
|
label: "窗口",
|
||||||
matchLabel: "进程名",
|
|
||||||
icon: "widgets",
|
icon: "widgets",
|
||||||
color: "indigo",
|
color: "indigo",
|
||||||
desc: "匹配呼出uTools前或唤出超级面板时的活动窗口,可以获取窗口的信息或文件夹路径作为变量",
|
desc: "匹配呼出uTools前或唤出超级面板时的活动窗口,可以获取窗口的信息或文件夹路径作为变量",
|
||||||
valueType: "array",
|
|
||||||
disabledSpecialVars: /{{input}}|{{MatchImage}}|{{MatchedFiles.*?}}/g,
|
|
||||||
matchToCmds: (rules, desc) => [
|
|
||||||
{
|
|
||||||
type: "window",
|
|
||||||
label: desc,
|
|
||||||
match: {
|
|
||||||
app: rules,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
],
|
|
||||||
verify: (rules) => !window.lodashM.isEmpty(rules) || "进程名不能为空",
|
|
||||||
},
|
},
|
||||||
img: {
|
img: {
|
||||||
name: "img",
|
name: "img",
|
||||||
label: "图片",
|
label: "图片",
|
||||||
matchLabel: "无需配置",
|
|
||||||
icon: "panorama",
|
icon: "panorama",
|
||||||
color: "deep-orange",
|
color: "deep-orange",
|
||||||
desc: "匹配剪贴板的图片,并返回图片的 DataUrl",
|
desc: "匹配剪贴板的图片,并返回图片的 DataUrl",
|
||||||
valueType: null,
|
|
||||||
disabledSpecialVars:
|
|
||||||
/{{input}}|{{SelectFile}}|{{pwd}}|{{WindowInfo.*?}}|{{MatchedFiles.*?}}/g,
|
|
||||||
matchToCmds: (rules, desc) => [
|
|
||||||
{
|
|
||||||
label: desc,
|
|
||||||
type: "img",
|
|
||||||
},
|
|
||||||
],
|
|
||||||
verify: (rules) => true,
|
|
||||||
tempPayload: () =>
|
tempPayload: () =>
|
||||||
window.resolveFileToBase64(
|
window.resolveFileToBase64(
|
||||||
utools.showOpenDialog({
|
utools.showOpenDialog({
|
||||||
@ -156,23 +60,9 @@ export default {
|
|||||||
files: {
|
files: {
|
||||||
name: "files",
|
name: "files",
|
||||||
label: "文件",
|
label: "文件",
|
||||||
matchLabel: "正则",
|
|
||||||
icon: "description",
|
icon: "description",
|
||||||
color: "light-blue",
|
color: "light-blue",
|
||||||
desc: "匹配主输入框或超级面板选中的文件,可以获取复制及选中的文件信息作为变量",
|
desc: "匹配主输入框或超级面板选中的文件,可以获取复制及选中的文件信息作为变量",
|
||||||
valueType: "regex",
|
|
||||||
disabledSpecialVars:
|
|
||||||
/{{input}}|{{MatchImage}}|{{SelectFile}}|{{pwd}}|{{WindowInfo.*?}}/g,
|
|
||||||
matchToCmds: (rules, desc) => [
|
|
||||||
{
|
|
||||||
type: "files",
|
|
||||||
label: desc,
|
|
||||||
match: rules.match,
|
|
||||||
fileType: rules.fileType,
|
|
||||||
minLength: 1,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
verify: (rules) => !!rules > 0 || "正则不能为空",
|
|
||||||
tempPayload: () =>
|
tempPayload: () =>
|
||||||
window.convertFilePathToUtoolsPayload(
|
window.convertFilePathToUtoolsPayload(
|
||||||
utools.showOpenDialog({
|
utools.showOpenDialog({
|
||||||
@ -181,23 +71,4 @@ export default {
|
|||||||
})
|
})
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
professional: {
|
|
||||||
name: "professional",
|
|
||||||
label: "专业模式",
|
|
||||||
matchLabel: "json配置",
|
|
||||||
icon: "construction",
|
|
||||||
desc: "通过json格式的配置实现同时匹配关键字、窗口、文件甚至图片,或者指定文件数量、窗口类等",
|
|
||||||
valueType: "json",
|
|
||||||
disabledSpecialVars: null,
|
|
||||||
matchToCmds: (rules, desc) => JSON.parse(rules),
|
|
||||||
verify: (rules) => {
|
|
||||||
try {
|
|
||||||
JSON.parse(rules);
|
|
||||||
return true;
|
|
||||||
} catch (error) {
|
|
||||||
return "专业模式json配置错误";
|
|
||||||
}
|
|
||||||
},
|
|
||||||
jsonSample: jsonSample,
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user