Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion packages/compass/src/app/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { globalAppRegistry } from 'hadron-app-registry';
import { defaultPreferencesInstance } from 'compass-preferences-model';
import semver from 'semver';
import { CompassElectron } from './components/entrypoint';
import { openToast } from '@mongodb-js/compass-components';
import { openToast, ToastBody } from '@mongodb-js/compass-components';

// https://github.com/nodejs/node/issues/40537
dns.setDefaultResultOrder('ipv4first');
Expand Down Expand Up @@ -324,6 +324,28 @@ const app = {
ipcRenderer?.on('compass:open-import', () => {
globalAppRegistry.emit('open-active-namespace-import');
});
ipcRenderer?.on('download-finished', (event, { path }) => {
openToast('file-download-complete', {
title: 'Success',
description: (
<ToastBody
statusMessage="File download complete"
actionHandler={() => ipcRenderer?.send('show-file', path)}
actionText="show file"
/>
),
variant: 'success',
});
});
ipcRenderer?.on('download-failed', (event, { filename }) => {
openToast('file-download-failed', {
title: 'Failure',
description: filename
? `Failed to download ${filename}`
: 'Download failed',
variant: 'warning',
});
});
// Autoupdate handlers
ipcRenderer?.on(
'autoupdate:download-update-externally',
Expand Down
17 changes: 17 additions & 0 deletions packages/compass/src/main/application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,23 @@ class CompassApplication {
// Accessing defaultSession is not allowed when app is not ready
await app.whenReady();

session.defaultSession.on(
'will-download',
function (event, item, webContents) {
item.once('done', (event, state) => {
if (state === 'completed') {
webContents.send('download-finished', {
path: item.getSavePath(),
});
} else if (state === 'interrupted') {
webContents.send('download-failed', {
filename: item.getFilename(),
});
}
});
}
);

session.defaultSession.webRequest.onBeforeSendHeaders(
allowedCloudEndpoints,
(details, callback) => {
Expand Down
Loading