From 0e66c4a1f598d3ec8efa9e5314bbb600c71165ec Mon Sep 17 00:00:00 2001 From: Nuckyz <61953774+Nuckyz@users.noreply.github.com> Date: Tue, 7 May 2024 02:46:52 -0300 Subject: [PATCH] Fix subscribing to plugin flux events twice --- src/plugins/index.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/plugins/index.ts b/src/plugins/index.ts index 2d5e3e5a..488847d1 100644 --- a/src/plugins/index.ts +++ b/src/plugins/index.ts @@ -36,6 +36,7 @@ export const patches = [] as Patch[]; /** Whether we have subscribed to flux events of all the enabled plugins when FluxDispatcher was ready */ let enabledPluginsSubscribedFlux = false; +const subscribedFluxEventsPlugins = new Set(); const settings = Settings.plugins; @@ -123,7 +124,9 @@ export function startDependenciesRecursive(p: Plugin) { } export function subscribePluginFluxEvents(p: Plugin, fluxDispatcher: typeof FluxDispatcher) { - if (p.flux) { + if (p.flux && !subscribedFluxEventsPlugins.has(p.name)) { + subscribedFluxEventsPlugins.add(p.name); + logger.debug("Subscribing to flux events of plugin", p.name); for (const [event, handler] of Object.entries(p.flux)) { fluxDispatcher.subscribe(event as FluxEvents, handler); @@ -133,6 +136,8 @@ export function subscribePluginFluxEvents(p: Plugin, fluxDispatcher: typeof Flux export function unsubscribePluginFluxEvents(p: Plugin, fluxDispatcher: typeof FluxDispatcher) { if (p.flux) { + subscribedFluxEventsPlugins.delete(p.name); + logger.debug("Unsubscribing from flux events of plugin", p.name); for (const [event, handler] of Object.entries(p.flux)) { fluxDispatcher.unsubscribe(event as FluxEvents, handler);