add getActivePlugins and isActive

This commit is contained in:
Araxeus
2023-03-19 03:00:17 +02:00
parent 7d93e9f031
commit a6242d13ae

View File

@ -3,6 +3,30 @@ const { ipcRenderer, ipcMain } = require("electron");
const defaultConfig = require("./defaults");
const { getOptions, setOptions, setMenuOptions } = require("./plugins");
const activePlugins = {};
/**
* [!IMPORTANT!]
* The method is **sync** in the main process and **async** in the renderer process.
*/
module.exports.getActivePlugins =
process.type === "renderer"
? async () => ipcRenderer.invoke("get-active-plugins")
: () => activePlugins;
if (process.type === "browser") {
ipcMain.handle("get-active-plugins", this.getActivePlugins);
}
/**
* [!IMPORTANT!]
* The method is **sync** in the main process and **async** in the renderer process.
*/
module.exports.isActive =
process.type === "renderer"
? async (plugin) =>
plugin in (await ipcRenderer.invoke("get-active-plugins"))
: (plugin) => plugin in activePlugins;
/**
* This class is used to create a dynamic synced config for plugins.
*
@ -46,6 +70,8 @@ module.exports.PluginConfig = class PluginConfig {
if (this.#enableFront) {
this.#setupFront();
}
activePlugins[name] = this;
}
get = (option) => {
@ -85,6 +111,7 @@ module.exports.PluginConfig = class PluginConfig {
setMenuOptions(this.#name, this.#config);
};
/** Called only from back */
#save() {
setOptions(this.#name, this.#config);
}