emit('openMenu')" class="suffix-tool" >
@@ -24,22 +26,22 @@
import { defineProps, defineEmits, ref } from "vue";
import { ipcRenderer } from "electron";
-defineProps({
+const props = defineProps({
+ searchValue: {
+ type: [String, Number],
+ default: "",
+ },
currentPlugin: {},
});
-const searchValue = ref("");
-
const changeValue = (e) => {
emit("onSearch", e);
- searchValue.value = e.target.value;
};
const emit = defineEmits(["onSearch", "changeCurrent", "openMenu", "changeSelect"]);
const checkNeedInit = (e) => {
- console.log(e.keyCode);
- if (searchValue.value === "" && e.keyCode === 8) {
+ if (props.searchValue === "" && e.keyCode === 8) {
closeTag();
}
};
diff --git a/src/renderer/plugins-manager/index.ts b/src/renderer/plugins-manager/index.ts
index 360aeb1..35cf169 100644
--- a/src/renderer/plugins-manager/index.ts
+++ b/src/renderer/plugins-manager/index.ts
@@ -1,21 +1,13 @@
-import { reactive, toRefs, toRaw } from "vue";
+import { reactive, toRefs, ref } from "vue";
import { nativeImage, remote, ipcRenderer } from "electron";
import { appSearch, PluginHandler } from "@/core";
import path from "path";
-import throttle from "lodash.throttle";
import commonConst from "@/common/utils/commonConst";
+import searchManager from "./search";
+import optionsManager from "./options";
const appPath = remote.app.getPath("cache");
-function searchKeyValues(lists, value) {
- return lists.filter((item) => {
- if (typeof item === "string") {
- return item.toLowerCase().indexOf(value.toLowerCase()) >= 0;
- }
- return item.type.toLowerCase().indexOf(value.toLowerCase()) >= 0;
- });
-}
-
const createPluginManager = (): any => {
const baseDir = path.join(appPath, "./rubick-plugins");
const pluginInstance = new PluginHandler({
@@ -25,100 +17,47 @@ const createPluginManager = (): any => {
const state: any = reactive({
appList: [],
plugins: [],
- options: [],
- searchValue: "",
localPlugins: [],
currentPlugin: {},
});
+ const appList = ref([]);
+
const initPlugins = async () => {
- state.appList = await appSearch(nativeImage);
+ appList.value = await appSearch(nativeImage);
};
- const addPlugin = (plugin: any) => {
- state.plugins.unshift(plugin);
- };
-
- const removePlugin = (plugin: any) => {
- // todo
- };
-
- const onSearch = throttle((e) => {
- const value = e.target.value;
- state.searchValue = value;
- if (!value) return;
- state.localPlugins = remote.getGlobal("LOCAL_PLUGINS").getLocalPlugins();
- let options: any = [];
- // todo 先搜索 plugin
- state.localPlugins.forEach((plugin) => {
- const feature = plugin.features;
- feature.forEach((fe) => {
- const cmds = searchKeyValues(fe.cmds, value);
- options = [
- ...options,
- ...cmds.map((cmd) => ({
- name: cmd,
- value: "plugin",
- icon: plugin.logo,
- desc: fe.explain,
- type: plugin.pluginType,
- click: () => {
- const pluginPath = path.resolve(
- pluginInstance.baseDir,
- "node_modules",
- plugin.name
- );
- openPlugin({
- ...toRaw(plugin),
- indexPath: `file://${path.join(
- pluginPath,
- "./",
- plugin.main
- )}`,
- cmd,
- feature: fe,
- });
+ const openPlugin = (plugin) => {
+ if (plugin.pluginType === "ui") {
+ state.currentPlugin = plugin;
+ ipcRenderer.sendSync("msg-trigger", {
+ type: "openPlugin",
+ plugin: JSON.parse(
+ JSON.stringify({
+ ...plugin,
+ ext: {
+ code: plugin.feature.code,
+ type: plugin.cmd.type || "text",
+ payload: null,
},
- })),
- ];
+ })
+ ),
});
- });
- // todo 再搜索 app
- const descMap = new Map();
- options = [
- ...options,
- ...state.appList
- .filter((plugin) => {
- if (!descMap.get(plugin)) {
- descMap.set(plugin, true);
- let has = false;
- plugin.keyWords.some((keyWord) => {
- if (
- keyWord
- .toLocaleUpperCase()
- .indexOf(value.toLocaleUpperCase()) >= 0
- ) {
- has = keyWord;
- plugin.name = keyWord;
- return true;
- }
- return false;
- });
- return has;
- } else {
- return false;
- }
- })
- .map((plugin) => {
- plugin.click = () => {
- openPlugin(plugin);
- };
- return plugin;
- }),
- ];
- state.options = options;
- }, 500);
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
+ // @ts-ignore
+ // document.getElementById("search").value = "";
+ // state.searchValue = "";
+ }
+ };
+ const { searchValue, onSearch } = searchManager();
+ const { options } = optionsManager({
+ searchValue,
+ baseDir,
+ appList,
+ openPlugin,
+ });
+ // plugin operation
const getPluginInfo = async ({ pluginName, pluginPath }) => {
const pluginInfo = await pluginInstance.getAdapterInfo(pluginName, pluginPath);
return {
@@ -129,20 +68,18 @@ const createPluginManager = (): any => {
};
};
- const openPlugin = (plugin) => {
- if (plugin.pluginType === "ui") {
- state.currentPlugin = plugin;
- ipcRenderer.sendSync("msg-trigger", {
- type: "openPlugin",
- plugin: JSON.parse(JSON.stringify(plugin)),
- });
- }
- };
-
const changeSelect = (select) => {
state.currentPlugin = select;
};
+ const addPlugin = (plugin: any) => {
+ state.plugins.unshift(plugin);
+ };
+
+ const removePlugin = (plugin: any) => {
+ // todo
+ };
+
return {
...toRefs(state),
initPlugins,
@@ -152,6 +89,8 @@ const createPluginManager = (): any => {
getPluginInfo,
openPlugin,
changeSelect,
+ options,
+ searchValue,
};
};
diff --git a/src/renderer/plugins-manager/options.ts b/src/renderer/plugins-manager/options.ts
new file mode 100644
index 0000000..ceb48bc
--- /dev/null
+++ b/src/renderer/plugins-manager/options.ts
@@ -0,0 +1,100 @@
+import { ref, toRaw, toRefs, watch } from "vue";
+import throttle from "lodash.throttle";
+import { remote } from "electron";
+import path from "path";
+
+function searchKeyValues(lists, value) {
+ return lists.filter((item) => {
+ if (typeof item === "string") {
+ return item.toLowerCase().indexOf(value.toLowerCase()) >= 0;
+ }
+ return item.type.toLowerCase().indexOf(value.toLowerCase()) >= 0;
+ });
+}
+
+const optionsManager = ({ searchValue, baseDir, appList, openPlugin }) => {
+ const optionsRef = ref([]);
+
+ watch(searchValue, () => search(searchValue.value));
+ // search Input operation
+ const search = throttle((value) => {
+ if (!value) return;
+ const localPlugins = remote.getGlobal("LOCAL_PLUGINS").getLocalPlugins();
+ let options: any = [];
+ // todo 先搜索 plugin
+ localPlugins.forEach((plugin) => {
+ const feature = plugin.features;
+ feature.forEach((fe) => {
+ const cmds = searchKeyValues(fe.cmds, value);
+ options = [
+ ...options,
+ ...cmds.map((cmd) => ({
+ name: cmd,
+ value: "plugin",
+ icon: plugin.logo,
+ desc: fe.explain,
+ type: plugin.pluginType,
+ click: () => {
+ const pluginPath = path.resolve(
+ baseDir,
+ "node_modules",
+ plugin.name
+ );
+ openPlugin({
+ ...toRaw(plugin),
+ indexPath: `file://${path.join(
+ pluginPath,
+ "./",
+ plugin.main
+ )}`,
+ cmd,
+ feature: fe,
+ });
+ },
+ })),
+ ];
+ });
+ });
+ // todo 再搜索 app
+ const appPlugins = appList.value || [];
+ const descMap = new Map();
+ options = [
+ ...options,
+ ...appPlugins
+ .filter((plugin) => {
+ if (!descMap.get(plugin)) {
+ descMap.set(plugin, true);
+ let has = false;
+ plugin.keyWords.some((keyWord) => {
+ if (
+ keyWord
+ .toLocaleUpperCase()
+ .indexOf(value.toLocaleUpperCase()) >= 0
+ ) {
+ has = keyWord;
+ plugin.name = keyWord;
+ return true;
+ }
+ return false;
+ });
+ return has;
+ } else {
+ return false;
+ }
+ })
+ .map((plugin) => {
+ plugin.click = () => {
+ openPlugin(plugin);
+ };
+ return plugin;
+ }),
+ ];
+ optionsRef.value = options;
+ }, 500);
+
+ return {
+ options: optionsRef,
+ };
+};
+
+export default optionsManager;
diff --git a/src/renderer/plugins-manager/search.ts b/src/renderer/plugins-manager/search.ts
new file mode 100644
index 0000000..a6cef99
--- /dev/null
+++ b/src/renderer/plugins-manager/search.ts
@@ -0,0 +1,20 @@
+import { reactive, toRefs } from "vue";
+
+const searchManager = () => {
+ const state = reactive({
+ searchValue: "",
+ });
+
+ // search Input operation
+ const onSearch = (e) => {
+ const value = e.target.value;
+ state.searchValue = value;
+ };
+
+ return {
+ ...toRefs(state),
+ onSearch,
+ };
+};
+
+export default searchManager;