mirror of
https://github.com/rubickCenter/rubick
synced 2026-03-03 19:47:27 +08:00
✨ 支持插件开发者模式
This commit is contained in:
@@ -1,5 +0,0 @@
|
||||
const APP_FINDER_PATH = process.platform === 'darwin' ? ['/System/Applications', '/Applications', '/System/Library/PreferencePanes'] : []
|
||||
|
||||
export {
|
||||
APP_FINDER_PATH
|
||||
}
|
||||
8
src/common/constans/main.ts
Normal file
8
src/common/constans/main.ts
Normal file
@@ -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 };
|
||||
8
src/common/constans/renderer.ts
Normal file
8
src/common/constans/renderer.ts
Normal file
@@ -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 };
|
||||
@@ -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;
|
||||
|
||||
@@ -68,8 +68,8 @@ class AdapterHandler {
|
||||
}
|
||||
|
||||
// 安装并启动插件
|
||||
async install(adapters: Array<string>) {
|
||||
const installCmd = "install";
|
||||
async install(adapters: Array<string>, 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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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
|
||||
);
|
||||
|
||||
@@ -48,6 +48,7 @@ const props = defineProps({
|
||||
});
|
||||
|
||||
const changeValue = (e) => {
|
||||
if (props.currentPlugin.name === "rubick-system-feature") return;
|
||||
emit("onSearch", e);
|
||||
};
|
||||
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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));
|
||||
|
||||
Reference in New Issue
Block a user