mirror of
https://github.com/rubickCenter/rubick
synced 2025-06-17 00:57:22 +08:00
✨ 支持系统插件
This commit is contained in:
parent
8a35e60e48
commit
64f2eba2fa
50
src/main/common/registerySystemPlugin.ts
Normal file
50
src/main/common/registerySystemPlugin.ts
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
/* eslint-disable */
|
||||||
|
import path from "path";
|
||||||
|
import {app} from "electron";
|
||||||
|
import fs from "fs";
|
||||||
|
|
||||||
|
const appPath = app.getPath("cache");
|
||||||
|
|
||||||
|
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,
|
||||||
|
"node_modules",
|
||||||
|
plugin.name
|
||||||
|
);
|
||||||
|
return {
|
||||||
|
...plugin,
|
||||||
|
indexPath: path.join(
|
||||||
|
pluginPath,
|
||||||
|
"./",
|
||||||
|
plugin.entry
|
||||||
|
),
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
const hooks = {
|
||||||
|
onReady: [],
|
||||||
|
};
|
||||||
|
|
||||||
|
systemPlugins.forEach((plugin) => {
|
||||||
|
if (fs.existsSync(plugin.indexPath)) {
|
||||||
|
const pluginModule = __non_webpack_require__(plugin.indexPath)();
|
||||||
|
// @ts-ignore
|
||||||
|
hooks.onReady.push(pluginModule.onReady);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
const triggerReadyHooks = (ctx) => {
|
||||||
|
// @ts-ignore
|
||||||
|
hooks.onReady.forEach(hook => hook(ctx));
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
triggerReadyHooks
|
||||||
|
};
|
||||||
|
}
|
@ -1,5 +1,10 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
import { app, globalShortcut, protocol, BrowserWindow } from "electron";
|
import electron, {
|
||||||
|
app,
|
||||||
|
globalShortcut,
|
||||||
|
protocol,
|
||||||
|
BrowserWindow,
|
||||||
|
} from "electron";
|
||||||
import { main } from "./browsers";
|
import { main } from "./browsers";
|
||||||
import commonConst from "../common/utils/commonConst";
|
import commonConst from "../common/utils/commonConst";
|
||||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||||
@ -11,8 +16,11 @@ import registerHotKey from "./common/registerHotKey";
|
|||||||
import "../common/utils/localPlugin";
|
import "../common/utils/localPlugin";
|
||||||
import "../common/utils/localConfig";
|
import "../common/utils/localConfig";
|
||||||
|
|
||||||
|
import registerySystemPlugin from "./common/registerySystemPlugin";
|
||||||
|
|
||||||
class App {
|
class App {
|
||||||
private windowCreator: { init: () => void; getWindow: () => BrowserWindow };
|
private windowCreator: { init: () => void; getWindow: () => BrowserWindow };
|
||||||
|
private systemPlugins: any;
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
protocol.registerSchemesAsPrivileged([
|
protocol.registerSchemesAsPrivileged([
|
||||||
@ -23,6 +31,7 @@ class App {
|
|||||||
if (!gotTheLock) {
|
if (!gotTheLock) {
|
||||||
app.quit();
|
app.quit();
|
||||||
} else {
|
} else {
|
||||||
|
this.systemPlugins = registerySystemPlugin();
|
||||||
this.beforeReady();
|
this.beforeReady();
|
||||||
this.onReady();
|
this.onReady();
|
||||||
this.onRunning();
|
this.onRunning();
|
||||||
@ -54,6 +63,9 @@ class App {
|
|||||||
// this.init()
|
// this.init()
|
||||||
createTray(this.windowCreator.getWindow());
|
createTray(this.windowCreator.getWindow());
|
||||||
registerHotKey(this.windowCreator.getWindow());
|
registerHotKey(this.windowCreator.getWindow());
|
||||||
|
this.systemPlugins.triggerReadyHooks(
|
||||||
|
Object.assign(electron, { mainWindow: this.windowCreator.getWindow() })
|
||||||
|
);
|
||||||
};
|
};
|
||||||
if (!app.isReady()) {
|
if (!app.isReady()) {
|
||||||
app.on("ready", readyFunction);
|
app.on("ready", readyFunction);
|
||||||
|
@ -25,6 +25,8 @@ const optionsManager = ({ searchValue, baseDir, appList, openPlugin, currentPlug
|
|||||||
// todo 先搜索 plugin
|
// todo 先搜索 plugin
|
||||||
localPlugins.forEach((plugin) => {
|
localPlugins.forEach((plugin) => {
|
||||||
const feature = plugin.features;
|
const feature = plugin.features;
|
||||||
|
// 系统插件无 features 的情况,不需要再搜索
|
||||||
|
if (!feature) return;
|
||||||
feature.forEach((fe) => {
|
feature.forEach((fe) => {
|
||||||
const cmds = searchKeyValues(fe.cmds, value);
|
const cmds = searchKeyValues(fe.cmds, value);
|
||||||
options = [
|
options = [
|
||||||
|
Loading…
x
Reference in New Issue
Block a user