From 672d07e1e2a3fd8f0cce21fc162b596424e17284 Mon Sep 17 00:00:00 2001 From: Oscar Hinton Date: Tue, 27 Apr 2021 16:44:28 +0200 Subject: [PATCH] Change download to happen in the renderer (#365) --- .../services/electronMainMessaging.service.ts | 11 ----------- .../services/electronPlatformUtils.service.ts | 11 +++++++---- 2 files changed, 7 insertions(+), 15 deletions(-) diff --git a/src/electron/services/electronMainMessaging.service.ts b/src/electron/services/electronMainMessaging.service.ts index c620fd660b..69d5b1ba12 100644 --- a/src/electron/services/electronMainMessaging.service.ts +++ b/src/electron/services/electronMainMessaging.service.ts @@ -19,17 +19,6 @@ export class ElectronMainMessagingService implements MessagingService { return dialog.showMessageBox(options); }); - ipcMain.handle('saveFile', (event, options) => { - dialog.showSaveDialog(windowMain.win, { - defaultPath: options.fileName, - showsTagField: false, - }).then(ret => { - if (ret.filePath != null) { - fs.writeFile(ret.filePath, options.buffer, { mode: 0o600 }); - } - }); - }); - ipcMain.handle('openContextMenu', (event, options: {menu: RendererMenuItem[]}) => { return new Promise(resolve => { const menu = new Menu(); diff --git a/src/electron/services/electronPlatformUtils.service.ts b/src/electron/services/electronPlatformUtils.service.ts index fd7980d342..a3db37dc7d 100644 --- a/src/electron/services/electronPlatformUtils.service.ts +++ b/src/electron/services/electronPlatformUtils.service.ts @@ -97,10 +97,13 @@ export class ElectronPlatformUtilsService implements PlatformUtilsService { } saveFile(win: Window, blobData: any, blobOptions: any, fileName: string): void { - ipcRenderer.invoke('saveFile', { - fileName: fileName, - buffer: Buffer.from(blobData), - }); + const blob = new Blob([blobData], blobOptions); + const a = win.document.createElement('a'); + a.href = URL.createObjectURL(blob); + a.download = fileName; + win.document.body.appendChild(a); + a.click(); + win.document.body.removeChild(a); } getApplicationVersion(): Promise {