From b3a00c88ad6f705ce2b80bde2d2dba80ff5629c6 Mon Sep 17 00:00:00 2001 From: muwoo <2424880409@qq.com> Date: Thu, 9 Dec 2021 11:46:06 +0800 Subject: [PATCH] =?UTF-8?q?:sparkles:=20=E6=94=AF=E6=8C=81=E6=8F=92?= =?UTF-8?q?=E4=BB=B6=E5=BC=80=E5=8F=91=E8=80=85=E6=A8=A1=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- feature/public/package.json | 2 +- feature/src/App.vue | 7 + feature/src/assets/request/index.ts | 7 + feature/src/router/index.ts | 6 + feature/src/views/dev/index.vue | 64 +++++++++ feature/src/views/installed/index.vue | 135 ++++++++++-------- .../src/views/market/components/finder.vue | 1 - .../src/views/market/components/system.vue | 49 +++++++ feature/src/views/market/index.vue | 2 + src/common/constans/index.js | 5 - src/common/constans/main.ts | 8 ++ src/common/constans/renderer.ts | 8 ++ src/common/utils/localPlugin.ts | 27 +++- src/core/plugin-handler/index.ts | 10 +- src/main/common/api.ts | 2 + src/main/common/registerySystemPlugin.ts | 8 +- src/renderer/components/search.vue | 1 + src/renderer/plugins-manager/index.ts | 7 +- src/renderer/plugins-manager/options.ts | 3 +- 19 files changed, 264 insertions(+), 88 deletions(-) create mode 100644 feature/src/views/dev/index.vue create mode 100644 feature/src/views/market/components/system.vue delete mode 100644 src/common/constans/index.js create mode 100644 src/common/constans/main.ts create mode 100644 src/common/constans/renderer.ts diff --git a/feature/public/package.json b/feature/public/package.json index 6d96e0b..a6f61a8 100644 --- a/feature/public/package.json +++ b/feature/public/package.json @@ -3,7 +3,7 @@ "pluginName": "rubick 系统菜单", "description": "rubick 系统菜单", "main": "index.html", - "logo": "httpss://static.91jkys.com/upload/202112/08/8a1abbb051bf4b05bbc9bbf66ade63f2.png", + "logo": "https://static.91jkys.com/upload/202112/08/8a1abbb051bf4b05bbc9bbf66ade63f2.png", "version": "0.0.0", "preload":"preload.js", "pluginType": "ui", diff --git a/feature/src/App.vue b/feature/src/App.vue index 7caeabe..dfc5b5b 100644 --- a/feature/src/App.vue +++ b/feature/src/App.vue @@ -26,6 +26,12 @@ 账户 + + + 开发者 + @@ -40,6 +46,7 @@ import { UserOutlined, AppstoreOutlined, SettingOutlined, + BugOutlined, } from "@ant-design/icons-vue"; import { useStore } from "vuex"; const router = useRouter(); diff --git a/feature/src/assets/request/index.ts b/feature/src/assets/request/index.ts index dbfb321..5701e76 100644 --- a/feature/src/assets/request/index.ts +++ b/feature/src/assets/request/index.ts @@ -14,4 +14,11 @@ export default { ); return res.data; }, + + async getSystemDetail() { + const res = await axios.get( + "https://gitee.com/monkeyWang/rubick-database/raw/master/plugins/system.json" + ); + return res.data; + }, }; diff --git a/feature/src/router/index.ts b/feature/src/router/index.ts index 7173647..7e2d5b1 100644 --- a/feature/src/router/index.ts +++ b/feature/src/router/index.ts @@ -3,6 +3,7 @@ import Market from "../views/market/index.vue"; import Installed from "../views/installed/index.vue"; import Account from "../views/account/index.vue"; import Settings from "../views/settings/index.vue"; +import Dev from "../views/dev/index.vue"; const routes: Array = [ { @@ -25,6 +26,11 @@ const routes: Array = [ name: "settings", component: Settings, }, + { + path: "/dev", + name: "dev", + component: Dev, + }, { path: "/:catchAll(.*)", name: "market", diff --git a/feature/src/views/dev/index.vue b/feature/src/views/dev/index.vue new file mode 100644 index 0000000..d68c10f --- /dev/null +++ b/feature/src/views/dev/index.vue @@ -0,0 +1,64 @@ + + + + + diff --git a/feature/src/views/installed/index.vue b/feature/src/views/installed/index.vue index b752ed9..170cb72 100644 --- a/feature/src/views/installed/index.vue +++ b/feature/src/views/installed/index.vue @@ -1,57 +1,61 @@ @@ -88,7 +94,11 @@ const appPath = remote.app.getPath("cache"); const baseDir = path.join(appPath, "./rubick-plugins"); const store = useStore(); -const localPlugins = computed(() => store.state.localPlugins); +const localPlugins = computed(() => + store.state.localPlugins.filter( + (plugin) => plugin.name !== "rubick-system-feature" + ) +); const updateLocalPlugin = () => store.dispatch("updateLocalPlugin"); const currentSelect = ref(0); @@ -125,7 +135,14 @@ const deletePlugin = async (plugin) => { overflow: hidden; background: #f3efef; height: calc(~"100vh - 46px"); - display: flex; + .container { + box-sizing: border-box; + width: 100%; + overflow: hidden; + background: #f3efef; + height: 100%; + display: flex; + } .installed-list { width: 40%; background: #fff; diff --git a/feature/src/views/market/components/finder.vue b/feature/src/views/market/components/finder.vue index 94dfda9..06cab15 100644 --- a/feature/src/views/market/components/finder.vue +++ b/feature/src/views/market/components/finder.vue @@ -45,7 +45,6 @@ const totalPlugins = computed(() => store.state.totalPlugins); const data = ref([]); onBeforeMount(async () => { - console.log(12312); data.value = await request.getFinderDetail(); }); diff --git a/feature/src/views/market/components/system.vue b/feature/src/views/market/components/system.vue new file mode 100644 index 0000000..1f6ec2d --- /dev/null +++ b/feature/src/views/market/components/system.vue @@ -0,0 +1,49 @@ + + + + + diff --git a/feature/src/views/market/index.vue b/feature/src/views/market/index.vue index 147cbd1..2e1f0a6 100644 --- a/feature/src/views/market/index.vue +++ b/feature/src/views/market/index.vue @@ -67,9 +67,11 @@ import { import { reactive, toRefs, computed } from "vue"; import { useStore } from "vuex"; import Finder from "./components/finder.vue"; +import System from "./components/system.vue"; const Components = { finder: Finder, + system: System, }; const state = reactive({ diff --git a/src/common/constans/index.js b/src/common/constans/index.js deleted file mode 100644 index 7e679cb..0000000 --- a/src/common/constans/index.js +++ /dev/null @@ -1,5 +0,0 @@ -const APP_FINDER_PATH = process.platform === 'darwin' ? ['/System/Applications', '/Applications', '/System/Library/PreferencePanes'] : [] - -export { - APP_FINDER_PATH -} diff --git a/src/common/constans/main.ts b/src/common/constans/main.ts new file mode 100644 index 0000000..95b42a0 --- /dev/null +++ b/src/common/constans/main.ts @@ -0,0 +1,8 @@ +import { app } from "electron"; +import path from "path"; + +const appPath = app.getPath("cache"); + +const PLUGIN_INSTALL_DIR = path.join(appPath, "./rubick-plugins"); + +export { PLUGIN_INSTALL_DIR }; diff --git a/src/common/constans/renderer.ts b/src/common/constans/renderer.ts new file mode 100644 index 0000000..ba1e559 --- /dev/null +++ b/src/common/constans/renderer.ts @@ -0,0 +1,8 @@ +import { remote } from "electron"; +import path from "path"; + +const appPath = remote.app.getPath("cache"); + +const PLUGIN_INSTALL_DIR = path.join(appPath, "./rubick-plugins"); + +export { PLUGIN_INSTALL_DIR }; diff --git a/src/common/utils/localPlugin.ts b/src/common/utils/localPlugin.ts index c56e232..fd9b8de 100644 --- a/src/common/utils/localPlugin.ts +++ b/src/common/utils/localPlugin.ts @@ -1,21 +1,36 @@ import path from "path"; import fs from "fs"; import getLocalDataFile from "./getLocalDataFile"; -import { app } from "electron"; import { PluginHandler } from "@/core"; +import { PLUGIN_INSTALL_DIR as baseDir } from "@/common/constans/main"; const configPath = path.join(getLocalDataFile(), "./rubick-local-plugin.json"); -const appPath = app.getPath("cache"); -const baseDir = path.join(appPath, "./rubick-plugins"); const pluginInstance = new PluginHandler({ - baseDir: baseDir, + baseDir, }); global.LOCAL_PLUGINS = { PLUGINS: [], async downloadPlugin(plugin) { - await pluginInstance.install([plugin.name]); + console.log(plugin); + await pluginInstance.install([plugin.name], { isDev: plugin.isDev }); + if (plugin.isDev) { + // 获取 dev 插件信息 + const pluginPath = path.resolve( + baseDir, + "node_modules", + plugin.name + ); + const pluginInfo = JSON.parse( + fs.readFileSync(path.join(pluginPath, "./package.json"), "utf8") + ); + plugin = { + ...plugin, + ...pluginInfo, + }; + } + console.log(plugin); global.LOCAL_PLUGINS.addPlugin(plugin); return global.LOCAL_PLUGINS.PLUGINS; }, @@ -60,7 +75,7 @@ global.LOCAL_PLUGINS = { fs.writeFileSync(configPath, JSON.stringify(global.LOCAL_PLUGINS.PLUGINS)); }, async deletePlugin(plugin) { - await pluginInstance.uninstall([plugin.name]); + await pluginInstance.uninstall([plugin.name], { isDev: plugin.isDev }); global.LOCAL_PLUGINS.PLUGINS = global.LOCAL_PLUGINS.PLUGINS.filter((p) => plugin.name !== p.name); fs.writeFileSync(configPath, JSON.stringify(global.LOCAL_PLUGINS.PLUGINS)); return global.LOCAL_PLUGINS.PLUGINS; diff --git a/src/core/plugin-handler/index.ts b/src/core/plugin-handler/index.ts index 939d5d6..7ac8894 100644 --- a/src/core/plugin-handler/index.ts +++ b/src/core/plugin-handler/index.ts @@ -68,8 +68,8 @@ class AdapterHandler { } // 安装并启动插件 - async install(adapters: Array) { - const installCmd = "install"; + async install(adapters: Array, options: { isDev: boolean }) { + const installCmd = options.isDev ? "link" : "install"; // 安装 await this.execCommand(installCmd, adapters); } @@ -110,11 +110,13 @@ class AdapterHandler { /** * 卸载指定插件 * @param {...string[]} adapters 插件名称 + * @param options * @memberof AdapterHandler */ - async uninstall(adapters: string[]) { + async uninstall(adapters: string[], options: { isDev: boolean }) { + const installCmd = options.isDev ? "unlink" : "uninstall"; // 卸载插件 - await this.execCommand("uninstall", adapters); + await this.execCommand(installCmd, adapters); } /** diff --git a/src/main/common/api.ts b/src/main/common/api.ts index 96ee03a..1856ccf 100644 --- a/src/main/common/api.ts +++ b/src/main/common/api.ts @@ -22,11 +22,13 @@ const API: any = { currentPlugin: null, DBKEY: "RUBICK_DB_DEFAULT", openPlugin({ plugin }, window) { + if (API.currentPlugin && API.currentPlugin.name === plugin.name) return; runnerInstance.removeView(window); runnerInstance.init(plugin, window); API.currentPlugin = plugin; }, removePlugin(e, window) { + API.currentPlugin = null; runnerInstance.removeView(window); }, hideMainWindow(arg, window) { diff --git a/src/main/common/registerySystemPlugin.ts b/src/main/common/registerySystemPlugin.ts index 75b47f1..fe138b3 100644 --- a/src/main/common/registerySystemPlugin.ts +++ b/src/main/common/registerySystemPlugin.ts @@ -1,19 +1,15 @@ /* eslint-disable */ import path from "path"; -import {app} from "electron"; import fs from "fs"; - -const appPath = app.getPath("cache"); +import { PLUGIN_INSTALL_DIR } from "@/common/constans/main"; export default () => { // 读取所有插件 const totalPlugins = global.LOCAL_PLUGINS.getLocalPlugins(); let systemPlugins = totalPlugins.filter((plugin) => plugin.pluginType === "system"); - const baseDir = path.join(appPath, "./rubick-plugins"); - systemPlugins = systemPlugins.map((plugin) => { const pluginPath = path.resolve( - baseDir, + PLUGIN_INSTALL_DIR, "node_modules", plugin.name ); diff --git a/src/renderer/components/search.vue b/src/renderer/components/search.vue index dac9751..968b164 100644 --- a/src/renderer/components/search.vue +++ b/src/renderer/components/search.vue @@ -48,6 +48,7 @@ const props = defineProps({ }); const changeValue = (e) => { + if (props.currentPlugin.name === "rubick-system-feature") return; emit("onSearch", e); }; diff --git a/src/renderer/plugins-manager/index.ts b/src/renderer/plugins-manager/index.ts index 4411eb5..d3f556a 100644 --- a/src/renderer/plugins-manager/index.ts +++ b/src/renderer/plugins-manager/index.ts @@ -6,13 +6,11 @@ import commonConst from "@/common/utils/commonConst"; import { execSync } from "child_process"; import searchManager from "./search"; import optionsManager from "./options"; - -const appPath = remote.app.getPath("cache"); +import { PLUGIN_INSTALL_DIR as baseDir } from "@/common/constans/renderer"; const createPluginManager = (): any => { - const baseDir = path.join(appPath, "./rubick-plugins"); const pluginInstance = new PluginHandler({ - baseDir: baseDir, + baseDir, }); const state: any = reactive({ @@ -54,7 +52,6 @@ const createPluginManager = (): any => { const { searchValue, onSearch, setSearchValue, placeholder } = searchManager(); const { options } = optionsManager({ searchValue, - baseDir, appList, openPlugin, currentPlugin: toRefs(state).currentPlugin, diff --git a/src/renderer/plugins-manager/options.ts b/src/renderer/plugins-manager/options.ts index d20448b..f61a769 100644 --- a/src/renderer/plugins-manager/options.ts +++ b/src/renderer/plugins-manager/options.ts @@ -2,6 +2,7 @@ import { ref, toRaw, toRefs, watch } from "vue"; import throttle from "lodash.throttle"; import { remote } from "electron"; import path from "path"; +import { PLUGIN_INSTALL_DIR as baseDir } from "@/common/constans/renderer"; function searchKeyValues(lists, value) { return lists.filter((item) => { @@ -12,7 +13,7 @@ function searchKeyValues(lists, value) { }); } -const optionsManager = ({ searchValue, baseDir, appList, openPlugin, currentPlugin }) => { +const optionsManager = ({ searchValue, appList, openPlugin, currentPlugin }) => { const optionsRef = ref([]); watch(searchValue, () => search(searchValue.value));