Skip to content

Commit

Permalink
fix(plugins): filter out internal fields when loading plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
pylixonly committed Nov 9, 2024
1 parent 795639a commit e141a62
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
11 changes: 8 additions & 3 deletions src/core/ui/settings/pages/Plugins/models/bunny.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
9 changes: 8 additions & 1 deletion src/lib/addons/plugins/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,18 @@ import { BunnyPluginObject } from "./types";

type DisposableFn = (...props: any[]) => () => unknown;
function shimDisposableFn<F extends DisposableFn>(unpatches: (() => void)[], f: F): F {
return ((...props: Parameters<F>) => {
const dummy = ((...props: Parameters<F>) => {
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) {
Expand Down
5 changes: 3 additions & 2 deletions src/lib/addons/plugins/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand All @@ -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<t.BunnyPluginManifest>(`plugins/manifests/${id}.json`);
if (manifest === undefined) continue; // shouldn't happen, but just incase if it does

Expand Down

0 comments on commit e141a62

Please sign in to comment.