适配 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

@ -14,7 +14,8 @@
"pluginSetting": {
"single": false
},
"features": [{
"features": [
{
"code": "configuration",
"explain": "创建或编辑快捷命令",
"cmds": [

View File

@ -569,7 +569,7 @@ window.runCodeInSandbox = (code, callback, addVars = {}) => {
}
}
window.runCodeFile = (cmd, option, terminal, callback) => {
window.runCodeFile = (cmd, option, terminal, callback, realTime=true) => {
let {
bin,
argv,
@ -612,24 +612,28 @@ window.runCodeFile = (cmd, option, terminal, callback) => {
shell: true,
env: processEnv
});
// var chunks = [],
// err_chunks = [];
let chunks = [], err_chunks = [];
console.log('Running: ' + cmdline);
child.stdout.on('data', chunk => {
if (charset.outputCode) chunk = iconv.decode(chunk, charset.outputCode);
callback(chunk.toString(), null);
// chunks.push(chunk)
realTime
? callback(chunk.toString(), null)
: chunks.push(chunk);
});
child.stderr.on('data', stderr => {
if (charset.outputCode) stderr = iconv.decode(stderr, charset.outputCode);
callback(null, stderr.toString());
// err_chunks.push(err_chunk)
child.stderr.on("data", (err_chunk) => {
if (charset.outputCode)
err_chunk = iconv.decode(err_chunk, charset.outputCode);
realTime
? callback(null, err_chunk.toString())
: err_chunks.push(err_chunk);
});
// child.on('close', code => {
// let stdout = chunks.join("");
// let stderr = err_chunks.join("");
// callback(stdout, stderr)
// })
if (!realTime) {
child.on('close', code => {
let stdout = chunks.join("");
let stderr = err_chunks.join("");
callback(stdout, stderr)
})
}
return child
}

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,