From 211f48002759bc7f93fc64f7b943230a03424359 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Tue, 21 Dec 2021 15:34:57 +0000 Subject: [PATCH] Abstract electron download path behind an opaque ID (#20271) --- src/@types/global.d.ts | 2 +- src/vector/platform/ElectronPlatform.tsx | 11 ++++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/@types/global.d.ts b/src/@types/global.d.ts index 4f10fde823..74a65af14f 100644 --- a/src/@types/global.d.ts +++ b/src/@types/global.d.ts @@ -32,7 +32,7 @@ type ElectronChannel = "setBadgeCount" | "update-downloaded" | "userDownloadCompleted" | - "userDownloadOpen"; + "userDownloadAction"; declare global { interface Window { diff --git a/src/vector/platform/ElectronPlatform.tsx b/src/vector/platform/ElectronPlatform.tsx index c0b860e4fd..a330cb5307 100644 --- a/src/vector/platform/ElectronPlatform.tsx +++ b/src/vector/platform/ElectronPlatform.tsx @@ -258,14 +258,18 @@ export default class ElectronPlatform extends VectorBasePlatform { dis.fire(Action.ViewUserSettings); }); - electron.on('userDownloadCompleted', (ev, { path, name }) => { - const key = `DOWNLOAD_TOAST_${path}`; + electron.on('userDownloadCompleted', (ev, { id, name }) => { + const key = `DOWNLOAD_TOAST_${id}`; const onAccept = () => { - electron.send('userDownloadOpen', { path }); + electron.send('userDownloadAction', { id, open: true }); ToastStore.sharedInstance().dismissToast(key); }; + const onDismiss = () => { + electron.send('userDownloadAction', { id }); + }; + ToastStore.sharedInstance().addOrReplaceToast({ key, title: _t("Download Completed"), @@ -274,6 +278,7 @@ export default class ElectronPlatform extends VectorBasePlatform { acceptLabel: _t("Open"), onAccept, dismissLabel: _t("Dismiss"), + onDismiss, numSeconds: 10, }, component: GenericExpiringToast,