From cf0090029888efc6a1f4d178cec773e6cd4c5b69 Mon Sep 17 00:00:00 2001 From: Fabian-Lars Date: Wed, 17 Jan 2024 16:45:26 +0100 Subject: [PATCH] fix(upload): Prevent duplicate progress reports when using Promise.all (#908) * fix(upload): Prevent duplicate progress reports when using Promise.all * fmt --- plugins/upload/guest-js/index.ts | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/plugins/upload/guest-js/index.ts b/plugins/upload/guest-js/index.ts index f59ea0fe..08620f02 100644 --- a/plugins/upload/guest-js/index.ts +++ b/plugins/upload/guest-js/index.ts @@ -15,16 +15,17 @@ async function listenToEventIfNeeded(event: string): Promise { if (listening) { return await Promise.resolve(); } - return await appWindow - .listen(event, ({ payload }) => { - const handler = handlers.get(payload.id); - if (handler != null) { - handler(payload.progress, payload.total); - } - }) - .then(() => { - listening = true; - }); + + // We're not awaiting this Promise to prevent issues with Promise.all + // the listener will still be registered in time. + appWindow.listen(event, ({ payload }) => { + const handler = handlers.get(payload.id); + if (handler != null) { + handler(payload.progress, payload.total); + } + }); + + listening = true; } async function upload(