1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
9 } = require("resource://devtools/client/shared/vendor/redux.js");
12 } = require("resource://devtools/client/shared/vendor/react.js");
15 unmountComponentAtNode,
16 } = require("resource://devtools/client/shared/vendor/react-dom.js");
17 const Provider = createFactory(
18 require("resource://devtools/client/shared/vendor/react-redux.js").Provider
21 const FluentReact = require("resource://devtools/client/shared/vendor/fluent-react.js");
22 const LocalizationProvider = createFactory(FluentReact.LocalizationProvider);
24 const actions = require("resource://devtools/client/aboutdebugging/src/actions/index.js");
27 } = require("resource://devtools/client/aboutdebugging/src/create-store.js");
29 setDebugTargetCollapsibilities,
30 } = require("resource://devtools/client/aboutdebugging/src/modules/debug-target-collapsibilities.js");
34 } = require("resource://devtools/client/aboutdebugging/src/modules/l10n.js");
37 addNetworkLocationsObserver,
39 removeNetworkLocationsObserver,
40 } = require("resource://devtools/client/aboutdebugging/src/modules/network-locations.js");
42 addUSBRuntimesObserver,
44 removeUSBRuntimesObserver,
45 } = require("resource://devtools/client/aboutdebugging/src/modules/usb-runtimes.js");
47 loader.lazyRequireGetter(
50 "resource://devtools/client/shared/remote-debugging/adb/adb.js",
53 loader.lazyRequireGetter(
56 "resource://devtools/client/shared/remote-debugging/adb/adb-addon.js",
59 loader.lazyRequireGetter(
62 "resource://devtools/client/shared/remote-debugging/adb/adb-process.js",
66 const Router = createFactory(
67 require("resource://devtools/client/shared/vendor/react-router-dom.js")
70 const App = createFactory(
71 require("resource://devtools/client/aboutdebugging/src/components/App.js")
74 const AboutDebugging = {
76 const direction = Services.locale.isAppLocaleRTL ? "rtl" : "ltr";
77 document.documentElement.setAttribute("dir", direction);
79 this.onAdbAddonUpdated = this.onAdbAddonUpdated.bind(this);
80 this.onAdbProcessReady = this.onAdbProcessReady.bind(this);
81 this.onNetworkLocationsUpdated = this.onNetworkLocationsUpdated.bind(this);
82 this.onUSBRuntimesUpdated = this.onUSBRuntimesUpdated.bind(this);
84 this.store = configureStore();
85 this.actions = bindActionCreators(actions, this.store.dispatch);
87 const width = this.getRoundedViewportWidth();
88 this.actions.recordTelemetryEvent("open_adbg", { width });
92 "devtools/client/aboutdebugging.ftl",
95 this.actions.createThisFirefoxRuntime();
97 // Listen to Network locations updates and retrieve the initial list of locations.
98 addNetworkLocationsObserver(this.onNetworkLocationsUpdated);
99 await this.onNetworkLocationsUpdated();
101 // Listen to USB runtime updates and retrieve the initial list of runtimes.
103 // If ADB is already started, wait for the initial runtime list to be able to restore
104 // already connected runtimes.
105 const isProcessStarted = await adb.isProcessStarted();
106 const onAdbRuntimesReady = isProcessStarted
107 ? adb.once("runtime-list-ready")
109 addUSBRuntimesObserver(this.onUSBRuntimesUpdated);
110 await onAdbRuntimesReady;
112 await this.onUSBRuntimesUpdated();
119 LocalizationProvider(
120 { bundles: l10n.getBundles() },
127 adbAddon.on("update", this.onAdbAddonUpdated);
128 this.onAdbAddonUpdated();
129 adbProcess.on("adb-ready", this.onAdbProcessReady);
130 // get the initial status of adb process, in case it's already started
131 this.onAdbProcessReady();
134 onAdbAddonUpdated() {
135 this.actions.updateAdbAddonStatus(adbAddon.status);
138 onAdbProcessReady() {
139 this.actions.updateAdbReady(adbProcess.ready);
142 onNetworkLocationsUpdated() {
143 return this.actions.updateNetworkLocations(getNetworkLocations());
146 async onUSBRuntimesUpdated() {
147 const runtimes = await getUSBRuntimes();
148 return this.actions.updateUSBRuntimes(runtimes);
152 const width = this.getRoundedViewportWidth();
153 this.actions.recordTelemetryEvent("close_adbg", { width });
155 const state = this.store.getState();
156 const currentRuntimeId = state.runtimes.selectedRuntimeId;
157 if (currentRuntimeId) {
158 await this.actions.unwatchRuntime(currentRuntimeId);
161 // Remove all client listeners.
162 this.actions.removeRuntimeListeners();
164 removeNetworkLocationsObserver(this.onNetworkLocationsUpdated);
165 removeUSBRuntimesObserver(this.onUSBRuntimesUpdated);
166 adbAddon.off("update", this.onAdbAddonUpdated);
167 adbProcess.off("adb-ready", this.onAdbProcessReady);
168 setDebugTargetCollapsibilities(state.ui.debugTargetCollapsibilities);
169 unmountComponentAtNode(this.mount);
173 return document.getElementById("mount");
177 * Computed viewport width, rounded at 50px. Used for telemetry events.
179 getRoundedViewportWidth() {
180 return Math.ceil(window.outerWidth / 50) * 50;
184 window.addEventListener(
187 AboutDebugging.init();
192 window.addEventListener(
195 AboutDebugging.destroy();
200 // Expose AboutDebugging to tests so that they can access to the store.
201 window.AboutDebugging = AboutDebugging;