diff --git a/app/components/PluginIcon.tsx b/app/components/PluginIcon.tsx
index 889525f432..bfffb2b031 100644
--- a/app/components/PluginIcon.tsx
+++ b/app/components/PluginIcon.tsx
@@ -1,7 +1,8 @@
import { observer } from "mobx-react";
import * as React from "react";
import styled from "styled-components";
-import { Hook, PluginManager } from "~/utils/PluginManager";
+import Logger from "~/utils/Logger";
+import { Hook, usePluginValue } from "~/utils/PluginManager";
type Props = {
/** The ID of the plugin to render an Icon for. */
@@ -16,8 +17,7 @@ type Props = {
* Renders an icon defined in a plugin (Hook.Icon).
*/
function PluginIcon({ id, color, size = 24 }: Props) {
- const plugin = PluginManager.getHook(Hook.Icon, id);
- const Icon = plugin?.value;
+ const Icon = usePluginValue(Hook.Icon, id);
if (Icon) {
return (
@@ -27,6 +27,7 @@ function PluginIcon({ id, color, size = 24 }: Props) {
);
}
+ Logger.warn("No Icon registered for plugin", { id });
return null;
}
diff --git a/app/scenes/Login/components/AuthenticationProvider.tsx b/app/scenes/Login/components/AuthenticationProvider.tsx
index 0eede84bd0..17ec432919 100644
--- a/app/scenes/Login/components/AuthenticationProvider.tsx
+++ b/app/scenes/Login/components/AuthenticationProvider.tsx
@@ -93,17 +93,15 @@ function AuthenticationProvider(props: Props) {
}
return (
-
- (window.location.href = href)}
- icon={}
- fullwidth
- >
- {t("Continue with {{ authProviderName }}", {
- authProviderName: name,
- })}
-
-
+ (window.location.href = href)}
+ icon={}
+ fullwidth
+ >
+ {t("Continue with {{ authProviderName }}", {
+ authProviderName: name,
+ })}
+
);
}
diff --git a/app/utils/PluginManager.ts b/app/utils/PluginManager.ts
index ddda02c120..9df44c8468 100644
--- a/app/utils/PluginManager.ts
+++ b/app/utils/PluginManager.ts
@@ -1,6 +1,7 @@
import isArray from "lodash/isArray";
import sortBy from "lodash/sortBy";
-import { observable } from "mobx";
+import { action, observable } from "mobx";
+import { useComputed } from "~/hooks/useComputed";
import Logger from "./Logger";
import isCloudHosted from "./isCloudHosted";
@@ -22,7 +23,7 @@ type PluginValueMap = {
/** The displayed icon of the plugin. */
icon: React.ElementType;
/** The settings screen somponent, should be lazy loaded. */
- component: React.LazyExoticComponent>;
+ component: React.LazyExoticComponent;
};
[Hook.Icon]: React.ElementType;
};
@@ -63,6 +64,7 @@ export class PluginManager {
this.register(plugins);
}
+ @action
private static register(plugin: Plugin) {
const enabledInDeployment =
!plugin?.deployments ||
@@ -75,7 +77,7 @@ export class PluginManager {
}
if (!this.plugins.has(plugin.type)) {
- this.plugins.set(plugin.type, []);
+ this.plugins.set(plugin.type, observable.array([]));
}
this.plugins
@@ -108,7 +110,9 @@ export class PluginManager {
* @returns A plugin
*/
public static getHook(type: T, id: string) {
- return this.getHooks(type).find((hook) => hook.id === id);
+ return this.plugins.get(type)?.find((hook) => hook.id === id) as
+ | Plugin
+ | undefined;
}
/**
@@ -121,11 +125,21 @@ export class PluginManager {
const r = import.meta.glob("../../plugins/*/client/index.{ts,js,tsx,jsx}");
await Promise.all(Object.keys(r).map((key: string) => r[key]()));
-
this.loaded = true;
}
private static plugins = observable.map[]>();
+ @observable
private static loaded = false;
}
+
+/**
+ * Convenience hook to get the value for a specific plugin and type.
+ */
+export function usePluginValue(type: T, id: string) {
+ return useComputed(
+ () => PluginManager.getHook(type, id)?.value,
+ [type, id]
+ );
+}
diff --git a/plugins/azure/client/index.tsx b/plugins/azure/client/index.tsx
index c7e5c49c5e..b3dbea4a24 100644
--- a/plugins/azure/client/index.tsx
+++ b/plugins/azure/client/index.tsx
@@ -2,7 +2,7 @@ import { Hook, PluginManager } from "~/utils/PluginManager";
import config from "../plugin.json";
import Icon from "./Icon";
-export default PluginManager.add([
+PluginManager.add([
{
...config,
type: Hook.Icon,
diff --git a/plugins/github/client/index.tsx b/plugins/github/client/index.tsx
index 8700687cd2..fbdc2d7824 100644
--- a/plugins/github/client/index.tsx
+++ b/plugins/github/client/index.tsx
@@ -3,7 +3,7 @@ import { Hook, PluginManager } from "~/utils/PluginManager";
import config from "../plugin.json";
import Icon from "./Icon";
-export default PluginManager.add([
+PluginManager.add([
{
...config,
type: Hook.Settings,
diff --git a/plugins/google/client/index.tsx b/plugins/google/client/index.tsx
index c7e5c49c5e..b3dbea4a24 100644
--- a/plugins/google/client/index.tsx
+++ b/plugins/google/client/index.tsx
@@ -2,7 +2,7 @@ import { Hook, PluginManager } from "~/utils/PluginManager";
import config from "../plugin.json";
import Icon from "./Icon";
-export default PluginManager.add([
+PluginManager.add([
{
...config,
type: Hook.Icon,
diff --git a/plugins/googleanalytics/client/index.tsx b/plugins/googleanalytics/client/index.tsx
index 8700687cd2..fbdc2d7824 100644
--- a/plugins/googleanalytics/client/index.tsx
+++ b/plugins/googleanalytics/client/index.tsx
@@ -3,7 +3,7 @@ import { Hook, PluginManager } from "~/utils/PluginManager";
import config from "../plugin.json";
import Icon from "./Icon";
-export default PluginManager.add([
+PluginManager.add([
{
...config,
type: Hook.Settings,
diff --git a/plugins/matomo/client/index.tsx b/plugins/matomo/client/index.tsx
index 8700687cd2..fbdc2d7824 100644
--- a/plugins/matomo/client/index.tsx
+++ b/plugins/matomo/client/index.tsx
@@ -3,7 +3,7 @@ import { Hook, PluginManager } from "~/utils/PluginManager";
import config from "../plugin.json";
import Icon from "./Icon";
-export default PluginManager.add([
+PluginManager.add([
{
...config,
type: Hook.Settings,
diff --git a/plugins/slack/client/index.tsx b/plugins/slack/client/index.tsx
index 8700687cd2..6f1797b65f 100644
--- a/plugins/slack/client/index.tsx
+++ b/plugins/slack/client/index.tsx
@@ -3,7 +3,7 @@ import { Hook, PluginManager } from "~/utils/PluginManager";
import config from "../plugin.json";
import Icon from "./Icon";
-export default PluginManager.add([
+PluginManager.add([
{
...config,
type: Hook.Settings,
@@ -13,4 +13,9 @@ export default PluginManager.add([
component: React.lazy(() => import("./Settings")),
},
},
+ {
+ ...config,
+ type: Hook.Icon,
+ value: Icon,
+ },
]);
diff --git a/plugins/webhooks/client/index.tsx b/plugins/webhooks/client/index.tsx
index 8700687cd2..fbdc2d7824 100644
--- a/plugins/webhooks/client/index.tsx
+++ b/plugins/webhooks/client/index.tsx
@@ -3,7 +3,7 @@ import { Hook, PluginManager } from "~/utils/PluginManager";
import config from "../plugin.json";
import Icon from "./Icon";
-export default PluginManager.add([
+PluginManager.add([
{
...config,
type: Hook.Settings,