fix PronounDB crash with new profile in dms, force start dependencies

This commit is contained in:
Vendicated 2022-11-12 15:09:02 +01:00
parent b48c8d8a4a
commit 81edc14070
No known key found for this signature in database
GPG key ID: EC781ADFB93EFFA3
8 changed files with 80 additions and 24 deletions

View file

@ -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;
}
for (const p of Object.values(Plugins))
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 pluginsValues)
if (p.patches && isPluginEnabled(p.name)) {
for (const patch of p.patches) {
patch.plugin = p.name;