Bug 1444392 - Part 3 - Simplify the PanelUI.show method. r=Gijs
In addition to removing the unnecessary return value and the logic that may anchor the panel to anything other than the main menu button, this also fixes the asynchronous error handling. MozReview-Commit-ID: KaUKYUhrUoc
This commit is contained in:
@@ -194,36 +194,24 @@ const PanelUI = {
|
||||
*/
|
||||
show(aEvent) {
|
||||
this._ensureShortcutsShown();
|
||||
return new Promise(resolve => {
|
||||
this.ensureReady().then(() => {
|
||||
if (this.panel.state == "open" ||
|
||||
document.documentElement.hasAttribute("customizing")) {
|
||||
resolve();
|
||||
return;
|
||||
}
|
||||
(async () => {
|
||||
await this.ensureReady();
|
||||
|
||||
let anchor;
|
||||
let domEvent = null;
|
||||
if (!aEvent ||
|
||||
aEvent.type == "command") {
|
||||
anchor = this.menuButton;
|
||||
} else {
|
||||
domEvent = aEvent;
|
||||
anchor = aEvent.target;
|
||||
}
|
||||
if (this.panel.state == "open" ||
|
||||
document.documentElement.hasAttribute("customizing")) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.panel.addEventListener("popupshown", function() {
|
||||
resolve();
|
||||
}, {once: true});
|
||||
let domEvent = null;
|
||||
if (aEvent && aEvent.type != "command") {
|
||||
domEvent = aEvent;
|
||||
}
|
||||
|
||||
anchor = this._getPanelAnchor(anchor);
|
||||
PanelMultiView.openPopup(this.panel, anchor, {
|
||||
triggerEvent: domEvent,
|
||||
}).catch(Cu.reportError);
|
||||
}, (reason) => {
|
||||
console.error("Error showing the PanelUI menu", reason);
|
||||
let anchor = this._getPanelAnchor(this.menuButton);
|
||||
await PanelMultiView.openPopup(this.panel, anchor, {
|
||||
triggerEvent: domEvent,
|
||||
});
|
||||
});
|
||||
})().catch(Cu.reportError);
|
||||
},
|
||||
|
||||
/**
|
||||
|
||||
@@ -59,7 +59,7 @@ async function reopenAppMenu(browserWindow) {
|
||||
browserWindow.PanelUI.hide();
|
||||
let view = browserWindow.document.getElementById("appMenu-mainView");
|
||||
let promiseViewShown = BrowserTestUtils.waitForEvent(view, "ViewShown");
|
||||
await browserWindow.PanelUI.show();
|
||||
browserWindow.PanelUI.show();
|
||||
await promiseViewShown;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user