From 73c5dbaceecc971151684a723bf84a9c97d3f55f Mon Sep 17 00:00:00 2001 From: fofolee Date: Sun, 10 Apr 2022 00:38:56 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84=E6=89=A7=E8=A1=8C=E5=91=BD?= =?UTF-8?q?=E4=BB=A4=E5=8A=9F=E8=83=BD=2090%?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- public/preload.js | 83 ++++++++-------------- src/components/CommandCard.vue | 15 ++-- src/components/CommandEditor.vue | 2 +- src/components/CommandMenu.vue | 11 +-- src/components/CommandRunResult.vue | 19 +++-- src/js/options/commandTypes.js | 106 ++++++++++++++-------------- src/js/options/specialVars.js | 87 +++++++++++++++++++---- src/pages/CommandPage.vue | 2 +- src/pages/ConfigurationPage.vue | 15 ++++ 9 files changed, 200 insertions(+), 140 deletions(-) diff --git a/public/preload.js b/public/preload.js index 4a61a7a..16d4e0c 100644 --- a/public/preload.js +++ b/public/preload.js @@ -255,10 +255,6 @@ let getSleepCodeByShell = ms => { return cmd } -let modWindowHeight = height => { - $('#options').is(':hidden') && utools.setExpendHeight(height > 600 ? 600 : height); -} - // 屏蔽危险函数 getuToolsLite = () => { var utoolsLite = Object.assign({}, utools) @@ -564,6 +560,16 @@ getCurrentFolderPathFix = () => { return pwdFix.replace(/\\/g, '\\\\') } +getMatchedFilesFix = payload => { + let MatchedFiles = payload + let Matched = cmd.match(/\{\{MatchedFiles(\[\d+\]){0,1}(\.\w{1,11}){0,1}\}\}/g) + Matched && Matched.forEach(m => { + repl = eval(m.slice(2, -2)) + typeof repl == 'object' ? (repl = JSON.stringify(repl)) : (repl = repl.replace('\\', '\\\\')) + cmd = cmd.replace(m, repl.replace('$', '$$$')) + }) +} + saveFile = (content, file) => { if (file instanceof Object) { file = utools.showSaveDialog(file) @@ -580,18 +586,16 @@ yuQueClient = axios.create({ } }); -getSelectFile = hwnd => - new Promise((reslove, reject) => { - if (utools.isWindows()) { - var cmd = `powershell.exe -NoProfile "(New-Object -COM 'Shell.Application').Windows() | Where-Object { $_.HWND -eq ${hwnd} } | Select-Object -Expand Document | select @{ n='SelectItems'; e={$_.SelectedItems()} } | select -Expand SelectItems | select -Expand Path "`; - child_process.exec(cmd, { - encoding: "buffer" - }, (err, stdout, stderr) => { - if (err) reject(stderr) - else reslove(iconv.decode(stdout, 'GBK').trim().replace(/\\/g, '/')); - }) - } else { - var cmd = `osascript -e 'tell application "Finder" to set selectedItems to selection as alias list +getSelectFile = hwnd => { + if (utools.isWindows()) { + var cmd = `powershell.exe -NoProfile "(New-Object -COM 'Shell.Application').Windows() | Where-Object { $_.HWND -eq ${hwnd} } | Select-Object -Expand Document | select @{ n='SelectItems'; e={$_.SelectedItems()} } | select -Expand SelectItems | select -Expand Path "`; + let result = child_process.execSync(cmd, { + encoding: "buffer", + windowsHide: true + }) + return iconv.decode(result, 'GBK').trim().replace(/\\/g, '/'); + } else { + var cmd = `osascript -e 'tell application "Finder" to set selectedItems to selection as alias list if selectedItems is {} then return set parentPath to do shell script "dirname " & quoted form of POSIX path of (item 1 of selectedItems) set pathData to "" @@ -600,45 +604,16 @@ getSelectFile = hwnd => end repeat ' ` - child_process.exec(cmd, (err, stdout, stderr) => { - if (err) reject(stderr) - else reslove(stdout.trim()); - }); - } - }) - -clipboardReadText = () => { - return electron.clipboard.readText() - }, - - special = cmd => { - // 判断是否 windows 系统 - if (cmd.includes('{{isWin}}')) { - let repl = utools.isWindows() ? 1 : 0; - cmd = cmd.replace(/\{\{isWin\}\}/mg, repl) - } - // 获取本机唯一ID - if (cmd.includes('{{LocalId}}')) { - let repl = utools.getNativeId(); - cmd = cmd.replace(/\{\{LocalId\}\}/mg, repl) - } - // 获取浏览器当前链接 - if (cmd.includes('{{BrowserUrl}}')) { - let repl = utools.getCurrentBrowserUrl(); - cmd = cmd.replace(/\{\{BrowserUrl\}\}/mg, repl) - } - // 获取剪切板的文本 - if (cmd.includes('{{ClipText}}')) { - let repl = clipboardReadText(); - cmd = cmd.replace(/\{\{ClipText\}\}/mg, repl) - } - // 获取选中的文本 - // if (cmd.includes('{{SelectText}}')) { - // let repl = getSelectText(); - // cmd = cmd.replace(/\{\{SelectText\}\}/mg, repl) - // } - return cmd; + let result = child_process.execSync(cmd, { + encoding: "utf8", + windowsHide: true + }) + console.log(result); + return result ? result.trim() : "" } +} + +clipboardReadText = () => electron.clipboard.readText() runCodeFile = (cmd, option, terminal, callback) => { var bin = option.bin, diff --git a/src/components/CommandCard.vue b/src/components/CommandCard.vue index f81a7b7..ae17cbe 100644 --- a/src/components/CommandCard.vue +++ b/src/components/CommandCard.vue @@ -108,10 +108,9 @@ {{ getShortStrByByte(cmd) }}{{ + getShortStrByByte(cmd) + }}
@@ -302,9 +301,11 @@ export default { }, // 运行命令 runCommand() { - utools.redirect( - this.commandInfo.features.cmds.filter((x) => x.length)[0] - ); + let event = { + type: "run", + data: this.commandInfo.features.code, + }; + this.$emit("commandChanged", event); }, // 启用/禁用命令 toggleCommandActivated() { diff --git a/src/components/CommandEditor.vue b/src/components/CommandEditor.vue index 2a6971e..127f43f 100644 --- a/src/components/CommandEditor.vue +++ b/src/components/CommandEditor.vue @@ -361,7 +361,7 @@ export default { // 如果 action 是 run 则输出一律为 text this.quickcommandInfo.output = this.$refs.menu?.currentCommand.output || "text"; - this.$refs.result.runCurrentCommand(this.quickcommandInfo); + this.$refs.result.runCurrentCommand(_.cloneDeep(this.quickcommandInfo)); }, }, }; diff --git a/src/components/CommandMenu.vue b/src/components/CommandMenu.vue index f449f04..470a721 100644 --- a/src/components/CommandMenu.vue +++ b/src/components/CommandMenu.vue @@ -165,13 +165,8 @@ - - 注意需要自行在变量两边加上引号,如"{{ scope.opt.label }}" - - - 需要自行对json进行处理,如json.loads(r"""{{ - scope.opt.label - }}""") + + {{ scope.opt.tooltip }} {{ scope.opt.desc }} @@ -337,7 +332,7 @@ export default { this.cmdMatch = `/${this.cmdMatch}/`; }, insertSpecialVar(text) { - this.$parent.$refs.editor.repacleEditorSelection(text); + this.$parent.$refs.editor.repacleEditorSelection(`'${text}'`); }, // 保存各类数据 SaveMenuData() { diff --git a/src/components/CommandRunResult.vue b/src/components/CommandRunResult.vue index 397caec..b6c1609 100644 --- a/src/components/CommandRunResult.vue +++ b/src/components/CommandRunResult.vue @@ -44,6 +44,7 @@