From 9b20fd1316f1a3a688d4beb8e1cedcadc340b330 Mon Sep 17 00:00:00 2001 From: NejcZdovc Date: Fri, 25 Aug 2017 13:57:40 +0200 Subject: [PATCH] Fixes dev tools inspect element functionality Resolves #10249 Auditors: Test Plan: --- app/browser/reducers/tabsReducer.js | 5 +++++ app/browser/tabs.js | 7 +++++++ js/actions/appActions.js | 15 +++++++++++++++ js/actions/webviewActions.js | 12 ------------ js/constants/appConstants.js | 3 ++- js/contextMenus.js | 4 ++-- 6 files changed, 31 insertions(+), 15 deletions(-) diff --git a/app/browser/reducers/tabsReducer.js b/app/browser/reducers/tabsReducer.js index 264b74001ec..c57d8571385 100644 --- a/app/browser/reducers/tabsReducer.js +++ b/app/browser/reducers/tabsReducer.js @@ -256,6 +256,11 @@ const tabsReducer = (state, action, immutableAction) => { tabs.toggleDevTools(action.get('tabId')) }) break + case appConstants.APP_INSPECT_ELEMENT: + setImmediate(() => { + tabs.inspectElement(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 bebe53607e4..905b1dd1935 100644 --- a/app/browser/tabs.js +++ b/app/browser/tabs.js @@ -525,6 +525,13 @@ const api = { } }, + inspectElement: (tabId, x, y) => { + const tab = getWebContents(tabId) + if (tab && !tab.isDestroyed()) { + tab.inspectElement(x, y) + } + }, + setActive: (tabId) => { let tab = getWebContents(tabId) if (tab && !tab.isDestroyed()) { diff --git a/js/actions/appActions.js b/js/actions/appActions.js index a8e0efe4777..992f4ff2626 100644 --- a/js/actions/appActions.js +++ b/js/actions/appActions.js @@ -867,6 +867,21 @@ const appActions = { }) }, + /** + * Dispatches a message to inspect desired element on the page + * @param {number} tabId - The tabId + * @param {number} x - horizontal position of the element + * @param {number} y - vertical position of the element + */ + inspectElement: function (tabId, x, y) { + dispatch({ + actionType: appConstants.APP_INSPECT_ELEMENT, + tabId, + x, + y + }) + }, + /** * Dispatches a message when a tab is being cloned * @param {number} tabId - The tabId of the tab to clone diff --git a/js/actions/webviewActions.js b/js/actions/webviewActions.js index 5b98fa70573..8d349ab932e 100644 --- a/js/actions/webviewActions.js +++ b/js/actions/webviewActions.js @@ -20,18 +20,6 @@ const webviewActions = { } }, - /** - * Inspect the element for the active webview at the x, y content position - * @param {number} x - horizontal position of the element to inspect - * @param {number} y - vertical position of the element to inspect - */ - inspectElement: function (x, y) { - const webview = getWebview() - if (webview) { - webview.inspectElement(x, y) - } - }, - /** * Shows the certificate infomation */ diff --git a/js/constants/appConstants.js b/js/constants/appConstants.js index 71e69d772a0..0bd091fc15d 100644 --- a/js/constants/appConstants.js +++ b/js/constants/appConstants.js @@ -150,7 +150,8 @@ const appConstants = { APP_REMOVE_BOOKMARK_FOLDER: _, APP_REMOVE_BOOKMARK: _, APP_MOVE_BOOKMARK_FOLDER: _, - APP_MOVE_BOOKMARK: _ + APP_MOVE_BOOKMARK: _, + APP_INSPECT_ELEMENT: _ } module.exports = mapValuesByKeys(appConstants) diff --git a/js/contextMenus.js b/js/contextMenus.js index 107767a10d3..91d6d593a8d 100644 --- a/js/contextMenus.js +++ b/js/contextMenus.js @@ -1154,8 +1154,8 @@ function mainTemplateInit (nodeProps, frame, tab) { if (!isAboutPage) { template.push({ label: locale.translation('inspectElement'), - click: (item) => { - webviewActions.inspectElement(nodeProps.x, nodeProps.y) + click: () => { + appActions.inspectElement(frame.get('tabId'), nodeProps.x, nodeProps.y) } }) }