aboutsummaryrefslogtreecommitdiffstats
path: root/src/electron/ipc-api/download.js
diff options
context:
space:
mode:
authorLibravatar Amine El Mouafik <412895+kytwb@users.noreply.github.com>2021-02-08 10:34:45 +0100
committerLibravatar GitHub <noreply@github.com>2021-02-08 10:34:45 +0100
commit035002ceedf78d5ec73eabc0df7f06139939b967 (patch)
tree1c0d1e9531bae05fb65d70b9ea25baf404b74fe1 /src/electron/ipc-api/download.js
parentdocs: add k0staa as a contributor (#1193) (diff)
downloadferdium-app-035002ceedf78d5ec73eabc0df7f06139939b967.tar.gz
ferdium-app-035002ceedf78d5ec73eabc0df7f06139939b967.tar.zst
ferdium-app-035002ceedf78d5ec73eabc0df7f06139939b967.zip
Synchronize with Franz 5.6.0 (#1033)
Co-authored-by: FranzBot <i18n@meetfranz.com> Co-authored-by: vantezzen <hello@vantezzen.io> Co-authored-by: Makazzz <makazzzpro@live.ca> Co-authored-by: Stefan Malzner <stefan@adlk.io> Co-authored-by: Amine Mouafik <amine@mouafik.fr>
Diffstat (limited to 'src/electron/ipc-api/download.js')
-rw-r--r--src/electron/ipc-api/download.js26
1 files changed, 19 insertions, 7 deletions
diff --git a/src/electron/ipc-api/download.js b/src/electron/ipc-api/download.js
index 36eca3c9f..16de66229 100644
--- a/src/electron/ipc-api/download.js
+++ b/src/electron/ipc-api/download.js
@@ -17,9 +17,15 @@ function decodeBase64Image(dataString) {
17 17
18export default (params) => { 18export default (params) => {
19 ipcMain.on('download-file', async (event, { url, content, fileOptions = {} }) => { 19 ipcMain.on('download-file', async (event, { url, content, fileOptions = {} }) => {
20 // We're passing a fake browserWindow to `electron-dl` in order to access the
21 // webContents of the webview that has initiated the download
22 const fakeWindow = {
23 webContents: event.sender.webContents,
24 };
25
20 try { 26 try {
21 if (!content) { 27 if (!content) {
22 const dl = await download(params.mainWindow, url, { 28 const dl = await download(fakeWindow, url, {
23 saveAs: true, 29 saveAs: true,
24 }); 30 });
25 debug('File saved to', dl.savePath); 31 debug('File saved to', dl.savePath);
@@ -27,14 +33,20 @@ export default (params) => {
27 const extension = mime.extension(fileOptions.mime); 33 const extension = mime.extension(fileOptions.mime);
28 const filename = `${fileOptions.name}.${extension}`; 34 const filename = `${fileOptions.name}.${extension}`;
29 35
30 dialog.showSaveDialog(params.mainWindow, { 36 try {
31 defaultPath: filename, 37 const saveDialog = await dialog.showSaveDialog(params.mainWindow, {
32 }, (name) => { 38 defaultPath: filename,
39 });
40
41 if (saveDialog.canceled) return;
42
33 const binaryImage = decodeBase64Image(content); 43 const binaryImage = decodeBase64Image(content);
34 fs.writeFileSync(name, binaryImage, 'binary'); 44 fs.writeFileSync(saveDialog.filePath, binaryImage, 'binary');
35 45
36 debug('File blob saved to', name); 46 debug('File blob saved to', saveDialog.filePath);
37 }); 47 } catch (err) {
48 console.log(err);
49 }
38 } 50 }
39 } catch (e) { 51 } catch (e) {
40 console.error(e); 52 console.error(e);