适配 4.0,添加搜索面板推送功能

This commit is contained in:
fofolee
2023-08-07 01:36:35 +08:00
parent 1ef82a9682
commit bf2093f63a
4 changed files with 77 additions and 27 deletions

View File

@@ -62,6 +62,20 @@ export default defineComponent({
this.utools.whole.onPluginEnter((enter) => {
this.enterPlugin(enter);
});
this.utools.whole.onMainPush(
async ({ code, type, payload }) => {
let result = await this.runCommand(code, payload, 5000);
return result.map((x) => {
return {
text: x,
};
});
},
({ code, type, payload, option }) => {
window.quickcommand.writeClipboard(option.text);
window.utools.showNotification("已复制");
}
);
this.utools.whole.onPluginOut(() => {
this.outPlugin();
});
@@ -115,19 +129,43 @@ export default defineComponent({
this.runCommandSilently(featureCode);
});
},
runCommand(featureCode, mainInput, timeout = false) {
return new Promise((reslove, reject) => {
timeout &&
setTimeout(() => {
reslove([`超过${timeout}ms未响应`]);
}, timeout);
let command = this.utools.getDB("qc_" + featureCode);
let commandCode = command.cmd;
if (mainInput)
commandCode = commandCode.replace(/\{\{input\}\}/g, mainInput);
if (command.program === "quickcommand") {
window.runCodeInSandbox(commandCode, (stdout, stderr) => {
stderr && reslove([stderr.toString()]);
reslove(stdout);
});
} else {
let option =
command.program === "custom"
? command.customOptions
: this.programs[command.program];
option.scptarg = command.scptarg;
option.charset = command.charset;
window.runCodeFile(
commandCode,
option,
false,
(stdout, stderr) => {
stderr && reslove([stderr.toString()]);
reslove([stdout]);
},
false
);
}
});
},
runCommandSilently(featureCode) {
let command = this.utools.getDB("qc_" + featureCode);
if (command.program === "quickcommand") {
window.runCodeInSandbox(command.cmd, () => {});
} else {
let option =
command.program === "custom"
? command.customOptions
: this.programs[command.program];
option.scptarg = command.scptarg;
option.charset = command.charset;
window.runCodeFile(command.cmd, option, false, () => {});
}
this.runCommand(featureCode);
},
usageStatistics(featureCode, runTime) {
let statisticsData = this.utools.getDB("cfg_statisticsData");

View File

@@ -23,6 +23,12 @@
/>
</q-avatar>
<div class="row">
<!-- 搜索面板推送 -->
<q-checkbox
v-model="currentCommand.features.mainPush"
color="primary"
label="搜索面板推送"
/>
<div>
<!-- 说明 -->
<q-input
@@ -295,6 +301,7 @@ export default {
explain: "",
platform: ["win32", "linux", "darwin"],
icon: "",
mainPush: false,
},
},
commandTypes: commandTypes,