File tree Expand file tree Collapse file tree 2 files changed +40
-1
lines changed Expand file tree Collapse file tree 2 files changed +40
-1
lines changed Original file line number Diff line number Diff line change @@ -10,7 +10,7 @@ import { globalAppRegistry } from 'hadron-app-registry';
1010import { defaultPreferencesInstance } from 'compass-preferences-model' ;
1111import semver from 'semver' ;
1212import { 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
1616dns . 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' ,
Original file line number Diff line number Diff 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 ) => {
You can’t perform that action at this time.
0 commit comments