commit 882470344ade90bf2efd13e4105aa971fd86b470
parent a335f2b8e44ce62b3c5d4c0a8e391ffcde7d720b
Author: Duncan McIntosh <dmcintosh@mozilla.com>
Date: Fri, 12 Dec 2025 21:34:08 +0000
Bug 2000947 - Part 4: Avoid using event listeners for telemetry and pinning of Taskbar Tabs. r=nrishel
Differential Revision: https://phabricator.services.mozilla.com/D275327
Diffstat:
1 file changed, 19 insertions(+), 26 deletions(-)
diff --git a/browser/components/taskbartabs/TaskbarTabs.sys.mjs b/browser/components/taskbartabs/TaskbarTabs.sys.mjs
@@ -45,20 +45,13 @@ export const TaskbarTabs = new (class {
this.#ready = initRegistry().then(registry => {
this.#registry = registry;
this.#windowManager = initWindowManager(registry);
- initPinManager(registry);
- this.#setupTelemetry(registry);
+ this.#updateMetrics();
});
}
- #setupTelemetry(aRegistry) {
- function updateMetrics() {
- Glean.webApp.installedWebAppCount.set(aRegistry.countTaskbarTabs());
- }
-
- aRegistry.on(kTaskbarTabsRegistryEvents.created, updateMetrics);
- aRegistry.on(kTaskbarTabsRegistryEvents.removed, updateMetrics);
- updateMetrics();
+ #updateMetrics() {
+ Glean.webApp.installedWebAppCount.set(this.#registry.countTaskbarTabs());
}
async waitUntilReady() {
@@ -72,7 +65,16 @@ export const TaskbarTabs = new (class {
async findOrCreateTaskbarTab(...args) {
await this.#ready;
- return this.#registry.findOrCreateTaskbarTab(...args);
+ let result = this.#registry.findOrCreateTaskbarTab(...args);
+
+ if (result.created) {
+ this.#updateMetrics();
+
+ // Don't wait for the pinning to complete.
+ TaskbarTabsPin.pinTaskbarTab(result.taskbarTab, this.#registry);
+ }
+
+ return result;
}
async findTaskbarTab(...args) {
@@ -124,7 +126,12 @@ export const TaskbarTabs = new (class {
async removeTaskbarTab(...args) {
await this.#ready;
- return this.#registry.removeTaskbarTab(...args);
+
+ let taskbarTab = this.#registry.removeTaskbarTab(...args);
+ this.#updateMetrics();
+
+ // Don't wait for unpinning to finish.
+ TaskbarTabsPin.unpinTaskbarTab(taskbarTab, this.#registry);
}
async openWindow(...args) {
@@ -191,17 +198,3 @@ function initWindowManager() {
return wm;
}
-
-/**
- * Taskbar Tabs Pinning initialization.
- *
- * @param {TaskbarTabsRegistry} aRegistry - A registry to drive events to trigger pinning.
- */
-function initPinManager(aRegistry) {
- aRegistry.on(kTaskbarTabsRegistryEvents.created, (_, taskbarTab) => {
- return TaskbarTabsPin.pinTaskbarTab(taskbarTab, aRegistry);
- });
- aRegistry.on(kTaskbarTabsRegistryEvents.removed, (_, taskbarTab) => {
- return TaskbarTabsPin.unpinTaskbarTab(taskbarTab, aRegistry);
- });
-}