mirror of
https://github.com/fofolee/uTools-quickcommand.git
synced 2025-12-20 02:47:30 +08:00
增加模拟按键的功能
This commit is contained in:
69
src/assets/index.js
Executable file → Normal file
69
src/assets/index.js
Executable file → Normal file
@@ -10,18 +10,14 @@ utools.onPluginEnter( async ({ code, type, payload }) => {
|
||||
$("#out").show().text('');
|
||||
var db = utools.db.get('customFts').data[code],
|
||||
cmd = db.cmd;
|
||||
if (db.robotjs) {
|
||||
utools.setExpendHeight(0);
|
||||
utools.hideMainWindow();
|
||||
eval(cmd);
|
||||
utools.outPlugin();
|
||||
return;
|
||||
}
|
||||
if (db.program == "custom") {
|
||||
option = db.customOptions;
|
||||
} else {
|
||||
} else if(db.program == "simulation"){
|
||||
option = "simulation";
|
||||
}else{
|
||||
option = programs[db.program];
|
||||
}
|
||||
cmd = await special(cmd);
|
||||
// 正则
|
||||
if (type == 'regex') cmd = cmd.replace(/\{\{input\}\}/mg, payload);
|
||||
// 窗口
|
||||
@@ -58,7 +54,7 @@ utools.onPluginEnter( async ({ code, type, payload }) => {
|
||||
if (event.keyCode == 13) {
|
||||
$("#out").text('');
|
||||
var execmd = cmd.replace(/\{\{subinput\}\}/mg, subinput);
|
||||
runCmd(execmd, option, db.codec, db.output);
|
||||
runCmd(execmd, option, db.output);
|
||||
}
|
||||
};
|
||||
setSubInput();
|
||||
@@ -68,40 +64,47 @@ utools.onPluginEnter( async ({ code, type, payload }) => {
|
||||
document.removeEventListener('keydown', handleEnter);
|
||||
})
|
||||
} else {
|
||||
runCmd(cmd, option, db.codec, db.output);
|
||||
runCmd(cmd, option, db.output);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
function runCmd(cmd, option, codec, output) {
|
||||
function runCmd(cmd, option, output) {
|
||||
if (option == "simulation") {
|
||||
utools.setExpendHeight(0);
|
||||
// utools.hideMainWindow();
|
||||
eval(`(async () => {
|
||||
${cmd}
|
||||
})()`);
|
||||
utools.outPlugin();
|
||||
return;
|
||||
}
|
||||
// 不需要输出的,提前关闭窗口
|
||||
if (['ignore', 'clip', 'send', 'notice', 'terminal'].indexOf(output) !== -1) {
|
||||
utools.hideMainWindow()
|
||||
utools.setExpendHeight(0);
|
||||
utools.outPlugin();
|
||||
// utools.hideMainWindow();
|
||||
}
|
||||
var terminal = false;
|
||||
if(output == 'terminal') terminal = true;
|
||||
// 运行脚本
|
||||
window.run(cmd, option, codec, terminal, (stdout, stderr) => {
|
||||
window.run(cmd, option, terminal, (stdout, stderr) => {
|
||||
if (stderr) {
|
||||
// 报错
|
||||
utools.showMainWindow()
|
||||
Swal.fire({
|
||||
messageBox({
|
||||
type: 'error',
|
||||
title: '啊嘞?!',
|
||||
text: stderr,
|
||||
icon: 'error',
|
||||
showCancelButton: true,
|
||||
confirmButtonColor: '#3085d6',
|
||||
cancelButtonColor: '#d33',
|
||||
confirmButtonText: '转至脚本目录',
|
||||
cancelButtonText: '退出',
|
||||
}).then((result) => {
|
||||
if (result.value) {
|
||||
open(resolve(tmpdir, `QuickCommandTempScript.${option.ext}`));
|
||||
}
|
||||
copyTo(stderr);
|
||||
utools.showNotification("已复制报错信息");
|
||||
utools.outPlugin();
|
||||
})
|
||||
icon: window.logo,
|
||||
message: stderr,
|
||||
buttons: ['转至脚本目录', '退出']
|
||||
}, index => {
|
||||
if (index == 0) {
|
||||
locate(resolve(tmpdir, `QuickCommandTempScript.${option.ext}`));
|
||||
}
|
||||
copyTo(stderr);
|
||||
message("已复制报错信息");
|
||||
utools.outPlugin();
|
||||
})
|
||||
} else if (stdout) {
|
||||
// 有输出
|
||||
switch (output) {
|
||||
@@ -113,7 +116,6 @@ function runCmd(cmd, option, codec, output) {
|
||||
break;
|
||||
case "clip":
|
||||
copyTo(stdout);
|
||||
utools.outPlugin();
|
||||
break;
|
||||
case "send":
|
||||
// 暂存用户剪贴板
|
||||
@@ -123,15 +125,12 @@ function runCmd(cmd, option, codec, output) {
|
||||
setTimeout(() => {
|
||||
restoreClip(historyData);
|
||||
}, 500);
|
||||
utools.outPlugin();
|
||||
break;
|
||||
case "notice":
|
||||
// 发送系统通知
|
||||
utools.showNotification(stdout);
|
||||
utools.outPlugin();
|
||||
message(stdout);
|
||||
break;
|
||||
case "ignore":
|
||||
utools.outPlugin();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user