Fix event leak on reuse of touchbar item (#12527)

* fix event leak on reuse of touchbar item

* Clean up child touch bar item event listeners and escape item listeners
This commit is contained in:
Samuel Attard 2018-04-16 01:24:47 +10:00 committed by Charles Kerr
parent cd8278dceb
commit 7cc3b877dc

View file

@ -118,6 +118,18 @@ class TouchBar extends EventEmitter {
window.removeListener('closed', removeListeners)
window._touchBar = null
delete this.windowListeners[id]
const unregisterItems = (items) => {
for (const item of items) {
item.removeListener('change', this.changeListener)
if (item.child instanceof TouchBar) {
unregisterItems(item.child.ordereredItems)
}
}
}
unregisterItems(this.ordereredItems)
if (this.escapeItem) {
this.escapeItem.removeListener('change', this.changeListener)
}
}
window.once('closed', removeListeners)
this.windowListeners[id] = removeListeners