Abstract electron download path behind an opaque ID (#20271)

pull/20311/head
Michael Telatynski 2021-12-21 15:34:57 +00:00 committed by GitHub
parent 30cb0ae96d
commit 211f480027
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 4 deletions

View File

@ -32,7 +32,7 @@ type ElectronChannel =
"setBadgeCount" |
"update-downloaded" |
"userDownloadCompleted" |
"userDownloadOpen";
"userDownloadAction";
declare global {
interface Window {

View File

@ -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,