适配 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": { "pluginSetting": {
"single": false "single": false
}, },
"features": [{ "features": [
{
"code": "configuration", "code": "configuration",
"explain": "创建或编辑快捷命令", "explain": "创建或编辑快捷命令",
"cmds": [ "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 { let {
bin, bin,
argv, argv,
@ -612,24 +612,28 @@ window.runCodeFile = (cmd, option, terminal, callback) => {
shell: true, shell: true,
env: processEnv env: processEnv
}); });
// var chunks = [], let chunks = [], err_chunks = [];
// err_chunks = [];
console.log('Running: ' + cmdline); console.log('Running: ' + cmdline);
child.stdout.on('data', chunk => { child.stdout.on('data', chunk => {
if (charset.outputCode) chunk = iconv.decode(chunk, charset.outputCode); if (charset.outputCode) chunk = iconv.decode(chunk, charset.outputCode);
callback(chunk.toString(), null); realTime
// chunks.push(chunk) ? callback(chunk.toString(), null)
: chunks.push(chunk);
}); });
child.stderr.on('data', stderr => { child.stderr.on("data", (err_chunk) => {
if (charset.outputCode) stderr = iconv.decode(stderr, charset.outputCode); if (charset.outputCode)
callback(null, stderr.toString()); err_chunk = iconv.decode(err_chunk, charset.outputCode);
// err_chunks.push(err_chunk) realTime
? callback(null, err_chunk.toString())
: err_chunks.push(err_chunk);
}); });
// child.on('close', code => { if (!realTime) {
// let stdout = chunks.join(""); child.on('close', code => {
// let stderr = err_chunks.join(""); let stdout = chunks.join("");
// callback(stdout, stderr) let stderr = err_chunks.join("");
// }) callback(stdout, stderr)
})
}
return child return child
} }

View File

@ -62,6 +62,20 @@ export default defineComponent({
this.utools.whole.onPluginEnter((enter) => { this.utools.whole.onPluginEnter((enter) => {
this.enterPlugin(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.utools.whole.onPluginOut(() => {
this.outPlugin(); this.outPlugin();
}); });
@ -115,10 +129,21 @@ export default defineComponent({
this.runCommandSilently(featureCode); this.runCommandSilently(featureCode);
}); });
}, },
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 command = this.utools.getDB("qc_" + featureCode);
let commandCode = command.cmd;
if (mainInput)
commandCode = commandCode.replace(/\{\{input\}\}/g, mainInput);
if (command.program === "quickcommand") { if (command.program === "quickcommand") {
window.runCodeInSandbox(command.cmd, () => {}); window.runCodeInSandbox(commandCode, (stdout, stderr) => {
stderr && reslove([stderr.toString()]);
reslove(stdout);
});
} else { } else {
let option = let option =
command.program === "custom" command.program === "custom"
@ -126,8 +151,21 @@ export default defineComponent({
: this.programs[command.program]; : this.programs[command.program];
option.scptarg = command.scptarg; option.scptarg = command.scptarg;
option.charset = command.charset; option.charset = command.charset;
window.runCodeFile(command.cmd, option, false, () => {}); window.runCodeFile(
commandCode,
option,
false,
(stdout, stderr) => {
stderr && reslove([stderr.toString()]);
reslove([stdout]);
},
false
);
} }
});
},
runCommandSilently(featureCode) {
this.runCommand(featureCode);
}, },
usageStatistics(featureCode, runTime) { usageStatistics(featureCode, runTime) {
let statisticsData = this.utools.getDB("cfg_statisticsData"); let statisticsData = this.utools.getDB("cfg_statisticsData");

View File

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