fix: refresh plugin settings after enabling a plugin and match select and disabled bar styling

This commit is contained in:
LukeGus committed 2026-10-06 23:08:21 -05:00
1 parent 27819c477c
commit 8666533162
11 files changed
+136 -56

No files matched your search

+35
View File
@@ -0,0 +1,35 @@
import { useEffect, useState } from "react";
import {
getPlugins,
PLUGINS_CHANGED_EVENT,
type PluginSummary,
} from "@/api/plugins-api";
/**
* Every installed plugin, read again whenever one is enabled, disabled,
* installed or removed, so what a plugin adds shows up without a reload.
*/
export function useInstalledPlugins(): PluginSummary[] {
const [plugins, setPlugins] = useState<PluginSummary[]>([]);
useEffect(() => {
let cancelled = false;
let request = 0;
const load = () => {
const current = ++request;
void getPlugins()
.then((loaded) => {
if (!cancelled && current === request) setPlugins(loaded);
})
.catch(() => {});
};
load();
window.addEventListener(PLUGINS_CHANGED_EVENT, load);
return () => {
cancelled = true;
window.removeEventListener(PLUGINS_CHANGED_EVENT, load);
};
}, []);
return plugins;
}