From d602f60a9672b16d777f66457da5fd4c447c2aea Mon Sep 17 00:00:00 2001 From: redstonekasi Date: Fri, 20 Oct 2023 19:04:37 +0200 Subject: [PATCH] [Lib > Plugins] Use our own allSettled --- src/lib/plugins.ts | 3 ++- src/lib/polyfills.ts | 5 +++++ 2 files changed, 7 insertions(+), 1 deletion(-) create mode 100644 src/lib/polyfills.ts 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));