diff --git a/public/preload.js b/public/preload.js
index fd96912..d6e4ad0 100644
--- a/public/preload.js
+++ b/public/preload.js
@@ -358,6 +358,16 @@ let parseItem = item => {
return item.toString()
}
+convertFilePathToUtoolsPayload = files => files.map(file => {
+ let isFile = fs.statSync(file).isFile()
+ return {
+ isFile: isFile,
+ isDirectory: !isFile,
+ name: path.basename(file),
+ path: file
+ }
+})
+
let parseStdout = stdout => stdout.map(x => parseItem(x)).join("\n")
VmEval = (cmd, sandbox = {}) => new VM({
@@ -503,7 +513,7 @@ getQuickcommandTempFile = ext => {
return path.join(os.tmpdir(), `quickcommandTempFile.${ext}`)
}
-getBase64Ico = async filepath => {
+getBase64Ico = async (filepath, compressed = true) => {
let sourceImage, ext = path.extname(filepath).slice(1)
if (['png', 'jpg', 'jpeg', 'bmp', 'ico', 'gif', 'svg'].includes(ext)) {
if (ext == 'svg') ext = 'svg+xml'
@@ -513,6 +523,7 @@ getBase64Ico = async filepath => {
sourceImage = utools.getFileIcon(filepath)
return sourceImage
}
+ if (!compressed) return sourceImage
let compressedImage = await getCompressedIco(sourceImage)
return compressedImage
}
diff --git a/src/components/CommandEditor.vue b/src/components/CommandEditor.vue
index 127f43f..488d697 100644
--- a/src/components/CommandEditor.vue
+++ b/src/components/CommandEditor.vue
@@ -146,7 +146,7 @@
}"
/>
-
+
@@ -182,10 +182,6 @@ export default {
isRunCodePage: this.action.type === "run",
parent: this.$parent.$parent.$parent.$parent,
commandString: this.$q.platform.is.mac ? "⌘" : "ctrl",
- runResultAction: {
- type: "inPlugin",
- data: {},
- },
};
},
props: {
diff --git a/src/components/CommandRunResult.vue b/src/components/CommandRunResult.vue
index 2b7a8e1..a7d247b 100644
--- a/src/components/CommandRunResult.vue
+++ b/src/components/CommandRunResult.vue
@@ -16,10 +16,11 @@
>
-
+ >
import outputTypes from "../js/options/outputTypes.js";
import specialVars from "../js/options/specialVars.js";
+import commandTypes from "../js/options/commandTypes.js";
export default {
data() {
@@ -62,6 +64,13 @@ export default {
};
},
props: {
+ /**
+ * run: 「RunCode界面」 无侧栏,运行结果弹窗显示,保存命令历史
+ * edit: 「编辑命令界面』 有侧栏,运行结果弹窗显示
+ * new: 『新建命令界面」 有侧栏,运行结果弹窗显示
+ * config: 「配置界面』 运行结果弹窗显示,需要对payload临时赋值
+ * input: 『主输入框进入」 运行结果直接展示,动态调整窗体高度
+ */
action: Object,
},
mounted() {
@@ -69,19 +78,22 @@ export default {
},
computed: {
fromUtools() {
- return this.action.type !== "inPlugin";
+ return this.action.type === "input";
+ },
+ needTempPayload() {
+ return this.action.type === "config";
},
},
methods: {
// 运行命令
- runCurrentCommand(currentCommand) {
+ async runCurrentCommand(currentCommand) {
+ await this.getTempPayload(currentCommand);
if (currentCommand.cmd.includes("{{subinput"))
return this.setSubInput(currentCommand);
this.fire(currentCommand);
},
async fire(currentCommand) {
currentCommand.cmd = this.assignSpecialVars(currentCommand.cmd);
- // currentCommand.cmd = await this.replaceTempInputVars(currentCommand.cmd);
let { hideWindow, outPlugin, action } =
outputTypes[currentCommand.output];
// 需要隐藏的提前隐藏窗口
@@ -150,31 +162,15 @@ export default {
};
document.addEventListener("keydown", this.$profile.tmp.handleEnter);
},
- // 替换特殊变量
- async replaceTempInputVars(cmd) {
- let tempInputVals = [];
- let needInputVal = [
- "input",
- "subinput",
- "pwd",
- // "SelectFile",
- "WindowInfo",
- "MatchedFiles",
- ];
- needInputVal.forEach((x) => {
- let m = cmd.match(new RegExp("{{" + x + ".*?}}", "g"));
- m &&
- m.forEach((y) => tempInputVals.includes(y) || tempInputVals.push(y));
- });
- if (!tempInputVals.length) return cmd;
- let inputs = await quickcommand.showInputBox(
- tempInputVals,
- "需要临时为以下变量赋值"
- );
- tempInputVals.forEach((t, n) => {
- cmd = cmd.replace(new RegExp(t, "g"), inputs[n]);
- });
- return cmd;
+ // payload 临时赋值
+ async getTempPayload(currentCommand) {
+ if (!this.needTempPayload) return;
+ let cmd = currentCommand.features.cmds[0];
+ let type = cmd.type;
+ quickcommand.enterData = {
+ type: cmd.type || "text",
+ payload: (await commandTypes[type]?.tempPayload?.()) || cmd,
+ };
},
// 显示运行结果
showRunResult(content, isSuccess, action) {
diff --git a/src/js/options/commandTypes.js b/src/js/options/commandTypes.js
index 39bd431..7637dc3 100644
--- a/src/js/options/commandTypes.js
+++ b/src/js/options/commandTypes.js
@@ -2,6 +2,8 @@
* 所有的匹配类型
*/
+
+
const jsonSample = [
"关键词",
{
@@ -72,7 +74,11 @@ const commandTypes = {
match: rules,
minNum: 1,
}, ],
- verify: rules => !!rules > 0 || "正则不能为空"
+ verify: rules => !!rules > 0 || "正则不能为空",
+ tempPayload: async() => {
+ let values = await quickcommand.showInputBox(["需要处理的文本"])
+ return values[0]
+ }
},
over: {
name: "over",
@@ -87,7 +93,11 @@ const commandTypes = {
type: "over",
minNum: 1,
}],
- verify: rules => true
+ verify: rules => true,
+ tempPayload: async() => {
+ let values = await quickcommand.showInputBox(["需要处理的文本"])
+ return values[0]
+ }
},
window: {
name: "window",
@@ -104,21 +114,33 @@ const commandTypes = {
"app": rules
}
}],
- verify: rules => !_.isEmpty(rules) || "进程名不能为空"
+ verify: rules => !_.isEmpty(rules) || "进程名不能为空",
},
img: {
name: "img",
label: "图片",
matchLabel: "无需配置",
icon: "panorama",
- desc: "匹配主输入框或超级面板选中的图片,并返回图片的 base64",
+ desc: "匹配主输入框或超级面板选中的图片,并返回图片的 DataUrl",
valueType: null,
disabledSpecialVars: /{{input}}|{{SelectFile}}|{{pwd}}|{{WindowInfo.*?}}|{{MatchedFiles.*?}}/g,
matchToCmds: (rules, desc) => [{
label: desc,
type: "img",
}],
- verify: rules => true
+ verify: rules => true,
+ tempPayload: () => window.getBase64Ico(utools.showOpenDialog({
+ title: "需要处理的文件",
+ filters: [{
+ name: 'Images',
+ extensions: ['png',
+ 'jpg',
+ 'jpeg',
+ 'bmp',
+ 'gif',
+ ]
+ }]
+ })[0])
},
files: {
name: "files",
@@ -134,7 +156,11 @@ const commandTypes = {
match: rules,
"minLength": 1,
}, ],
- verify: rules => !!rules > 0 || "正则不能为空"
+ verify: rules => !!rules > 0 || "正则不能为空",
+ tempPayload: () => window.convertFilePathToUtoolsPayload(utools.showOpenDialog({
+ title: "需要处理的文件",
+ properties: ['openFile', 'openDirectory', 'multiSelections']
+ }))
},
professional: {
diff --git a/src/pages/CommandPage.vue b/src/pages/CommandPage.vue
index b6f5e49..d7c2063 100644
--- a/src/pages/CommandPage.vue
+++ b/src/pages/CommandPage.vue
@@ -12,7 +12,7 @@ export default {
data() {
return {
action: {
- type: "fromUtools",
+ type: "input",
data: {},
},
featureCode: this.$route.path.slice(1),
diff --git a/src/pages/ConfigurationPage.vue b/src/pages/ConfigurationPage.vue
index 781ad0f..6a13b40 100644
--- a/src/pages/ConfigurationPage.vue
+++ b/src/pages/ConfigurationPage.vue
@@ -188,7 +188,7 @@