Bug 1561886 - Color the profiler icon in blue if the profiler is running at startup r=gregtatum
authorJulien Wajsberg <felash@gmail.com>
Fri, 28 Jun 2019 14:12:00 +0000
changeset 543382 36f64a7df80cde6e66e84ac09c66df0c2ea1cf14
parent 543381 7006b881f891b82230c3f5334ff541aa38c8911d
child 543383 0d7b68ec3e0aceeb63acd84bf99ab43b5c7d7a72
push id2131
push userffxbld-merge
push dateMon, 26 Aug 2019 18:30:20 +0000
treeherdermozilla-release@b19ffb3ca153 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgregtatum
bugs1561886
milestone69.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1561886 - Color the profiler icon in blue if the profiler is running at startup r=gregtatum Differential Revision: https://phabricator.services.mozilla.com/D36198
devtools/client/performance-new/popup/menu-button.jsm
--- a/devtools/client/performance-new/popup/menu-button.jsm
+++ b/devtools/client/performance-new/popup/menu-button.jsm
@@ -67,16 +67,25 @@ function getIframeFromEvent(event) {
    // Create the iframe, and append it.
   const iframe = document.getElementById("PanelUI-profilerIframe");
   if (!iframe) {
     throw new Error("Unable to select the PanelUI-profilerIframe.");
   }
   return iframe;
 }
 
+// This function takes the button element, and returns a function that's used to
+// update the profiler button whenever the profiler activation status changed.
+const updateButtonColorForElement = buttonElement => () => {
+  const isRunning = Services.profiler.IsActive();
+
+  // Use photon blue-60 when active.
+  buttonElement.style.fill = isRunning ? "#0060df" : "";
+};
+
 /**
  * This function creates the widget definition for the CustomizableUI. It should
  * only be run if the profiler button is enabled.
  */
 function initialize() {
   const widget = CustomizableUI.getWidget(WIDGET_ID);
   if (widget && widget.provider == CustomizableUI.PROVIDER_API) {
      // This widget has already been created.
@@ -107,43 +116,30 @@ function initialize() {
     onViewHiding(event) {
       const iframe = getIframeFromEvent(event);
       // Unset the iframe src so that when the popup DOM element is moved, the popup's
       // contents aren't re-initialized.
       iframe.src = "";
     },
     onBeforeCreated: (document) => {
       setMenuItemChecked(document, true);
-      observer = {
-        observe(subject, topic, data) {
-          switch (topic) {
-            case "profiler-started": {
-              const button = document.querySelector("#profiler-button");
-              if (button) {
-                // Photon blue-60.
-                button.style.fill = "#0060df";
-              }
-              break;
-            }
-            case "profiler-stopped": {
-              const button = document.querySelector("#profiler-button");
-              if (button) {
-                button.style.fill = "";
-              }
-              break;
-            }
-          }
-        },
-      };
+    },
+    onCreated: (buttonElement) => {
+      observer = updateButtonColorForElement(buttonElement);
       Services.obs.addObserver(observer, "profiler-started");
       Services.obs.addObserver(observer, "profiler-stopped");
+
+      // Also run the observer right away to update the color if the profiler is
+      // already running at startup.
+      observer();
     },
     onDestroyed: () => {
       Services.obs.removeObserver(observer, "profiler-started");
       Services.obs.removeObserver(observer, "profiler-stopped");
+      observer = null;
     },
   };
   CustomizableUI.createWidget(item);
   CustomizableWidgets.push(item);
 }
 
 const ProfilerMenuButton = { toggle, initialize };