Bug 1881107 - Remove delay opening context menu due to awaiting fetched devices r=fxview-reviewers,jsudiaman,sfoster

I've moved the call to fetch devices to occur in connectedCallback rather than holding up the context menu toggle function.
https://profiler.firefox.com/from-browser/calltree/?globalTrackOrder=80w7&hiddenGlobalTracks=1w6&hiddenLocalTracksByPid=56852-134~56853-0~56859-0~56860-0~56858-0~56861-0~56857-0~56856-0&thread=c&v=10

Differential Revision: https://phabricator.services.mozilla.com/D205390
This commit is contained in:
Nikki Sharpley 2024-04-05 19:53:53 +00:00
Родитель 8512684c46
Коммит 91d3dc863c
1 изменённых файлов: 27 добавлений и 1 удалений

Просмотреть файл

@ -38,6 +38,9 @@ ChromeUtils.defineLazyGetter(lazy, "fxAccounts", () => {
).getFxAccountsSingleton();
});
const TOPIC_DEVICESTATE_CHANGED = "firefox-view.devicestate.changed";
const TOPIC_DEVICELIST_UPDATED = "fxaccounts:devicelist_updated";
/**
* A collection of open tabs grouped by window.
*
@ -671,6 +674,7 @@ class OpenTabsContextMenu extends MozLitElement {
constructor() {
super();
this.triggerNode = null;
this.boundObserve = (...args) => this.observe(...args);
this.devices = [];
}
@ -682,6 +686,28 @@ class OpenTabsContextMenu extends MozLitElement {
return this.ownerDocument.querySelector("view-opentabs");
}
connectedCallback() {
super.connectedCallback();
this.fetchDevicesPromise = this.fetchDevices();
Services.obs.addObserver(this.boundObserve, TOPIC_DEVICELIST_UPDATED);
Services.obs.addObserver(this.boundObserve, TOPIC_DEVICESTATE_CHANGED);
}
disconnectedCallback() {
super.disconnectedCallback();
Services.obs.removeObserver(this.boundObserve, TOPIC_DEVICELIST_UPDATED);
Services.obs.removeObserver(this.boundObserve, TOPIC_DEVICESTATE_CHANGED);
}
observe(_subject, topic, _data) {
if (
topic == TOPIC_DEVICELIST_UPDATED ||
topic == TOPIC_DEVICESTATE_CHANGED
) {
this.fetchDevicesPromise = this.fetchDevices();
}
}
async fetchDevices() {
const currentWindow = this.ownerViewPage.getWindow();
if (currentWindow?.gSync) {
@ -701,7 +727,7 @@ class OpenTabsContextMenu extends MozLitElement {
return;
}
this.triggerNode = triggerNode;
await this.fetchDevices();
await this.fetchDevicesPromise;
await this.getUpdateComplete();
this.panelList.toggle(originalEvent);
}