diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/electron/ipc-api/download.ts | 6 | ||||
-rw-r--r-- | src/webview/contextMenuBuilder.ts | 45 |
2 files changed, 31 insertions, 20 deletions
diff --git a/src/electron/ipc-api/download.ts b/src/electron/ipc-api/download.ts index 518a7091c..851bff4c3 100644 --- a/src/electron/ipc-api/download.ts +++ b/src/electron/ipc-api/download.ts | |||
@@ -1,6 +1,5 @@ | |||
1 | import { ipcMain, dialog, BrowserWindow } from 'electron'; | 1 | import { ipcMain, dialog, BrowserWindow } from 'electron'; |
2 | import { download } from 'electron-dl'; | 2 | import { download } from 'electron-dl'; |
3 | import mime from 'mime-types'; | ||
4 | import { writeFileSync } from 'fs-extra'; | 3 | import { writeFileSync } from 'fs-extra'; |
5 | import { PathLike } from 'fs'; | 4 | import { PathLike } from 'fs'; |
6 | 5 | ||
@@ -24,12 +23,9 @@ export default (params: { mainWindow: BrowserWindow }) => { | |||
24 | 23 | ||
25 | try { | 24 | try { |
26 | if (content) { | 25 | if (content) { |
27 | const extension = mime.extension(fileOptions.mime); | ||
28 | const filename = `${fileOptions.name}.${extension}`; | ||
29 | |||
30 | try { | 26 | try { |
31 | const saveDialog = await dialog.showSaveDialog(params.mainWindow, { | 27 | const saveDialog = await dialog.showSaveDialog(params.mainWindow, { |
32 | defaultPath: filename, | 28 | defaultPath: fileOptions.name, |
33 | }); | 29 | }); |
34 | 30 | ||
35 | if (saveDialog.canceled) return; | 31 | if (saveDialog.canceled) return; |
diff --git a/src/webview/contextMenuBuilder.ts b/src/webview/contextMenuBuilder.ts index 2e64977c1..6d904eee3 100644 --- a/src/webview/contextMenuBuilder.ts +++ b/src/webview/contextMenuBuilder.ts | |||
@@ -633,27 +633,42 @@ export class ContextMenuBuilder { | |||
633 | menu.append(copyImageUrl); | 633 | menu.append(copyImageUrl); |
634 | 634 | ||
635 | // TODO: This doesn't seem to work on linux, so, limiting to Mac for now | 635 | // TODO: This doesn't seem to work on linux, so, limiting to Mac for now |
636 | if (isMac && menuInfo.srcURL.startsWith('blob:')) { | 636 | if (isMac) { |
637 | const downloadImage = new MenuItem({ | 637 | const clickHandler = menuInfo.srcURL.startsWith('blob:') |
638 | label: this.stringTable.downloadImage(), | 638 | ? () => { |
639 | click: () => { | 639 | const urlWithoutBlob = menuInfo.srcURL.slice(5); |
640 | const urlWithoutBlob = menuInfo.srcURL.slice(5); | 640 | this.convertImageToBase64(menuInfo.srcURL, (dataURL: any) => { |
641 | this.convertImageToBase64(menuInfo.srcURL, (dataURL: any) => { | 641 | const url = new window.URL(urlWithoutBlob); |
642 | const url = new window.URL(urlWithoutBlob); | 642 | const fileName = url.pathname.slice(1); |
643 | ipcRenderer.send('download-file', { | ||
644 | content: dataURL, | ||
645 | fileOptions: { | ||
646 | name: `${fileName}.png`, | ||
647 | }, | ||
648 | }); | ||
649 | }); | ||
650 | this._sendNotificationOnClipboardEvent( | ||
651 | menuInfo.clipboardNotifications, | ||
652 | () => `Image downloaded: ${urlWithoutBlob}`, | ||
653 | ); | ||
654 | } | ||
655 | : () => { | ||
656 | const url = new window.URL(menuInfo.srcURL); | ||
643 | const fileName = url.pathname.slice(1); | 657 | const fileName = url.pathname.slice(1); |
644 | ipcRenderer.send('download-file', { | 658 | ipcRenderer.send('download-file', { |
645 | content: dataURL, | 659 | url: menuInfo.srcURL, |
646 | fileOptions: { | 660 | fileOptions: { |
647 | name: fileName, | 661 | name: fileName, |
648 | mime: 'image/png', | ||
649 | }, | 662 | }, |
650 | }); | 663 | }); |
651 | }); | 664 | this._sendNotificationOnClipboardEvent( |
652 | this._sendNotificationOnClipboardEvent( | 665 | menuInfo.clipboardNotifications, |
653 | menuInfo.clipboardNotifications, | 666 | () => `Image downloaded: ${menuInfo.srcURL}`, |
654 | () => `Image downloaded: ${urlWithoutBlob}`, | 667 | ); |
655 | ); | 668 | }; |
656 | }, | 669 | const downloadImage = new MenuItem({ |
670 | label: this.stringTable.downloadImage(), | ||
671 | click: clickHandler, | ||
657 | }); | 672 | }); |
658 | 673 | ||
659 | menu.append(downloadImage); | 674 | menu.append(downloadImage); |