Skip to content

Commit 3c13f55

Browse files
authored
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 <[email protected]> * Update test Signed-off-by: Michael Telatynski <[email protected]> * Lint Signed-off-by: Michael Telatynski <[email protected]> --------- Signed-off-by: Michael Telatynski <[email protected]>
1 parent 3432613 commit 3c13f55

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

src/vector/platform/ElectronPlatform.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ export default class ElectronPlatform extends BasePlatform {
9797
private badgeOverlayRenderer?: BadgeOverlayRenderer;
9898
private config!: IConfigOptions;
9999
private supportedSettings?: Record<string, boolean>;
100+
private clientStartedPromiseWithResolvers = Promise.withResolvers<void>();
100101

101102
public constructor() {
102103
super();
@@ -184,7 +185,9 @@ export default class ElectronPlatform extends BasePlatform {
184185
await this.ipc.call("callDisplayMediaCallback", source ?? { id: "", name: "", thumbnailURL: "" });
185186
});
186187

187-
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+
188191
const key = uniqueId("electron_showToast_");
189192
const onPrimaryClick = (): void => {
190193
ToastStore.sharedInstance().dismissToast(key);
@@ -214,6 +217,10 @@ export default class ElectronPlatform extends BasePlatform {
214217
if (["call_state"].includes(payload.action)) {
215218
this.electron.send("app_onAction", payload);
216219
}
220+
221+
if (payload.action === "client_started") {
222+
this.clientStartedPromiseWithResolvers.resolve();
223+
}
217224
}
218225

219226
private async initialise(): Promise<void> {

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)