aboutsummaryrefslogtreecommitdiff
path: root/src/plugins
diff options
context:
space:
mode:
authorVen <vendicated@riseup.net>2022-10-29 20:45:31 +0200
committerGitHub <noreply@github.com>2022-10-29 20:45:31 +0200
commitd72542405af8873a542b55128d8b0c6311183235 (patch)
treecaa295bcec18eb56ca2360558130fc0c9c7aa047 /src/plugins
parent95aa2d9d8d850c27e88fce76f065d5e71c8022c2 (diff)
downloadVencord-d72542405af8873a542b55128d8b0c6311183235.tar.gz
Vencord-d72542405af8873a542b55128d8b0c6311183235.tar.bz2
Vencord-d72542405af8873a542b55128d8b0c6311183235.zip
Implement Subcommands; fix errors due to Settings <-> Plugins circular imports (#174)
Diffstat (limited to 'src/plugins')
-rw-r--r--src/plugins/index.ts31
1 files changed, 19 insertions, 12 deletions
diff --git a/src/plugins/index.ts b/src/plugins/index.ts
index fdb256c..be6fae3 100644
--- a/src/plugins/index.ts
+++ b/src/plugins/index.ts
@@ -28,24 +28,31 @@ const logger = new Logger("PluginManager", "#a6d189");
export const plugins = Plugins;
export const patches = [] as Patch[];
-for (const plugin of Object.values(Plugins)) if (plugin.patches && Settings.plugins[plugin.name].enabled) {
- for (const patch of plugin.patches) {
- patch.plugin = plugin.name;
- if (!Array.isArray(patch.replacement)) patch.replacement = [patch.replacement];
- patches.push(patch);
- }
+export function isPluginEnabled(p: string) {
+ return (Settings.plugins[p]?.enabled || Plugins[p]?.required) ?? false;
}
-export function startAllPlugins() {
- for (const name in Plugins) if (Settings.plugins[name].enabled) {
- startPlugin(Plugins[name]);
+for (const p of Object.values(Plugins))
+ if (p.patches && isPluginEnabled(p.name)) {
+ for (const patch of p.patches) {
+ patch.plugin = p.name;
+ if (!Array.isArray(patch.replacement))
+ patch.replacement = [patch.replacement];
+ patches.push(patch);
+ }
}
+
+export function startAllPlugins() {
+ for (const name in Plugins)
+ if (isPluginEnabled(name)) {
+ startPlugin(Plugins[name]);
+ }
}
export function startDependenciesRecursive(p: Plugin) {
let restartNeeded = false;
const failures: string[] = [];
- if (p.dependencies) for (const dep of p.dependencies) {
+ p.dependencies?.forEach(dep => {
if (!Settings.plugins[dep].enabled) {
startDependenciesRecursive(Plugins[dep]);
// If the plugin has patches, don't start the plugin, just enable it.
@@ -53,12 +60,12 @@ export function startDependenciesRecursive(p: Plugin) {
logger.warn(`Enabling dependency ${dep} requires restart.`);
Settings.plugins[dep].enabled = true;
restartNeeded = true;
- continue;
+ return;
}
const result = startPlugin(Plugins[dep]);
if (!result) failures.push(dep);
}
- }
+ });
return { restartNeeded, failures };
}