diff --git a/lib/browser/api/touch-bar.js b/lib/browser/api/touch-bar.js index f9629a66ce2b..327b6392fe8a 100644 --- a/lib/browser/api/touch-bar.js +++ b/lib/browser/api/touch-bar.js @@ -101,7 +101,7 @@ class TouchBar extends EventEmitter { const interactionListener = (event, itemID, details) => { let item = this.items[itemID] - if (item == null && this.escapeItem.id === itemID) { + if (item == null && this.escapeItem != null && this.escapeItem.id === itemID) { item = this.escapeItem } if (item != null && item.onInteraction != null) { diff --git a/spec/api-touch-bar-spec.js b/spec/api-touch-bar-spec.js index c2d5d26c3e46..70803045911a 100644 --- a/spec/api-touch-bar-spec.js +++ b/spec/api-touch-bar-spec.js @@ -78,5 +78,17 @@ describe('TouchBar module', function () { window.setTouchBar(new TouchBar([new TouchBarLabel({label: 'two'})])) touchBar.escapeItem = null }) + + it('calls the callback on the items when a window interaction event fires', function (done) { + const button = new TouchBarButton({ + label: 'bar', + click: () => { + done() + } + }) + const touchBar = new TouchBar({items: [button]}) + window.setTouchBar(touchBar) + window.emit('-touch-bar-interaction', {}, button.id) + }) }) })