This repository has been archived by the owner on Dec 3, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathapi.js
41 lines (40 loc) · 1.68 KB
/
api.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/* global ChromeUtils ExtensionAPI */
this.customizableUI = class extends ExtensionAPI {
getAPI(context) {
const {CustomizableUI} = ChromeUtils.import('resource:///modules/CustomizableUI.jsm');
const {ExtensionCommon} = ChromeUtils.import('resource://gre/modules/ExtensionCommon.jsm');
const {EventManager} = ExtensionCommon;
const {Services} = ChromeUtils.import('resource://gre/modules/Services.jsm');
return {
customizableUI: {
onWidgetRemoved: new EventManager(
context,
'customizableUI.onWidgetRemoved',
(fire) => {
const toolbarButton = {
onWidgetRemoved(widgetId) {
fire.async(widgetId);
},
};
CustomizableUI.addListener(toolbarButton);
return () => {
CustomizableUI.removeListener(toolbarButton);
};
},
).api(),
async isWidgetInOverflow(widgetId) {
const {area} = CustomizableUI.getPlacementOfWidget(widgetId);
const browserWindow = Services.wm.getMostRecentWindow('navigator:browser');
// First check is for the non-fixed overflow menu (e.g. widget moved by resizing window)
// Second is for fixed overflow menu (e.g. widget moved by (un)pinning button to overflow)
return (
CustomizableUI.getWidget(widgetId).forWindow(browserWindow).overflowed
|| area === 'widget-overflow-fixed-list');
},
},
};
}
};