feat: Add OtherItemsProxy TouchBar item (#22270)

* feat: Add OtherItemsProxy touchbar item

* review!
This commit is contained in:
Erick Zhao 2020-02-24 00:55:06 -08:00 committed by GitHub
parent 8cc0435d9c
commit 1848e3f658
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 83 additions and 29 deletions

View file

@ -51,13 +51,27 @@ class TouchBar extends EventEmitter {
item.child.ordereredItems.forEach(registerItem)
}
}
let hasOtherItemsProxy = false
items.forEach((item) => {
if (!(item instanceof TouchBarItem)) {
throw new Error('Each item must be an instance of TouchBarItem')
}
if (item.type === 'other_items_proxy') {
if (!hasOtherItemsProxy) {
hasOtherItemsProxy = true
} else {
throw new Error('Must only have one OtherItemsProxy per TouchBar')
}
}
})
// register in separate loop after all items are validated
for (const item of items) {
this.ordereredItems.push(item)
registerItem(item)
})
}
}
set escapeItem (item) {
@ -334,4 +348,11 @@ TouchBar.TouchBarScrubber = class TouchBarScrubber extends TouchBarItem {
}
}
TouchBar.TouchBarOtherItemsProxy = class TouchBarOtherItemsProxy extends TouchBarItem {
constructor (config) {
super()
this._addImmutableProperty('type', 'other_items_proxy')
}
}
module.exports = TouchBar