mirror of
https://github.com/fofolee/uTools-quickcommand.git
synced 2025-09-24 13:03:30 +08:00
添加快捷命令服务的功能
This commit is contained in:
127
src/components/quickFeatures/ApiServer.vue
Normal file
127
src/components/quickFeatures/ApiServer.vue
Normal file
@@ -0,0 +1,127 @@
|
||||
<template>
|
||||
<div>
|
||||
<MonacoEditor
|
||||
:placeholder="false"
|
||||
class="absolute-top"
|
||||
ref="editor"
|
||||
@typing="
|
||||
(val) => {
|
||||
$profile.quickFeatures.apiServer.cmd = val;
|
||||
serverStatus && (needRestart = true);
|
||||
}
|
||||
"
|
||||
:style="{
|
||||
bottom: bottomHeight + 'px',
|
||||
}"
|
||||
/>
|
||||
<div
|
||||
class="
|
||||
absolute-bottom
|
||||
flex
|
||||
items-center
|
||||
justify-between
|
||||
q-px-md
|
||||
shadow-10
|
||||
"
|
||||
:style="{
|
||||
height: bottomHeight + 'px',
|
||||
}"
|
||||
>
|
||||
<div class="q-gutter-xs">
|
||||
<q-badge color="primary" dense square>POST</q-badge
|
||||
><q-badge color="primary" dense square>GET</q-badge>
|
||||
<span>
|
||||
http://127.0.0.1:{{ $profile.quickFeatures.apiServer.port }}
|
||||
</span>
|
||||
<span>的参数,均会作为本脚本里的变量 </span>
|
||||
</div>
|
||||
<q-btn-group unelevated>
|
||||
<q-btn flat color="primary" icon="help" />
|
||||
<q-separator inset vertical />
|
||||
<q-btn
|
||||
flat
|
||||
color="negative"
|
||||
icon="stop"
|
||||
v-if="serverStatus && !needRestart"
|
||||
@click="stopServer"
|
||||
label="停止服务"
|
||||
/>
|
||||
<q-btn
|
||||
flat
|
||||
color="warning"
|
||||
icon="restart_alt"
|
||||
v-else-if="serverStatus && needRestart"
|
||||
@click="restartServer"
|
||||
label="重启服务"
|
||||
/>
|
||||
<q-btn
|
||||
flat
|
||||
color="primary"
|
||||
icon="play_arrow"
|
||||
v-else
|
||||
label="开启服务"
|
||||
@click="enableServer"
|
||||
>
|
||||
</q-btn>
|
||||
</q-btn-group>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import MonacoEditor from "components/MonacoEditor";
|
||||
|
||||
export default {
|
||||
components: { MonacoEditor },
|
||||
data() {
|
||||
return {
|
||||
bottomHeight: 40,
|
||||
serverStatus: this.$profile.quickFeatures.apiServer.serverStatus,
|
||||
needRestart: null,
|
||||
};
|
||||
},
|
||||
mounted() {
|
||||
this.$refs.editor.setEditorValue(this.$profile.quickFeatures.apiServer.cmd);
|
||||
this.$refs.editor.setEditorLanguage("javascript");
|
||||
this.needRestart = false;
|
||||
},
|
||||
methods: {
|
||||
enableServer() {
|
||||
quickcommand
|
||||
.showConfirmBox(
|
||||
"请注意,该接口未做任何权限鉴定,千万不要试图将本端口转发出去,否则无异于将本机的 shell 权限暴露在公网!",
|
||||
"FBI WARNING"
|
||||
)
|
||||
.then((ok) => {
|
||||
if (!ok) return;
|
||||
this.$profile.quickFeatures.apiServer.serverStatus =
|
||||
this.serverStatus = true;
|
||||
window
|
||||
.quickcommandHttpServer()
|
||||
.run(
|
||||
this.$profile.quickFeatures.apiServer.cmd,
|
||||
this.$profile.quickFeatures.apiServer.port
|
||||
);
|
||||
quickcommand.showMessageBox("启动服务成功!");
|
||||
});
|
||||
},
|
||||
stopServer() {
|
||||
window.quickcommandHttpServer().stop();
|
||||
this.$profile.quickFeatures.apiServer.serverStatus =
|
||||
this.serverStatus = false;
|
||||
quickcommand.showMessageBox("关闭服务成功!");
|
||||
},
|
||||
restartServer() {
|
||||
window.quickcommandHttpServer().stop();
|
||||
window
|
||||
.quickcommandHttpServer()
|
||||
.run(
|
||||
this.$profile.quickFeatures.apiServer.cmd,
|
||||
this.$profile.quickFeatures.apiServer.port
|
||||
);
|
||||
this.needRestart = false;
|
||||
quickcommand.showMessageBox("重启服务成功!");
|
||||
},
|
||||
},
|
||||
};
|
||||
</script>
|
55
src/components/quickFeatures/CrontabCmd.vue
Normal file
55
src/components/quickFeatures/CrontabCmd.vue
Normal file
@@ -0,0 +1,55 @@
|
||||
<template>
|
||||
<q-card>
|
||||
<q-card-section class="text-h5 text-center">定时执行</q-card-section>
|
||||
<q-card-section class="q-gutter-md">
|
||||
<q-input
|
||||
v-model="crontab"
|
||||
type="text"
|
||||
standout="bg-primary text-white"
|
||||
label="请输入 Crontab 表达式"
|
||||
mask="# # # # # #"
|
||||
>
|
||||
<template v-slot:append>
|
||||
<q-btn flat icon="help"></q-btn>
|
||||
</template>
|
||||
</q-input>
|
||||
<pre class="explain">
|
||||
{{ explain }}
|
||||
</pre>
|
||||
<div>当前状态:</div>
|
||||
<div>下次执行时间:</div>
|
||||
</q-card-section>
|
||||
<q-card-actions align="right">
|
||||
<q-btn flat color="negative" v-close-popup>禁用</q-btn>
|
||||
<q-btn flat color="primary" v-close-popup>启用</q-btn>
|
||||
</q-card-actions>
|
||||
</q-card>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
const explain = `
|
||||
┌──────────────── (可选) 秒 (0 - 59)
|
||||
│ ┌────────────── 分钟 (0 - 59)
|
||||
│ │ ┌──────────── 小时 (0 - 23)
|
||||
│ │ │ ┌────────── 日 (1 - 31)
|
||||
│ │ │ │ ┌──────── 月 (1 - 12, 一月-十二月)
|
||||
│ │ │ │ │ ┌────── 星期 (0 - 6, 周日-周六)
|
||||
* * * * * *`;
|
||||
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
crontab: "",
|
||||
explain: explain,
|
||||
};
|
||||
},
|
||||
};
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.explain {
|
||||
background: #ffffff18;
|
||||
padding: 0 10px;
|
||||
border-radius: 5px;
|
||||
}
|
||||
</style>
|
40
src/components/quickFeatures/FavFile.vue
Normal file
40
src/components/quickFeatures/FavFile.vue
Normal file
@@ -0,0 +1,40 @@
|
||||
<script>
|
||||
export default {
|
||||
mounted() {
|
||||
utools.setExpendHeight(0);
|
||||
quickcommand.enterData.payload.forEach((file) => {
|
||||
let uid = this.getUid();
|
||||
let fileInfo = window.getFileInfo({
|
||||
type: "file",
|
||||
argvs: file.path,
|
||||
readfile: false,
|
||||
});
|
||||
let fileName = fileInfo.name.replace(fileInfo.ext, "");
|
||||
let command = {
|
||||
features: {
|
||||
cmds: [fileName],
|
||||
explain: `打开${fileName}`,
|
||||
icon: utools.getFileIcon(file.path),
|
||||
platform: [window.processPlatform],
|
||||
code: `key_${uid}`,
|
||||
},
|
||||
program: "quickcommand",
|
||||
cmd: `open(\"${file.path.replace(/\\/g, "\\\\")}\")`,
|
||||
output: "ignore",
|
||||
tags: [this.$profile.quickFeatures.favFile.tag],
|
||||
};
|
||||
this.importCommand(command);
|
||||
});
|
||||
utools.showNotification("操作成功!");
|
||||
utools.outPlugin();
|
||||
},
|
||||
methods: {
|
||||
getUid() {
|
||||
return this.$parent.getUid();
|
||||
},
|
||||
importCommand(command) {
|
||||
this.$parent.importCommand(command);
|
||||
},
|
||||
},
|
||||
};
|
||||
</script>
|
76
src/components/quickFeatures/FavUrl.vue
Normal file
76
src/components/quickFeatures/FavUrl.vue
Normal file
@@ -0,0 +1,76 @@
|
||||
<script>
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
cmdCtrlKey: window.processPlatform === "darwin" ? "command" : "control",
|
||||
};
|
||||
},
|
||||
async mounted() {
|
||||
utools.setExpendHeight(0);
|
||||
utools.hideMainWindow();
|
||||
// getCurrentBrowserUrl 似乎失效了
|
||||
// let url = utools.getCurrentBrowserUrl();
|
||||
utools.simulateKeyboardTap("l", this.cmdCtrlKey);
|
||||
await this.wait(50);
|
||||
utools.simulateKeyboardTap("c", this.cmdCtrlKey);
|
||||
await this.wait(50);
|
||||
let url = window.clipboardReadText();
|
||||
if (!/^http/.test(url)) {
|
||||
utools.showMainWindow();
|
||||
utools.setExpendHeight(550);
|
||||
let choise = await quickcommand.showButtonBox(
|
||||
["http", "https"],
|
||||
"当前浏览器网址显示不完整,请问访问的页面是哪一种?"
|
||||
);
|
||||
url = choise.text + "://" + url;
|
||||
}
|
||||
let title = quickcommand.enterData.payload.title
|
||||
.replace(/和另外 \d+ 个页面.*/, "")
|
||||
.replace(/[-|—] .*?[Edge|Firefox|Chrome].*/, "")
|
||||
.trim();
|
||||
// let req = await axios(url)
|
||||
// let title = quickcommand.htmlParse(req.data).querySelector('title').innerText
|
||||
let base = /(http(s){0,1}:\/\/.*?(:\d+){0,1})(\/|$).*/.exec(url)[1];
|
||||
let iconUrl = base + "/favicon.ico";
|
||||
let iconPath = window.joinPath(
|
||||
utools.getPath("temp"),
|
||||
"quickcommandfavicon.ico"
|
||||
);
|
||||
let uid = this.getUid();
|
||||
let command = {
|
||||
features: {
|
||||
explain: `访问${title}`,
|
||||
cmds: [title],
|
||||
platform: ["linux", "win32", "darwin"],
|
||||
code: `key_${uid}`,
|
||||
},
|
||||
program: "quickcommand",
|
||||
cmd: `visit(\"${url}\")\n`,
|
||||
output: "ignore",
|
||||
tags: [this.$profile.quickFeatures.favUrl.tag],
|
||||
};
|
||||
try {
|
||||
let res = await quickcommand.downloadFile(iconUrl, iconPath);
|
||||
if (res) command.features.icon = iconPath;
|
||||
} catch (e) {}
|
||||
this.importCommand(command);
|
||||
utools.showNotification("操作成功!");
|
||||
utools.outPlugin();
|
||||
},
|
||||
methods: {
|
||||
wait(ms) {
|
||||
return new Promise((resolve) => {
|
||||
setTimeout(() => {
|
||||
resolve();
|
||||
}, ms);
|
||||
});
|
||||
},
|
||||
getUid() {
|
||||
return this.$parent.getUid();
|
||||
},
|
||||
importCommand(command) {
|
||||
this.$parent.importCommand(command);
|
||||
},
|
||||
},
|
||||
};
|
||||
</script>
|
144
src/components/quickFeatures/PluginNickName.vue
Normal file
144
src/components/quickFeatures/PluginNickName.vue
Normal file
@@ -0,0 +1,144 @@
|
||||
<template>
|
||||
<div class="flex justify-center content-center" style="height: 500px">
|
||||
<div class="q-gutter-lg q-pa-lg" style="width: 600px">
|
||||
<div class="text-center text-h2 q-ma-none">插件别名设置</div>
|
||||
<q-select
|
||||
outlined
|
||||
transition-show="jump-down"
|
||||
transition-hide="jump-up"
|
||||
v-model="plugin"
|
||||
:options="plugins"
|
||||
type="text"
|
||||
class="full-width"
|
||||
:display-value="plugin.pluginName"
|
||||
@update:model-value="feature = features[0]"
|
||||
label="请选择插件"
|
||||
>
|
||||
<template v-slot:prepend>
|
||||
<q-icon name="extension" />
|
||||
</template>
|
||||
<template v-slot:option="scope">
|
||||
<q-item v-bind="scope.itemProps">
|
||||
<q-item-section avatar>
|
||||
<q-img :src="`file:///${scope.opt.logoPath}`" />
|
||||
</q-item-section>
|
||||
<q-item-section>
|
||||
<q-item-label v-html="scope.opt.pluginName" />
|
||||
<q-item-label caption>{{ scope.opt.description }}</q-item-label>
|
||||
</q-item-section>
|
||||
</q-item>
|
||||
</template>
|
||||
</q-select>
|
||||
<q-select
|
||||
outlined
|
||||
transition-show="jump-down"
|
||||
transition-hide="jump-up"
|
||||
v-model="feature"
|
||||
:options="features"
|
||||
type="text"
|
||||
:display-value="feature.cmd || ''"
|
||||
class="full-width"
|
||||
label="请选择功能关键字"
|
||||
>
|
||||
<template v-slot:prepend>
|
||||
<q-icon name="font_download" />
|
||||
</template>
|
||||
<template v-slot:option="scope">
|
||||
<q-item v-bind="scope.itemProps">
|
||||
<q-item-section avatar>
|
||||
<q-img :src="`file:///${plugin.logoPath}`" />
|
||||
</q-item-section>
|
||||
<q-item-section>
|
||||
<q-item-label v-html="scope.opt.cmd" />
|
||||
<q-item-label caption>{{ scope.opt.explain }}</q-item-label>
|
||||
</q-item-section>
|
||||
</q-item>
|
||||
</template>
|
||||
</q-select>
|
||||
<q-select
|
||||
class="full-width"
|
||||
max-values="3"
|
||||
type="text"
|
||||
placeholder="键入后回车"
|
||||
use-input
|
||||
hide-dropdown-icon
|
||||
use-chips
|
||||
multiple
|
||||
new-value-mode="add-unique"
|
||||
input-debounce="0"
|
||||
outlined
|
||||
v-model="nickName"
|
||||
label="要设置的别名"
|
||||
>
|
||||
<template v-slot:prepend>
|
||||
<q-icon name="drive_file_rename_outline" />
|
||||
</template>
|
||||
</q-select>
|
||||
<q-btn
|
||||
class="full-width"
|
||||
color="primary"
|
||||
label="确定"
|
||||
@click="addPluNickName()"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
plugins: [],
|
||||
plugin: {},
|
||||
feature: {},
|
||||
nickName: [],
|
||||
};
|
||||
},
|
||||
mounted() {
|
||||
this.plugins = _.values(window.getUtoolsPlugins());
|
||||
this.plugin = this.plugins[0];
|
||||
this.feature = this.features[0];
|
||||
},
|
||||
computed: {
|
||||
features() {
|
||||
return this.plugin?.features
|
||||
?.map((x) => {
|
||||
return {
|
||||
explain: x.explain,
|
||||
cmd: x.cmds.filter((y) => y.length)[0],
|
||||
};
|
||||
})
|
||||
.filter((x) => x.cmd);
|
||||
},
|
||||
},
|
||||
methods: {
|
||||
addPluNickName() {
|
||||
if (!this.nickName.length)
|
||||
return quickcommand.showMessageBox("请填写别名", "warning");
|
||||
let uid = this.getUid();
|
||||
let command = {
|
||||
features: {
|
||||
cmds: this.nickName,
|
||||
explain: this.feature.explain,
|
||||
icon: window.getBase64Ico(this.plugin.logoPath),
|
||||
platform: this.plugin.platform || ["darwin", "win32", "linux"],
|
||||
code: `key_${uid}`,
|
||||
},
|
||||
program: "quickcommand",
|
||||
cmd: `utools.redirect("${this.feature.cmd}");utools.showMainWindow()`,
|
||||
output: "ignore",
|
||||
tags: [this.$profile.quickFeatures.pluNickName.tag],
|
||||
};
|
||||
this.importCommand(command);
|
||||
this.nickName = [];
|
||||
quickcommand.showMessageBox("添加成功!");
|
||||
},
|
||||
getUid() {
|
||||
return this.$parent.getUid();
|
||||
},
|
||||
importCommand(command) {
|
||||
this.$parent.importCommand(command);
|
||||
},
|
||||
},
|
||||
};
|
||||
</script>
|
Reference in New Issue
Block a user