Skip to content

Commit

Permalink
Abstract electron download path behind an opaque ID (#20271)
Browse files Browse the repository at this point in the history
  • Loading branch information
t3chguy committed Dec 21, 2021
1 parent 30cb0ae commit 211f480
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/@types/global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ type ElectronChannel =
"setBadgeCount" |
"update-downloaded" |
"userDownloadCompleted" |
"userDownloadOpen";
"userDownloadAction";

declare global {
interface Window {
Expand Down
11 changes: 8 additions & 3 deletions src/vector/platform/ElectronPlatform.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand All @@ -274,6 +278,7 @@ export default class ElectronPlatform extends VectorBasePlatform {
acceptLabel: _t("Open"),
onAccept,
dismissLabel: _t("Dismiss"),
onDismiss,
numSeconds: 10,
},
component: GenericExpiringToast,
Expand Down

0 comments on commit 211f480

Please sign in to comment.