mirror of
https://github.com/Equicord/Equicord.git
synced 2025-06-18 10:57:04 -04:00
allow plugins to specify how soon their start() method is called
This commit is contained in:
parent
074ebae334
commit
371b5b0be8
4 changed files with 38 additions and 24 deletions
|
@ -12,7 +12,7 @@ import { getTheme, Theme } from "@utils/discord";
|
|||
import { Margins } from "@utils/margins";
|
||||
import { classes } from "@utils/misc";
|
||||
import { LazyComponent } from "@utils/react";
|
||||
import definePlugin, { OptionType } from "@utils/types";
|
||||
import definePlugin, { OptionType, StartAt } from "@utils/types";
|
||||
import { findByCode } from "@webpack";
|
||||
import { Button, Forms } from "@webpack/common";
|
||||
|
||||
|
@ -87,25 +87,13 @@ export default definePlugin({
|
|||
description: "Recreation of the old client theme experiment. Add a color to your Discord client theme",
|
||||
settings,
|
||||
|
||||
patches: [
|
||||
{
|
||||
find: "Could not find app-mount",
|
||||
replacement: {
|
||||
match: /(?<=Could not find app-mount"\))/,
|
||||
replace: ",$self.addThemeInitializer()"
|
||||
}
|
||||
}
|
||||
],
|
||||
|
||||
addThemeInitializer() {
|
||||
document.addEventListener("DOMContentLoaded", this.themeInitializer = () => {
|
||||
updateColorVars(settings.store.color);
|
||||
generateColorOffsets();
|
||||
});
|
||||
startAt: StartAt.DOMContentLoaded,
|
||||
start() {
|
||||
updateColorVars(settings.store.color);
|
||||
generateColorOffsets();
|
||||
},
|
||||
|
||||
stop() {
|
||||
document.removeEventListener("DOMContentLoaded", this.themeInitializer);
|
||||
document.getElementById("clientThemeVars")?.remove();
|
||||
document.getElementById("clientThemeOffsets")?.remove();
|
||||
}
|
||||
|
|
|
@ -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]);
|
||||
}
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue