Skip to content

Commit 7c568b2

Browse files
RiotRobott3chguy
authored andcommitted
Hold Electron toasts until after the client starts (element-hq#30768) (element-hq#30769)
Co-authored-by: Michael Telatynski <7t3chguy@gmail.com>
1 parent 96cd727 commit 7c568b2

2 files changed

Lines changed: 16 additions & 3 deletions

File tree

src/vector/platform/ElectronPlatform.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,9 @@ export default class ElectronPlatform extends BasePlatform {
185185
await this.ipc.call("callDisplayMediaCallback", source ?? { id: "", name: "", thumbnailURL: "" });
186186
});
187187

188-
this.electron.on("showToast", (ev, { title, description, priority = 40 }) => {
188+
this.electron.on("showToast", async (ev, { title, description, priority = 40 }) => {
189+
await this.clientStartedPromiseWithResolvers.promise;
190+
189191
const key = uniqueId("electron_showToast_");
190192
const onPrimaryClick = (): void => {
191193
ToastStore.sharedInstance().dismissToast(key);

test/unit-tests/vector/platform/ElectronPlatform-test.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,14 +130,25 @@ describe("ElectronPlatform", () => {
130130

131131
it("should show a toast when showToast is fired", async () => {
132132
new ElectronPlatform();
133+
dispatcher.dispatch(
134+
{
135+
action: "client_started",
136+
},
137+
true,
138+
);
133139
const spy = jest.spyOn(ToastStore.sharedInstance(), "addOrReplaceToast");
134140

135141
const [event, handler] = getElectronEventHandlerCall("showToast")!;
136142
handler({} as any, { title: "title", description: "description" });
137143

138144
expect(event).toBeTruthy();
139-
expect(spy).toHaveBeenCalledWith(
140-
expect.objectContaining({ title: "title", props: expect.objectContaining({ description: "description" }) }),
145+
await waitFor(() =>
146+
expect(spy).toHaveBeenCalledWith(
147+
expect.objectContaining({
148+
title: "title",
149+
props: expect.objectContaining({ description: "description" }),
150+
}),
151+
),
141152
);
142153
});
143154

0 commit comments

Comments
 (0)