allow plugins to specify how soon their start() method is called

This commit is contained in:
V 2023-11-22 06:14:16 +01:00
parent 074ebae334
commit 371b5b0be8
No known key found for this signature in database
GPG key ID: A1DC0CFB5615D905
4 changed files with 38 additions and 24 deletions

View file

@ -19,7 +19,7 @@
import { registerCommand, unregisterCommand } from "@api/Commands";
import { Settings } from "@api/Settings";
import { Logger } from "@utils/Logger";
import { Patch, Plugin } from "@utils/types";
import { Patch, Plugin, StartAt } from "@utils/types";
import { FluxDispatcher } from "@webpack/common";
import { FluxEvents } from "@webpack/types";
@ -85,9 +85,15 @@ for (const p of pluginsValues) {
}
}
export const startAllPlugins = traceFunction("startAllPlugins", function startAllPlugins() {
export const startAllPlugins = traceFunction("startAllPlugins", function startAllPlugins(target: StartAt) {
logger.info(`Starting plugins (stage ${target})`);
for (const name in Plugins)
if (isPluginEnabled(name)) {
const p = Plugins[name];
const startAt = p.startAt ?? StartAt.WebpackReady;
if (startAt !== target) continue;
startPlugin(Plugins[name]);
}
});