diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/webview/contextMenuBuilder.js | 31 |
1 files changed, 30 insertions, 1 deletions
diff --git a/src/webview/contextMenuBuilder.js b/src/webview/contextMenuBuilder.js index a1a733a75..eac383fbd 100644 --- a/src/webview/contextMenuBuilder.js +++ b/src/webview/contextMenuBuilder.js | |||
@@ -11,7 +11,7 @@ import { isMac } from '../environment'; | |||
11 | import { SEARCH_ENGINE_NAMES, SEARCH_ENGINE_URLS } from '../config'; | 11 | import { SEARCH_ENGINE_NAMES, SEARCH_ENGINE_URLS } from '../config'; |
12 | 12 | ||
13 | const { | 13 | const { |
14 | clipboard, nativeImage, remote, shell, | 14 | clipboard, ipcRenderer, nativeImage, remote, shell, |
15 | } = require('electron'); | 15 | } = require('electron'); |
16 | 16 | ||
17 | const { URL } = require('url'); | 17 | const { URL } = require('url'); |
@@ -36,6 +36,7 @@ const contextMenuStringTable = { | |||
36 | copyLinkUrl: () => 'Copy Link', | 36 | copyLinkUrl: () => 'Copy Link', |
37 | copyImageUrl: () => 'Copy Image Address', | 37 | copyImageUrl: () => 'Copy Image Address', |
38 | copyImage: () => 'Copy Image', | 38 | copyImage: () => 'Copy Image', |
39 | downloadImage: () => 'Download Image', | ||
39 | addToDictionary: () => 'Add to Dictionary', | 40 | addToDictionary: () => 'Add to Dictionary', |
40 | goBack: () => 'Go Back', | 41 | goBack: () => 'Go Back', |
41 | goForward: () => 'Go Forward', | 42 | goForward: () => 'Go Forward', |
@@ -192,6 +193,7 @@ module.exports = class ContextMenuBuilder { | |||
192 | this.addInspectElement(menu, menuInfo); | 193 | this.addInspectElement(menu, menuInfo); |
193 | this.processMenu(menu, menuInfo); | 194 | this.processMenu(menu, menuInfo); |
194 | 195 | ||
196 | this.addSeparator(menu); | ||
195 | this.goBack(menu); | 197 | this.goBack(menu); |
196 | this.goForward(menu); | 198 | this.goForward(menu); |
197 | this.copyPageUrl(menu); | 199 | this.copyPageUrl(menu); |
@@ -214,6 +216,7 @@ module.exports = class ContextMenuBuilder { | |||
214 | this.addInspectElement(menu, menuInfo); | 216 | this.addInspectElement(menu, menuInfo); |
215 | this.processMenu(menu, menuInfo); | 217 | this.processMenu(menu, menuInfo); |
216 | 218 | ||
219 | this.addSeparator(menu); | ||
217 | this.goBack(menu); | 220 | this.goBack(menu); |
218 | this.goForward(menu); | 221 | this.goForward(menu); |
219 | this.copyPageUrl(menu); | 222 | this.copyPageUrl(menu); |
@@ -337,6 +340,32 @@ module.exports = class ContextMenuBuilder { | |||
337 | }); | 340 | }); |
338 | 341 | ||
339 | menu.append(copyImageUrl); | 342 | menu.append(copyImageUrl); |
343 | |||
344 | // TODO: This doesn't seem to work on linux, so, limiting to Mac for now | ||
345 | if (isMac && menuInfo.srcURL.startsWith('blob:')) { | ||
346 | const downloadImage = new MenuItem({ | ||
347 | label: this.stringTable.downloadImage(), | ||
348 | click: () => { | ||
349 | const urlWithoutBlob = menuInfo.srcURL.substr(5); | ||
350 | this.convertImageToBase64(menuInfo.srcURL, | ||
351 | (dataURL) => { | ||
352 | const url = new window.URL(urlWithoutBlob); | ||
353 | const fileName = url.pathname.substr(1); | ||
354 | ipcRenderer.send('download-file', { | ||
355 | content: dataURL, | ||
356 | fileOptions: { | ||
357 | name: fileName, | ||
358 | mime: 'image/png', | ||
359 | }, | ||
360 | }); | ||
361 | }); | ||
362 | this.sendNotificationOnClipboardEvent(`Image downloaded: ${urlWithoutBlob}`); | ||
363 | }, | ||
364 | }); | ||
365 | |||
366 | menu.append(downloadImage); | ||
367 | } | ||
368 | |||
340 | return menu; | 369 | return menu; |
341 | } | 370 | } |
342 | 371 | ||