diff --git a/src/lib/plugins.ts b/src/lib/plugins.ts index 09121fe..d44236a 100644 --- a/src/lib/plugins.ts +++ b/src/lib/plugins.ts @@ -2,6 +2,7 @@ import { PluginManifest, Plugin } from "@types"; import { safeFetch } from "@lib/utils"; import { awaitSyncWrapper, createMMKVBackend, createStorage, wrapSync } from "@lib/storage"; import { MMKVManager } from "@lib/native"; +import { allSettled } from "@lib/polyfills"; import logger, { logModule } from "@lib/logger"; import settings from "@lib/settings"; @@ -131,7 +132,7 @@ export async function initPlugins() { if (!settings.safeMode?.enabled) { // Loop over any plugin that is enabled, update it if allowed, then start it. - await Promise.allSettled(allIds.filter(pl => plugins[pl].enabled).map(async (pl) => (plugins[pl].update && await fetchPlugin(pl).catch((e: Error) => logger.error(e.message)), await startPlugin(pl)))); + await allSettled(allIds.filter(pl => plugins[pl].enabled).map(async (pl) => (plugins[pl].update && await fetchPlugin(pl).catch((e: Error) => logger.error(e.message)), await startPlugin(pl)))); // Wait for the above to finish, then update all disabled plugins that are allowed to. allIds.filter(pl => !plugins[pl].enabled && plugins[pl].update).forEach(pl => fetchPlugin(pl)); }; diff --git a/src/lib/polyfills.ts b/src/lib/polyfills.ts new file mode 100644 index 0000000..7c745e6 --- /dev/null +++ b/src/lib/polyfills.ts @@ -0,0 +1,5 @@ +//! Starting from 202.4, Promise.allSettled may be undefined due to conflicting then/promise versions, so we use our own. +const allSettledFulfill = (value: T) => ({ status: "fulfilled", value }); +const allSettledReject = (reason: T) => ({ status: "rejected", reason }); +const mapAllSettled = (item: T) => Promise.resolve(item).then(allSettledFulfill, allSettledReject); +export const allSettled = (iterator: T) => Promise.all(Array.from(iterator).map(mapAllSettled));