diff --git a/src/core/ui/settings/pages/Plugins/models/bunny.ts b/src/core/ui/settings/pages/Plugins/models/bunny.ts index 1f7f203..713307c 100644 --- a/src/core/ui/settings/pages/Plugins/models/bunny.ts +++ b/src/core/ui/settings/pages/Plugins/models/bunny.ts @@ -16,9 +16,14 @@ export default function unifyBunnyPlugin(manifest: BunnyPluginManifest): Unified useObservable([pluginSettings]); }, toggle(start: boolean) { - start - ? enablePlugin(manifest.id, true) - : disablePlugin(manifest.id); + try { + start + ? enablePlugin(manifest.id, true) + : disablePlugin(manifest.id); + } catch (e) { + console.error(e); + // showToast("Failed to toggle plugin " + e, findAssetId("Small")); + } }, resolveSheetComponent() { return import("../sheets/PluginInfoActionSheet"); diff --git a/src/lib/addons/plugins/api.ts b/src/lib/addons/plugins/api.ts index 0a7223d..9ff5a4d 100644 --- a/src/lib/addons/plugins/api.ts +++ b/src/lib/addons/plugins/api.ts @@ -8,11 +8,18 @@ import { BunnyPluginObject } from "./types"; type DisposableFn = (...props: any[]) => () => unknown; function shimDisposableFn(unpatches: (() => void)[], f: F): F { - return ((...props: Parameters) => { + const dummy = ((...props: Parameters) => { const up = f(...props); unpatches.push(up); return up; }) as F; + + for (const key in f) if (typeof f[key] === "function") { + // @ts-ignore + dummy[key] = shimDisposableFn(unpatches, f[key] as DisposableFn); + } + + return dummy; } export function createBunnyPluginApi(id: string) { diff --git a/src/lib/addons/plugins/index.ts b/src/lib/addons/plugins/index.ts index 1b5903e..c7dbbe4 100644 --- a/src/lib/addons/plugins/index.ts +++ b/src/lib/addons/plugins/index.ts @@ -152,7 +152,8 @@ export async function updateRepository(repoUrl: string) { } } - await Promise.all(Object.keys(repo).map(async pluginId => { + const pluginIds = Object.keys(repo).filter(id => !id.startsWith("$")); + await Promise.all(pluginIds.map(async pluginId => { if (!storedRepo || !storedRepo[pluginId] || repo[pluginId].alwaysFetch || isGreaterVersion(repo[pluginId].version, storedRepo[pluginId].version)) { updated = true; pluginRepositories[repoUrl][pluginId] = repo[pluginId]; @@ -166,7 +167,7 @@ export async function updateRepository(repoUrl: string) { })); // Register plugins in this repository - for (const id in repo) { + for (const id of pluginIds) { const manifest = getPreloadedStorage(`plugins/manifests/${id}.json`); if (manifest === undefined) continue; // shouldn't happen, but just incase if it does