From 977f0cd3b9862949ed2424534bdefa7d9811dfc2 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 a2d897312e3..d8f66106c45 100644 --- a/app/browser/tabs.js +++ b/app/browser/tabs.js @@ -533,6 +533,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 439ce6fd35e..548e0ff49eb 100644 --- a/js/actions/appActions.js +++ b/js/actions/appActions.js @@ -894,6 +894,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 6f8b28d937a..833aee07639 100644 --- a/js/constants/appConstants.js +++ b/js/constants/appConstants.js @@ -141,7 +141,8 @@ const appConstants = { APP_DEBUG_NO_REPORT_STATE_MODE_CLICKED: _, APP_SPELLING_SUGGESTED: _, APP_LEARN_SPELLING: _, - APP_FORGET_LEARNED_SPELLING: _ + APP_FORGET_LEARNED_SPELLING: _, + APP_INSPECT_ELEMENT: _ } module.exports = mapValuesByKeys(appConstants) diff --git a/js/contextMenus.js b/js/contextMenus.js index bde8827f1fe..3e6f9d2c922 100644 --- a/js/contextMenus.js +++ b/js/contextMenus.js @@ -1108,8 +1108,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) } }) }