mirror of
https://github.com/fofolee/uTools-quickcommand.git
synced 2025-06-08 22:51:25 +08:00
添加async支持
This commit is contained in:
parent
e1c31de4c1
commit
5f44e1dd2c
@ -50,12 +50,14 @@ export const commandCategories = [
|
||||
value: "utools.ubrowser.goto",
|
||||
label: "用ubrowser打开网址",
|
||||
desc: "要访问的网址链接",
|
||||
isAsync: true,
|
||||
},
|
||||
{
|
||||
value: "ubrowser",
|
||||
label: "UBrowser浏览器操作",
|
||||
desc: "配置UBrowser浏览器操作",
|
||||
hasUBrowserEditor: true,
|
||||
isAsync: true,
|
||||
},
|
||||
],
|
||||
},
|
||||
|
@ -1,21 +1,30 @@
|
||||
export function generateCode(commandFlow) {
|
||||
let code = [];
|
||||
// 检查是否包含异步函数
|
||||
const hasAsyncFunction = commandFlow.some((cmd) => cmd.isAsync);
|
||||
|
||||
let code = hasAsyncFunction ? ["async function run() {"] : [];
|
||||
const indent = hasAsyncFunction ? " " : "";
|
||||
|
||||
commandFlow.forEach((cmd) => {
|
||||
let line = "";
|
||||
let line = indent;
|
||||
|
||||
if (cmd.outputVariable) {
|
||||
line += `let ${cmd.outputVariable} = `;
|
||||
}
|
||||
|
||||
if (cmd.value === "ubrowser") {
|
||||
line += cmd.argv;
|
||||
line += `await ${cmd.argv}`;
|
||||
} else {
|
||||
line += `${cmd.value}(${cmd.argv})`;
|
||||
line += `${cmd.isAsync ? "await " : ""}${cmd.value}(${cmd.argv})`;
|
||||
}
|
||||
|
||||
code.push(line);
|
||||
});
|
||||
|
||||
if (hasAsyncFunction) {
|
||||
code.push("}"); // Close the async function
|
||||
code.push("run();"); // Call the function
|
||||
}
|
||||
|
||||
return code.join("\n");
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user