mirror of
https://github.com/fofolee/uTools-quickcommand.git
synced 2025-10-09 15:03:21 +08:00
新增quickcommand.runCode,quickcommand.runInTerminal支持warp
This commit is contained in:
@@ -159,7 +159,7 @@ export default {
|
||||
this.childProcess = window.runCodeFile(
|
||||
currentCommand.cmd,
|
||||
this.getCommandOpt(currentCommand),
|
||||
currentCommand.output === "terminal",
|
||||
currentCommand.output === "terminal" ? {} : false,
|
||||
(stdout, stderr) => this.handleResult(stdout, stderr, resultOpts)
|
||||
);
|
||||
this.listenStopSign();
|
||||
|
@@ -36,6 +36,7 @@ import ButtonBox from "components/quickcommandUI/ButtonBox";
|
||||
import ConfirmBox from "components/quickcommandUI/ConfirmBox";
|
||||
import TextArea from "components/quickcommandUI/TextArea";
|
||||
import SelectList from "components/quickcommandUI/SelectList";
|
||||
import programs from "js/options/programs";
|
||||
|
||||
export default {
|
||||
components: {
|
||||
@@ -256,8 +257,26 @@ export default {
|
||||
});
|
||||
},
|
||||
};
|
||||
// 将quickcommandUI添加到quickcommand
|
||||
Object.assign(window.quickcommand, quickcommandUI);
|
||||
|
||||
// 获取用户数据
|
||||
window.quickcommand.userData = this.$root.utools.userData;
|
||||
|
||||
// 添加runCode方法,不在preload中加是因为programs写在了src中-_-
|
||||
quickcommand.runCode = (code, program, runInTerminal = false) => {
|
||||
return new Promise((reslove, reject) => {
|
||||
window.runCodeFile(
|
||||
code,
|
||||
{ ...programs[program], charset: {}, scptarg: "" },
|
||||
runInTerminal,
|
||||
(result, err) => (err ? reject(err) : reslove(result))
|
||||
);
|
||||
false;
|
||||
});
|
||||
};
|
||||
|
||||
// 冻结quickcommand
|
||||
Object.freeze(quickcommand);
|
||||
},
|
||||
methods: {
|
||||
|
@@ -17,7 +17,7 @@ import { imageCommands } from "./imageCommands";
|
||||
import { windowsCommands } from "./windowsCommands";
|
||||
import { statusCommands } from "./statusCommands";
|
||||
import { macosCommands } from "./macosCommands";
|
||||
|
||||
import { scriptCommands } from "./scriptCommands";
|
||||
let commands = [
|
||||
fileCommands,
|
||||
networkCommands,
|
||||
@@ -30,6 +30,7 @@ let commands = [
|
||||
dataCommands,
|
||||
codingCommands,
|
||||
controlCommands,
|
||||
scriptCommands,
|
||||
uiCommands,
|
||||
simulateCommands,
|
||||
mathCommands,
|
||||
|
53
src/js/composer/commands/scriptCommands.js
Normal file
53
src/js/composer/commands/scriptCommands.js
Normal file
@@ -0,0 +1,53 @@
|
||||
export const scriptCommands = {
|
||||
label: "编程相关",
|
||||
icon: "integration_instructions",
|
||||
commands: [
|
||||
{
|
||||
value: "",
|
||||
label: "赋值",
|
||||
icon: "script",
|
||||
outputVariable: "value",
|
||||
saveOutput: true,
|
||||
config: [
|
||||
{
|
||||
label: "值或表达式",
|
||||
component: "VariableInput",
|
||||
width: 12,
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
value: "(function(code){new Function(code)()})",
|
||||
label: "注入JS脚本",
|
||||
icon: "script",
|
||||
config: [
|
||||
{
|
||||
label: "JS脚本",
|
||||
component: "CodeEditor",
|
||||
width: 12,
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
value: "quickcommand.runAppleScript",
|
||||
label: "执行 AppleScript",
|
||||
icon: "script",
|
||||
outputVariable: "result",
|
||||
saveOutput: true,
|
||||
config: [
|
||||
{
|
||||
label: "脚本",
|
||||
component: "CodeEditor",
|
||||
width: 12,
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
value: "quickcommand.runCsharp",
|
||||
label: "执行C#脚本",
|
||||
icon: "script",
|
||||
outputVariable: "result",
|
||||
saveOutput: true,
|
||||
},
|
||||
],
|
||||
};
|
52
src/plugins/monaco/types/quickcommand.api.d.ts
vendored
52
src/plugins/monaco/types/quickcommand.api.d.ts
vendored
@@ -378,11 +378,23 @@ interface quickcommandApi {
|
||||
* 在终端运行,不支持 Linux
|
||||
*
|
||||
* @param command 要在终端运行的命令
|
||||
* @param options 终端运行参数
|
||||
* @param options.dir 运行目录
|
||||
* @param options.windows 终端类型,默认wt
|
||||
* @param options.macos 终端类型,默认warp
|
||||
*
|
||||
* ```js
|
||||
* quickcommand.runInTerminal(`whoami`)
|
||||
* ```
|
||||
*/
|
||||
runInTerminal(command: string);
|
||||
runInTerminal(
|
||||
command: string,
|
||||
options?: {
|
||||
dir?: string;
|
||||
windows?: "wt" | "cmd";
|
||||
macos?: "warp" | "iterm" | "terminal";
|
||||
}
|
||||
);
|
||||
|
||||
/**
|
||||
* 对应 utools.onPluginEnter 的 `code` `type` 和 `payload`
|
||||
@@ -597,6 +609,44 @@ interface quickcommandApi {
|
||||
defaultText?: string,
|
||||
title?: string
|
||||
): Promise<string | null>;
|
||||
|
||||
/**
|
||||
* 运行代码
|
||||
* @param code 代码
|
||||
* @param program 编程语言
|
||||
* @param runInTerminal 终端运行参数,不传则不在终端运行
|
||||
* @param runInTerminal.dir 运行目录
|
||||
* @param runInTerminal.windows windows使用的终端,默认wt
|
||||
* @param runInTerminal.macos macos使用的终端,默认warp
|
||||
*
|
||||
* 支持的编程语言:
|
||||
* shell, applescript, cmd, python, powershell, javascript, ruby, php, lua, perl, csharp, c
|
||||
*
|
||||
* ```js
|
||||
* quickcommand.runCode("print('Hello, World!');", "python");
|
||||
* ```
|
||||
*/
|
||||
runCode(
|
||||
code: string,
|
||||
program:
|
||||
| "shell"
|
||||
| "applescript"
|
||||
| "cmd"
|
||||
| "python"
|
||||
| "powershell"
|
||||
| "javascript"
|
||||
| "ruby"
|
||||
| "php"
|
||||
| "lua"
|
||||
| "perl"
|
||||
| "csharp"
|
||||
| "c",
|
||||
runInTerminal?: {
|
||||
dir?: string;
|
||||
windows?: "wt" | "cmd";
|
||||
macos?: "warp" | "iterm" | "terminal";
|
||||
}
|
||||
): Promise<string>;
|
||||
}
|
||||
|
||||
declare var quickcommand: quickcommandApi;
|
||||
|
Reference in New Issue
Block a user