mirror of
https://github.com/fofolee/uTools-quickcommand.git
synced 2025-06-09 15:04:06 +08:00
适配新版本
This commit is contained in:
parent
54a9d012fa
commit
e412c405b3
@ -29,7 +29,7 @@ utools.onPluginEnter( async ({ code, type, payload }) => {
|
|||||||
}
|
}
|
||||||
// 获取资源管理器或访达当前目录
|
// 获取资源管理器或访达当前目录
|
||||||
if (cmd.includes('{{pwd}}')) {
|
if (cmd.includes('{{pwd}}')) {
|
||||||
let repl = await pwd(payload.id);
|
let repl = utools.getCurrentFolderPath().replace(/\\/g, '\\\\');
|
||||||
cmd = cmd.replace(/\{\{pwd\}\}/mg, repl)
|
cmd = cmd.replace(/\{\{pwd\}\}/mg, repl)
|
||||||
}
|
}
|
||||||
// 获取窗口信息
|
// 获取窗口信息
|
||||||
@ -92,20 +92,18 @@ function runCmd(cmd, option, output) {
|
|||||||
window.run(cmd, option, terminal, (stdout, stderr) => {
|
window.run(cmd, option, terminal, (stdout, stderr) => {
|
||||||
if (stderr) {
|
if (stderr) {
|
||||||
// 报错
|
// 报错
|
||||||
messageBox({
|
var index = utools.showMessageBox({
|
||||||
type: 'error',
|
type: 'error',
|
||||||
title: '啊嘞?!',
|
title: '啊嘞?!',
|
||||||
icon: window.logo,
|
|
||||||
message: stderr,
|
message: stderr,
|
||||||
buttons: ['转至脚本目录', '退出']
|
buttons: ['转至脚本目录', '退出']
|
||||||
}, index => {
|
|
||||||
if (index == 0) {
|
|
||||||
locate(resolve(tmpdir, `QuickCommandTempScript.${option.ext}`));
|
|
||||||
}
|
|
||||||
copyTo(stderr);
|
|
||||||
message("已复制报错信息");
|
|
||||||
utools.outPlugin();
|
|
||||||
})
|
})
|
||||||
|
if (index == 0) {
|
||||||
|
locate(resolve(tmpdir, `QuickCommandTempScript.${option.ext}`));
|
||||||
|
}
|
||||||
|
copyTo(stderr);
|
||||||
|
message("已复制报错信息");
|
||||||
|
utools.outPlugin();
|
||||||
} else if (stdout) {
|
} else if (stdout) {
|
||||||
// 有输出
|
// 有输出
|
||||||
switch (output) {
|
switch (output) {
|
||||||
@ -119,13 +117,7 @@ function runCmd(cmd, option, output) {
|
|||||||
copyTo(stdout);
|
copyTo(stdout);
|
||||||
break;
|
break;
|
||||||
case "send":
|
case "send":
|
||||||
// 暂存用户剪贴板
|
send(stdout)
|
||||||
var historyData = storeClip();
|
|
||||||
copyTo(stdout);
|
|
||||||
paste();
|
|
||||||
setTimeout(() => {
|
|
||||||
restoreClip(historyData);
|
|
||||||
}, 500);
|
|
||||||
break;
|
break;
|
||||||
case "notice":
|
case "notice":
|
||||||
// 发送系统通知
|
// 发送系统通知
|
||||||
|
@ -2,35 +2,26 @@ const fs = require('fs');
|
|||||||
const os = require('os');
|
const os = require('os');
|
||||||
const { spawn, exec, execSync } = require("child_process")
|
const { spawn, exec, execSync } = require("child_process")
|
||||||
const iconv = require('iconv-lite')
|
const iconv = require('iconv-lite')
|
||||||
const { clipboard, shell} = require('electron')
|
const { clipboard } = require('electron')
|
||||||
const robot = utools.robot
|
|
||||||
|
|
||||||
const path = require("path")
|
const path = require("path")
|
||||||
const { dialog, BrowserWindow, nativeImage } = require('electron').remote
|
|
||||||
|
|
||||||
pluginInfo = JSON.parse(fs.readFileSync(path.join(__dirname, 'plugin.json')));
|
pluginInfo = JSON.parse(fs.readFileSync(path.join(__dirname, 'plugin.json')));
|
||||||
logo = nativeImage.createFromPath(path.join(__dirname, 'logo.png'));
|
|
||||||
|
|
||||||
// fix PATH
|
// fix PATH
|
||||||
process.env.PATH += ':/usr/local/bin:/usr/local/sbin'
|
process.env.PATH += ':/usr/local/bin:/usr/local/sbin'
|
||||||
|
|
||||||
messageBox = (options,callback) => {
|
|
||||||
dialog.showMessageBox(BrowserWindow.getFocusedWindow(), options, index => {
|
|
||||||
utools.showMainWindow()
|
|
||||||
callback(index);
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
open = path => {
|
open = path => {
|
||||||
shell.openItem(path)
|
utools.shellOpenItem(path)
|
||||||
}
|
}
|
||||||
|
|
||||||
locate = path => {
|
locate = path => {
|
||||||
shell.showItemInFolder(path);
|
utools.shellShowItemInFolder(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
visit = url => {
|
visit = url => {
|
||||||
shell.openExternal(url);
|
utools.shellOpenExternal(url);
|
||||||
}
|
}
|
||||||
|
|
||||||
system = cmd => {
|
system = cmd => {
|
||||||
@ -41,6 +32,8 @@ message = msg => {
|
|||||||
utools.showNotification(msg)
|
utools.showNotification(msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
keyTap = utools.simulateKeyboardTap
|
||||||
|
|
||||||
sleep = ms => new Promise((r, j)=>setTimeout(r, ms))
|
sleep = ms => new Promise((r, j)=>setTimeout(r, ms))
|
||||||
// ------------------------
|
// ------------------------
|
||||||
|
|
||||||
@ -59,21 +52,19 @@ getBase64Ico = path => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
openFolder = options => {
|
openFolder = options => {
|
||||||
return dialog.showOpenDialogSync(BrowserWindow.getFocusedWindow(), options);
|
return utools.showOpenDialog(options);
|
||||||
}
|
}
|
||||||
|
|
||||||
saveFile = (options, content) => {
|
saveFile = (options, content) => {
|
||||||
dialog.showSaveDialog(BrowserWindow.getFocusedWindow(), options, filename => {
|
var filename = utools.showSaveDialog(options)
|
||||||
filename && fs.writeFile(filename, content, 'utf8', err => {
|
filename && fs.writeFile(filename, content, 'utf8', err => {
|
||||||
err && console.log(err)
|
err && console.log(err)
|
||||||
})
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
copy = () => {
|
copy = () => {
|
||||||
var ctlKey = isWin ? 'control' : 'command';
|
var ctlKey = isWin ? 'control' : 'command';
|
||||||
robot.keyTap('c', ctlKey);
|
utools.simulateKeyboardTap('c', ctlKey);
|
||||||
robot.setKeyboardDelay(20);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
copyTo = text => {
|
copyTo = text => {
|
||||||
@ -82,9 +73,19 @@ copyTo = text => {
|
|||||||
|
|
||||||
paste = () => {
|
paste = () => {
|
||||||
var ctlKey = isWin ? 'control' : 'command';
|
var ctlKey = isWin ? 'control' : 'command';
|
||||||
robot.keyTap('v', ctlKey);
|
utools.simulateKeyboardTap('v', ctlKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
send = text => {
|
||||||
|
var historyData = storeClip();
|
||||||
|
copyTo(text);
|
||||||
|
paste();
|
||||||
|
setTimeout(() => {
|
||||||
|
restoreClip(historyData);
|
||||||
|
}, 500);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// 保存剪贴板
|
// 保存剪贴板
|
||||||
storeClip = () => {
|
storeClip = () => {
|
||||||
var formats = clipboard.availableFormats("clipboard");
|
var formats = clipboard.availableFormats("clipboard");
|
||||||
@ -160,26 +161,26 @@ getSelectFile = hwnd =>
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
pwd = hwnd =>
|
// pwd = hwnd =>
|
||||||
new Promise((reslove, reject) => {
|
// new Promise((reslove, reject) => {
|
||||||
if (isWin) {
|
// if (isWin) {
|
||||||
var cmd = `powershell.exe -NoProfile "((New-Object -COM 'Shell.Application').Windows() | Where-Object { $_.HWND -eq (${hwnd}) } | Select-Object -Expand LocationURL).replace('file:///','')"`;
|
// var cmd = `powershell.exe -NoProfile "((New-Object -COM 'Shell.Application').Windows() | Where-Object { $_.HWND -eq (${hwnd}) } | Select-Object -Expand LocationURL).replace('file:///','')"`;
|
||||||
exec(cmd, { encoding: "buffer" }, (err, stdout, stderr) => {
|
// exec(cmd, { encoding: "buffer" }, (err, stdout, stderr) => {
|
||||||
if (err) {
|
// if (err) {
|
||||||
console.log(iconv.decode(stderr, 'GBK'));
|
// console.log(iconv.decode(stderr, 'GBK'));
|
||||||
reslove(`${os.homedir().replace(/\\/g, '/')}/Desktop`)
|
// reslove(`${os.homedir().replace(/\\/g, '/')}/Desktop`)
|
||||||
} else {
|
// } else {
|
||||||
reslove(decodeURIComponent(iconv.decode(stdout, 'GBK').trim()));
|
// reslove(decodeURIComponent(iconv.decode(stdout, 'GBK').trim()));
|
||||||
}
|
// }
|
||||||
});
|
// });
|
||||||
} else {
|
// } else {
|
||||||
var cmd = `osascript -e 'tell application "Finder" to get the POSIX path of (target of front window as alias)'`
|
// var cmd = `osascript -e 'tell application "Finder" to get the POSIX path of (target of front window as alias)'`
|
||||||
exec(cmd, (err, stdout, stderr) => {
|
// exec(cmd, (err, stdout, stderr) => {
|
||||||
if (err) reject(stderr)
|
// if (err) reject(stderr)
|
||||||
reslove(stdout.trim());
|
// reslove(stdout.trim());
|
||||||
});
|
// });
|
||||||
}
|
// }
|
||||||
});
|
// });
|
||||||
|
|
||||||
special = cmd => {
|
special = cmd => {
|
||||||
// 判断是否 windows 系统
|
// 判断是否 windows 系统
|
||||||
|
Loading…
x
Reference in New Issue
Block a user