From 3c13f55b74c4115898219c2c4f5d854594b3c25f Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Tue, 16 Sep 2025 11:16:12 +0100 Subject: [PATCH] Hold Electron toasts until after the client starts (#30768) * Hold Electron toasts until after the client starts as otherwise they won't be shown and will be reset out of existence Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Update test Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Lint Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> --------- Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> --- src/vector/platform/ElectronPlatform.tsx | 9 ++++++++- .../vector/platform/ElectronPlatform-test.ts | 15 +++++++++++++-- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/src/vector/platform/ElectronPlatform.tsx b/src/vector/platform/ElectronPlatform.tsx index 579096d5c0..4139f73d53 100644 --- a/src/vector/platform/ElectronPlatform.tsx +++ b/src/vector/platform/ElectronPlatform.tsx @@ -97,6 +97,7 @@ export default class ElectronPlatform extends BasePlatform { private badgeOverlayRenderer?: BadgeOverlayRenderer; private config!: IConfigOptions; private supportedSettings?: Record; + private clientStartedPromiseWithResolvers = Promise.withResolvers(); public constructor() { super(); @@ -184,7 +185,9 @@ export default class ElectronPlatform extends BasePlatform { await this.ipc.call("callDisplayMediaCallback", source ?? { id: "", name: "", thumbnailURL: "" }); }); - this.electron.on("showToast", (ev, { title, description, priority = 40 }) => { + this.electron.on("showToast", async (ev, { title, description, priority = 40 }) => { + await this.clientStartedPromiseWithResolvers.promise; + const key = uniqueId("electron_showToast_"); const onPrimaryClick = (): void => { ToastStore.sharedInstance().dismissToast(key); @@ -214,6 +217,10 @@ export default class ElectronPlatform extends BasePlatform { if (["call_state"].includes(payload.action)) { this.electron.send("app_onAction", payload); } + + if (payload.action === "client_started") { + this.clientStartedPromiseWithResolvers.resolve(); + } } private async initialise(): Promise { diff --git a/test/unit-tests/vector/platform/ElectronPlatform-test.ts b/test/unit-tests/vector/platform/ElectronPlatform-test.ts index ec1c18bb46..90b69f7fcf 100644 --- a/test/unit-tests/vector/platform/ElectronPlatform-test.ts +++ b/test/unit-tests/vector/platform/ElectronPlatform-test.ts @@ -130,14 +130,25 @@ describe("ElectronPlatform", () => { it("should show a toast when showToast is fired", async () => { new ElectronPlatform(); + dispatcher.dispatch( + { + action: "client_started", + }, + true, + ); const spy = jest.spyOn(ToastStore.sharedInstance(), "addOrReplaceToast"); const [event, handler] = getElectronEventHandlerCall("showToast")!; handler({} as any, { title: "title", description: "description" }); expect(event).toBeTruthy(); - expect(spy).toHaveBeenCalledWith( - expect.objectContaining({ title: "title", props: expect.objectContaining({ description: "description" }) }), + await waitFor(() => + expect(spy).toHaveBeenCalledWith( + expect.objectContaining({ + title: "title", + props: expect.objectContaining({ description: "description" }), + }), + ), ); });