From 81edc1407071c6c0328f40a1ee487ea0388b9a7e Mon Sep 17 00:00:00 2001 From: Vendicated Date: Sat, 12 Nov 2022 15:09:02 +0100 Subject: fix PronounDB crash with new profile in dms, force start dependencies --- src/plugins/index.ts | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) (limited to 'src/plugins/index.ts') diff --git a/src/plugins/index.ts b/src/plugins/index.ts index d3842aa..268e200 100644 --- a/src/plugins/index.ts +++ b/src/plugins/index.ts @@ -30,11 +30,36 @@ export const PMLogger = logger; export const plugins = Plugins; export const patches = [] as Patch[]; +const settings = Settings.plugins; + export function isPluginEnabled(p: string) { - return (Settings.plugins[p]?.enabled || Plugins[p]?.required) ?? false; + return ( + Plugins[p]?.required || + Plugins[p]?.isDependency || + settings[p]?.enabled + ) ?? false; +} + +const pluginsValues = Object.values(Plugins); + +// First roundtrip to mark and force enable dependencies +for (const p of pluginsValues) { + p.dependencies?.forEach(d => { + const dep = Plugins[d]; + if (dep) { + settings[d].enabled = true; + dep.isDependency = true; + } + else { + const error = new Error(`Plugin ${p.name} has unresolved dependency ${d}`); + if (IS_DEV) + throw error; + logger.warn(error); + } + }); } -for (const p of Object.values(Plugins)) +for (const p of pluginsValues) if (p.patches && isPluginEnabled(p.name)) { for (const patch of p.patches) { patch.plugin = p.name; -- cgit