diff options
author | 2023-05-27 21:51:11 +0530 | |
---|---|---|
committer | 2023-05-27 21:51:11 +0530 | |
commit | 7e33530a8d7cb30fb9fef2c48cba97e5bb88d73c (patch) | |
tree | 8c83b75ba7bbc395279077eca395aeeb3022fd27 /src/webview/contextMenuBuilder.ts | |
parent | Expose "Clear service cache" in the service settings screen and the sidebar c... (diff) | |
download | ferdium-app-7e33530a8d7cb30fb9fef2c48cba97e5bb88d73c.tar.gz ferdium-app-7e33530a8d7cb30fb9fef2c48cba97e5bb88d73c.tar.zst ferdium-app-7e33530a8d7cb30fb9fef2c48cba97e5bb88d73c.zip |
Add new context menu item to download images (#935)
Diffstat (limited to 'src/webview/contextMenuBuilder.ts')
-rw-r--r-- | src/webview/contextMenuBuilder.ts | 45 |
1 files changed, 30 insertions, 15 deletions
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); |