From bbc1c0f0595728d791b3f2caf12af90c659c849f Mon Sep 17 00:00:00 2001 From: Daisuke Akatsuka Date: Fri, 5 Oct 2018 04:03:04 +0000 Subject: [PATCH] Bug 1494170: Show proper runtime's name and version. r=jdescottes Depends on D6881 Differential Revision: https://phabricator.services.mozilla.com/D7036 --HG-- extra : moz-landing-system : lando --- .../aboutdebugging-new/src/actions/runtimes.js | 13 +++++++++++++ .../src/components/RuntimePage.js | 17 +++++++++++------ .../src/modules/runtimes-state-helper.js | 6 ++++++ .../src/reducers/runtimes-state.js | 6 +++--- 4 files changed, 33 insertions(+), 9 deletions(-) diff --git a/devtools/client/aboutdebugging-new/src/actions/runtimes.js b/devtools/client/aboutdebugging-new/src/actions/runtimes.js index 55bb72706161..d112e64b67c6 100644 --- a/devtools/client/aboutdebugging-new/src/actions/runtimes.js +++ b/devtools/client/aboutdebugging-new/src/actions/runtimes.js @@ -66,18 +66,31 @@ async function createClientForRuntime(runtime) { return null; } +async function getRuntimeInfo(client) { + const deviceFront = await client.mainRoot.getFront("device"); + const { brandName: name, version } = await deviceFront.getDescription(); + + return { + icon: "chrome://branding/content/icon64.png", + name, + version, + }; +} + function connectRuntime(id) { return async (dispatch, getState) => { dispatch({ type: CONNECT_RUNTIME_START }); try { const runtime = findRuntimeById(id, getState().runtimes); const client = await createClientForRuntime(runtime); + const info = await getRuntimeInfo(client); dispatch({ type: CONNECT_RUNTIME_SUCCESS, runtime: { id, client, + info, type: runtime.type, } }); diff --git a/devtools/client/aboutdebugging-new/src/components/RuntimePage.js b/devtools/client/aboutdebugging-new/src/components/RuntimePage.js index 065d62a3dfc3..44c9d94767fc 100644 --- a/devtools/client/aboutdebugging-new/src/components/RuntimePage.js +++ b/devtools/client/aboutdebugging-new/src/components/RuntimePage.js @@ -23,8 +23,8 @@ const TemporaryExtensionInstaller = createFactory(require("./debugtarget/TemporaryExtensionInstaller")); const WorkerDetail = createFactory(require("./debugtarget/WorkerDetail")); -const Services = require("Services"); const { DEBUG_TARGET_PANE } = require("../constants"); +const { getCurrentRuntimeInfo } = require("../modules/runtimes-state-helper"); class RuntimePage extends PureComponent { static get propTypes() { @@ -33,6 +33,7 @@ class RuntimePage extends PureComponent { dispatch: PropTypes.func.isRequired, installedExtensions: PropTypes.arrayOf(PropTypes.object).isRequired, otherWorkers: PropTypes.arrayOf(PropTypes.object).isRequired, + runtimeInfo: PropTypes.object, serviceWorkers: PropTypes.arrayOf(PropTypes.object).isRequired, sharedWorkers: PropTypes.arrayOf(PropTypes.object).isRequired, tabs: PropTypes.arrayOf(PropTypes.object).isRequired, @@ -46,21 +47,24 @@ class RuntimePage extends PureComponent { dispatch, installedExtensions, otherWorkers, + runtimeInfo, serviceWorkers, sharedWorkers, tabs, temporaryExtensions, } = this.props; + if (!runtimeInfo) { + // runtimeInfo can be null when the selectPage action navigates from a runtime A + // to a runtime B (between unwatchRuntime and watchRuntime). + return null; + } + return dom.article( { className: "page js-runtime-page", }, - RuntimeInfo({ - icon: "chrome://branding/content/icon64.png", - name: Services.appinfo.name, - version: Services.appinfo.version, - }), + RuntimeInfo(runtimeInfo), TemporaryExtensionInstaller({ dispatch }), Localized( { @@ -161,6 +165,7 @@ const mapStateToProps = state => { collapsibilities: state.ui.debugTargetCollapsibilities, installedExtensions: state.debugTargets.installedExtensions, otherWorkers: state.debugTargets.otherWorkers, + runtimeInfo: getCurrentRuntimeInfo(state.runtimes), serviceWorkers: state.debugTargets.serviceWorkers, sharedWorkers: state.debugTargets.sharedWorkers, tabs: state.debugTargets.tabs, diff --git a/devtools/client/aboutdebugging-new/src/modules/runtimes-state-helper.js b/devtools/client/aboutdebugging-new/src/modules/runtimes-state-helper.js index 53a1ffeff7c5..7cf105a6faac 100644 --- a/devtools/client/aboutdebugging-new/src/modules/runtimes-state-helper.js +++ b/devtools/client/aboutdebugging-new/src/modules/runtimes-state-helper.js @@ -15,6 +15,12 @@ function getCurrentClient(runtimesState) { } exports.getCurrentClient = getCurrentClient; +function getCurrentRuntimeInfo(runtimesState) { + const runtime = getCurrentRuntime(runtimesState); + return runtime ? runtime.info : null; +} +exports.getCurrentRuntimeInfo = getCurrentRuntimeInfo; + function findRuntimeById(id, runtimesState) { const allRuntimes = [ ...runtimesState.networkRuntimes, diff --git a/devtools/client/aboutdebugging-new/src/reducers/runtimes-state.js b/devtools/client/aboutdebugging-new/src/reducers/runtimes-state.js index 66363f4ea186..ece42fa45969 100644 --- a/devtools/client/aboutdebugging-new/src/reducers/runtimes-state.js +++ b/devtools/client/aboutdebugging-new/src/reducers/runtimes-state.js @@ -68,13 +68,13 @@ function _updateRuntimeById(runtimeId, updatedRuntime, state) { function runtimesReducer(state = RuntimesState(), action) { switch (action.type) { case CONNECT_RUNTIME_SUCCESS: { - const { id, client } = action.runtime; - return _updateRuntimeById(id, { client }, state); + const { id, client, info } = action.runtime; + return _updateRuntimeById(id, { client, info }, state); } case DISCONNECT_RUNTIME_SUCCESS: { const { id } = action.runtime; - return _updateRuntimeById(id, { client: null }, state); + return _updateRuntimeById(id, { client: null, info: null }, state); } case NETWORK_LOCATIONS_UPDATED: {