mirror of
https://github.com/fofolee/uTools-quickcommand.git
synced 2025-12-17 08:54:19 +08:00
优化命令的导入、保存和定位
This commit is contained in:
@@ -1,9 +1,19 @@
|
||||
<template>
|
||||
<div></div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { useCommandManager } from "js/commandManager";
|
||||
import { getUniqueId } from "js/common/uuid.js";
|
||||
|
||||
export default {
|
||||
mounted() {
|
||||
const commandManager = useCommandManager();
|
||||
utools.setExpendHeight(0);
|
||||
this.$root.enterData.payload.forEach((file) => {
|
||||
let uid = this.getUid();
|
||||
let uid = getUniqueId({
|
||||
short: true,
|
||||
});
|
||||
let fileInfo = window.getFileInfo({
|
||||
type: "file",
|
||||
argvs: file.path,
|
||||
@@ -17,24 +27,17 @@ export default {
|
||||
icon: utools.getFileIcon(file.path),
|
||||
platform: [window.processPlatform],
|
||||
code: `key_${uid}`,
|
||||
mainHide: true,
|
||||
},
|
||||
program: "quickcommand",
|
||||
cmd: `open(\"${file.path.replace(/\\/g, "\\\\")}\")`,
|
||||
cmd: `utools.shellOpenPath(\"${file.path.replace(/\\/g, "\\\\")}\")`,
|
||||
output: "ignore",
|
||||
tags: [this.$root.profile.quickFileTag],
|
||||
};
|
||||
this.importCommand(command);
|
||||
this.commandManager.importCommand(JSON.stringify(command));
|
||||
});
|
||||
utools.showNotification("操作成功!");
|
||||
utools.outPlugin();
|
||||
},
|
||||
methods: {
|
||||
getUid() {
|
||||
return this.$parent.getUid();
|
||||
},
|
||||
importCommand(command) {
|
||||
this.$parent.importCommand(command);
|
||||
},
|
||||
},
|
||||
};
|
||||
</script>
|
||||
|
||||
@@ -1,76 +1,60 @@
|
||||
<template>
|
||||
<div></div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { getUniqueId } from "js/common/uuid.js";
|
||||
import { useCommandManager } from "js/commandManager";
|
||||
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
cmdCtrlKey: window.processPlatform === "darwin" ? "command" : "control",
|
||||
};
|
||||
},
|
||||
async mounted() {
|
||||
const commandManager = useCommandManager();
|
||||
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();
|
||||
let url = utools.getCurrentBrowserUrl();
|
||||
if (!/^http/.test(url)) {
|
||||
utools.showMainWindow();
|
||||
utools.setExpendHeight(550);
|
||||
let choise = await quickcommand.showButtonBox(
|
||||
const choise = await quickcommand.showSystemButtonBox(
|
||||
["http", "https"],
|
||||
"当前浏览器网址显示不完整,请问访问的页面是哪一种?"
|
||||
);
|
||||
url = choise.text + "://" + url;
|
||||
}
|
||||
let title = this.$root.enterData.payload.title
|
||||
const title = this.$root.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(
|
||||
const base = /(http(s){0,1}:\/\/.*?(:\d+){0,1})(\/|$).*/.exec(url)[1];
|
||||
const iconUrl = base + "/favicon.ico";
|
||||
const iconPath = window.joinPath(
|
||||
utools.getPath("temp"),
|
||||
"quickcommandfavicon.ico"
|
||||
);
|
||||
let uid = this.getUid();
|
||||
let command = {
|
||||
const uid = getUniqueId({
|
||||
short: true,
|
||||
});
|
||||
const command = {
|
||||
features: {
|
||||
explain: title,
|
||||
cmds: [title],
|
||||
platform: ["linux", "win32", "darwin"],
|
||||
code: `key_${uid}`,
|
||||
mainHide: true,
|
||||
icon: "features/fav.png",
|
||||
},
|
||||
program: "quickcommand",
|
||||
cmd: `visit(\"${url}\")\n`,
|
||||
cmd: `utools.shellOpenExternal(\"${url}\")\n`,
|
||||
output: "ignore",
|
||||
tags: [this.$root.profile.quickUrlTag],
|
||||
};
|
||||
try {
|
||||
let res = await quickcommand.downloadFile(iconUrl, iconPath);
|
||||
const res = await quickcommand.downloadFile(iconUrl, iconPath);
|
||||
if (res) command.features.icon = window.resolveFileToBase64(iconPath);
|
||||
} catch (e) {}
|
||||
this.importCommand(command);
|
||||
} catch (_) {}
|
||||
commandManager.importCommand(JSON.stringify(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>
|
||||
|
||||
@@ -85,6 +85,9 @@
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { useCommandManager } from "js/commandManager";
|
||||
import { getUniqueId } from "js/common/uuid.js";
|
||||
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
@@ -113,10 +116,13 @@ export default {
|
||||
},
|
||||
methods: {
|
||||
addPluNickName() {
|
||||
const commandManager = useCommandManager();
|
||||
if (!this.nickName.length)
|
||||
return quickcommand.showMessageBox("请填写别名", "warning");
|
||||
let uid = this.getUid();
|
||||
let command = {
|
||||
const uid = getUniqueId({
|
||||
short: true,
|
||||
});
|
||||
const command = {
|
||||
features: {
|
||||
cmds: this.nickName,
|
||||
explain: this.feature.explain,
|
||||
@@ -129,16 +135,12 @@ export default {
|
||||
output: "ignore",
|
||||
tags: [this.$root.profile.pluNickNameTag],
|
||||
};
|
||||
this.importCommand(command);
|
||||
commandManager.importCommand(JSON.stringify(command), {
|
||||
showMessage: false,
|
||||
});
|
||||
this.nickName = [];
|
||||
quickcommand.showMessageBox("添加成功!");
|
||||
},
|
||||
getUid() {
|
||||
return this.$parent.getUid();
|
||||
},
|
||||
importCommand(command) {
|
||||
this.$parent.importCommand(command);
|
||||
},
|
||||
},
|
||||
};
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user