Skip to content

Commit d9b1735

Browse files
authored
feat: file download success/failure COMPASS-9095 (#6796)
feat: file download success/failure
1 parent 61505ea commit d9b1735

File tree

2 files changed

+40
-1
lines changed

2 files changed

+40
-1
lines changed

packages/compass/src/app/index.tsx

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { globalAppRegistry } from 'hadron-app-registry';
1010
import { defaultPreferencesInstance } from 'compass-preferences-model';
1111
import semver from 'semver';
1212
import { CompassElectron } from './components/entrypoint';
13-
import { openToast } from '@mongodb-js/compass-components';
13+
import { openToast, ToastBody } from '@mongodb-js/compass-components';
1414

1515
// https://github.com/nodejs/node/issues/40537
1616
dns.setDefaultResultOrder('ipv4first');
@@ -324,6 +324,28 @@ const app = {
324324
ipcRenderer?.on('compass:open-import', () => {
325325
globalAppRegistry.emit('open-active-namespace-import');
326326
});
327+
ipcRenderer?.on('download-finished', (event, { path }) => {
328+
openToast('file-download-complete', {
329+
title: 'Success',
330+
description: (
331+
<ToastBody
332+
statusMessage="File download complete"
333+
actionHandler={() => ipcRenderer?.send('show-file', path)}
334+
actionText="show file"
335+
/>
336+
),
337+
variant: 'success',
338+
});
339+
});
340+
ipcRenderer?.on('download-failed', (event, { filename }) => {
341+
openToast('file-download-failed', {
342+
title: 'Failure',
343+
description: filename
344+
? `Failed to download ${filename}`
345+
: 'Download failed',
346+
variant: 'warning',
347+
});
348+
});
327349
// Autoupdate handlers
328350
ipcRenderer?.on(
329351
'autoupdate:download-update-externally',

packages/compass/src/main/application.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,23 @@ class CompassApplication {
470470
// Accessing defaultSession is not allowed when app is not ready
471471
await app.whenReady();
472472

473+
session.defaultSession.on(
474+
'will-download',
475+
function (event, item, webContents) {
476+
item.once('done', (event, state) => {
477+
if (state === 'completed') {
478+
webContents.send('download-finished', {
479+
path: item.getSavePath(),
480+
});
481+
} else if (state === 'interrupted') {
482+
webContents.send('download-failed', {
483+
filename: item.getFilename(),
484+
});
485+
}
486+
});
487+
}
488+
);
489+
473490
session.defaultSession.webRequest.onBeforeSendHeaders(
474491
allowedCloudEndpoints,
475492
(details, callback) => {

0 commit comments

Comments
 (0)