Skip to content

Commit

Permalink
fix: old initialization behaviour
Browse files Browse the repository at this point in the history
  • Loading branch information
pylixonly committed Sep 8, 2024
1 parent 13d3672 commit c48fc16
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 17 deletions.
6 changes: 3 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ export default async () => {
window.bunny = lib;

if (!BunnySettings.isSafeMode()) {
await ColorManager.initialize();
await PluginManager.initialize();
await FontManager.initialize();
ColorManager.initialize(),
PluginManager.initialize(),
FontManager.initialize();
}

// We good :)
Expand Down
25 changes: 11 additions & 14 deletions src/lib/addons/plugins/PluginManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,28 +24,31 @@ function assert<T>(condition: T, id: string, attempt: string): asserts condition

const instances = Observable.from({}) as Record<string, PluginInstance | undefined>;
const bunnyApiObjects = new Map<string, ReturnType<typeof createBunnyPluginAPI>>();

let updateAllPromise: Promise<void>;
const updatePromiseMap = new Map<string, Promise<unknown>>();

export default {
settings: createStorage<PluginSettingsStorage>("plugins/settings.json"),
traces: createStorage<PluginTracesStorage>("plugins/infos.json"),

async initialize() {
await updateAllPromise;

for (const id of this.getAllIds()) {
this.getAllIds().map(async id => {
if (this.settings[id].enabled) {
await updatePromiseMap.get(id);
this.start(id, { throwOnPluginError: true });
}
}
});
},

async prepare(): Promise<void> {
await awaitStorage(this.settings, this.traces);
await this.migrate("VENDETTA_PLUGINS");
await Promise.all(this.getAllIds().map(id => preloadStorageIfExists(`plugins/manifests/${id}.json`)));
updateAllPromise = this.updateAll();

const pluginIds = this.getAllIds();

await Promise.all(pluginIds.map(id => preloadStorageIfExists(`plugins/manifests/${id}.json`)));
for (const id of pluginIds) {
updatePromiseMap.set(id, this.fetch(this.traces[id].sourceUrl, { id }));
}
},

migrate(oldKey: string): Promise<void> {
Expand Down Expand Up @@ -401,11 +404,5 @@ export default {
await removeFile(`plugins/scripts/${id}.js`);
await purgeStorage(`plugins/manifests/${id}.json`);
if (!keepData) await purgeStorage(`plugins/storage/${id}.json`);
},

async updateAll() {
const pluginIds = this.getAllIds();
const update = (id: string) => this.fetch(this.traces[id].sourceUrl, { id });
await Promise.allSettled(pluginIds.map(update));
}
};

0 comments on commit c48fc16

Please sign in to comment.