Initial support for dynamic properties
This commit is contained in:
parent
cbb6f8c33e
commit
98f5858b11
10 changed files with 46 additions and 33 deletions
|
@ -138,6 +138,8 @@ BrowserWindow.prototype._init = function () {
|
|||
this._touchBar.emit('interaction', id, details)
|
||||
}
|
||||
})
|
||||
|
||||
this._touchBarListener = this._refreshTouchBarItem.bind(this)
|
||||
}
|
||||
|
||||
BrowserWindow.getFocusedWindow = () => {
|
||||
|
@ -208,8 +210,11 @@ Object.assign(BrowserWindow.prototype, {
|
|||
// TouchBar API
|
||||
BrowserWindow.prototype.setTouchBar = function (touchBar) {
|
||||
if (touchBar == null) {
|
||||
if (this._touchBar != null) {
|
||||
this._touchBar.removeListener('change', this._touchBarListener)
|
||||
this._touchBar = null
|
||||
}
|
||||
this._destroyTouchBar()
|
||||
this._touchBar = null
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -218,11 +223,8 @@ BrowserWindow.prototype.setTouchBar = function (touchBar) {
|
|||
}
|
||||
|
||||
this._touchBar = touchBar
|
||||
this._touchBar.on('change', this._touchBarListener)
|
||||
this._setTouchBar(touchBar.ordereredItems)
|
||||
}
|
||||
|
||||
BrowserWindow.prototype._updateTouchBarItem = function (itemID) {
|
||||
this._refreshTouchBarItem(itemID)
|
||||
}
|
||||
|
||||
module.exports = BrowserWindow
|
||||
|
|
|
@ -14,6 +14,9 @@ class TouchBar extends EventEmitter {
|
|||
this.ordereredItems = []
|
||||
const registerItem = (item) => {
|
||||
this.items[item.id] = item
|
||||
item.on('change', () => {
|
||||
this.emit('change', item.id, item.type)
|
||||
})
|
||||
if (item.child instanceof TouchBar) {
|
||||
item.child.ordereredItems.forEach(registerItem)
|
||||
}
|
||||
|
@ -35,8 +38,9 @@ class TouchBar extends EventEmitter {
|
|||
}
|
||||
}
|
||||
|
||||
class TouchBarItem {
|
||||
class TouchBarItem extends EventEmitter {
|
||||
constructor (config) {
|
||||
super()
|
||||
this.id = `${itemIdIncrementor++}`
|
||||
}
|
||||
}
|
||||
|
@ -81,7 +85,16 @@ TouchBar.Label = class TouchBarLabel extends TouchBarItem {
|
|||
constructor (config) {
|
||||
super(config)
|
||||
this.type = 'label'
|
||||
this.label = config.label
|
||||
this._label = config.label
|
||||
}
|
||||
|
||||
set label (newLabel) {
|
||||
this._label = newLabel
|
||||
this.emit('change')
|
||||
}
|
||||
|
||||
get label () {
|
||||
return this._label
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue