diff --git a/app/browser/reducers/tabsReducer.js b/app/browser/reducers/tabsReducer.js index ad8ee8b823..bd37fa3fd7 100644 --- a/app/browser/reducers/tabsReducer.js +++ b/app/browser/reducers/tabsReducer.js @@ -261,6 +261,11 @@ const tabsReducer = (state, action, immutableAction) => { tabs.inspectElement(action.get('tabId'), action.get('x'), action.get('y')) }) break + case appConstants.APP_COPY_IMAGE: + setImmediate(() => { + tabs.copyImageAt(action.get('tabId'), action.get('x'), action.get('y')) + }) + break case appConstants.APP_LOAD_URL_REQUESTED: setImmediate(() => { tabs.loadURL(action) diff --git a/app/browser/tabs.js b/app/browser/tabs.js index c162c3f754..adbe6b25a8 100644 --- a/app/browser/tabs.js +++ b/app/browser/tabs.js @@ -737,6 +737,13 @@ const api = { } }, + copyImageAt: (tabId, x, y) => { + const tab = webContentsCache.getWebContents(tabId) + if (tab && !tab.isDestroyed()) { + tab.copyImageAt(x, y) + } + }, + setActive: (tabId) => { let tab = webContentsCache.getWebContents(tabId) if (tab && !tab.isDestroyed()) { diff --git a/app/nativeImage.js b/app/nativeImage.js deleted file mode 100644 index 6850ac83a5..0000000000 --- a/app/nativeImage.js +++ /dev/null @@ -1,15 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this file, - * You can obtain one at http://mozilla.org/MPL/2.0/. */ - -const electron = require('electron') -const nativeImage = electron.nativeImage -const clipboard = electron.clipboard - -module.exports.copyDataURL = (dataURL, html, text) => { - clipboard.write({ - image: nativeImage.createFromDataURL(dataURL), - html: html, - text: text - }) -} diff --git a/js/actions/appActions.js b/js/actions/appActions.js index 2935b0ae5d..72d910fba7 100644 --- a/js/actions/appActions.js +++ b/js/actions/appActions.js @@ -758,14 +758,14 @@ const appActions = { }, /** - * Dispatch a message to copy data URL to clipboard + * Dispatch a message to copy image **/ - dataURLCopied: function (dataURL, html, text) { + copyImage: function (tabId, x, y) { dispatch({ - actionType: appConstants.APP_DATA_URL_COPIED, - dataURL, - html, - text + actionType: appConstants.APP_COPY_IMAGE, + tabId, + x, + y }) }, diff --git a/js/constants/appConstants.js b/js/constants/appConstants.js index 1093a34f2d..41e2ed9178 100644 --- a/js/constants/appConstants.js +++ b/js/constants/appConstants.js @@ -74,7 +74,7 @@ const appConstants = { APP_DEFAULT_BROWSER_CHECK_COMPLETE: _, APP_POPULATE_HISTORY: _, APP_RENDER_TO_PDF: _, - APP_DATA_URL_COPIED: _, + APP_COPY_IMAGE: _, APP_DOWNLOAD_REVEALED: _, APP_DOWNLOAD_OPENED: _, APP_DOWNLOAD_ACTION_PERFORMED: _, diff --git a/js/contextMenus.js b/js/contextMenus.js index 5dde6fcfd9..84852bb437 100644 --- a/js/contextMenus.js +++ b/js/contextMenus.js @@ -26,7 +26,6 @@ const {getSetting} = require('./settings') const settings = require('./constants/settings') const textUtils = require('./lib/text') const {isIntermediateAboutPage, isUrl, aboutUrls} = require('./lib/appUrlUtil') -const {getBase64FromImageUrl} = require('./lib/imageUtil') const urlParse = require('../app/common/urlParse') const {getCurrentWindow} = require('../app/renderer/currentWindow') const extensionState = require('../app/common/state/extensionState') @@ -947,14 +946,7 @@ function mainTemplateInit (nodeProps, frame, tab) { { label: locale.translation('copyImage'), click: (item) => { - if (nodeProps.srcURL) { - if (urlParse(nodeProps.srcURL).protocol === 'data:') { - appActions.dataURLCopied(nodeProps.srcURL, ``, nodeProps.srcURL)) - } - } + appActions.copyImage(frame.get('tabId'), nodeProps.x, nodeProps.y) } }, copyAddressMenuItem('copyImageAddress', nodeProps.srcURL) diff --git a/js/stores/appStore.js b/js/stores/appStore.js index f9c3c3b140..1b009ab61b 100644 --- a/js/stores/appStore.js +++ b/js/stores/appStore.js @@ -23,7 +23,6 @@ const path = require('path') const diff = require('immutablediff') const debounce = require('../lib/debounce') const autofill = require('../../app/autofill') -const nativeImage = require('../../app/nativeImage') const filtering = require('../../app/filtering') const basicAuth = require('../../app/browser/basicAuth') const webtorrent = require('../../app/browser/webtorrent') @@ -251,9 +250,6 @@ const handleAppAction = (action) => { appDispatcher.shutdown() app.quit() break - case appConstants.APP_DATA_URL_COPIED: - nativeImage.copyDataURL(action.dataURL, action.html, action.text) - break case appConstants.APP_SET_DATA_FILE_ETAG: appState = appState.setIn([action.resourceName, 'etag'], action.etag) break