Add static helper to bind touch bar to window

This commit is contained in:
Kevin Sawicki 2017-03-01 11:12:22 -08:00
parent 51f1c5a557
commit f9dd91d54d
2 changed files with 21 additions and 17 deletions

View file

@ -1,6 +1,7 @@
'use strict'
const {ipcMain, TouchBar} = require('electron')
const electron = require('electron')
const {ipcMain} = electron
const {EventEmitter} = require('events')
const {BrowserWindow} = process.atomBinding('window')
const v8Util = process.atomBinding('v8_util')
@ -196,23 +197,8 @@ Object.assign(BrowserWindow.prototype, {
capturePage (...args) {
return this.webContents.capturePage(...args)
},
// TouchBar API
setTouchBar (touchBar) {
// This property is set from within TouchBar
if (this._touchBar != null) {
this._touchBar._removeFromWindow(this)
}
if (touchBar == null) {
this._setTouchBarItems([])
return
}
if (Array.isArray(touchBar)) {
touchBar = new TouchBar(touchBar)
}
touchBar._addToWindow(this)
electron.TouchBar._setOnWindow(touchBar, this)
}
})

View file

@ -3,6 +3,24 @@ const {EventEmitter} = require('events')
let itemIdIncrementor = 1
class TouchBar extends EventEmitter {
// Bind a touch bar to a window
static _setOnWindow (touchBar, window) {
if (window._touchBar != null) {
window._touchBar._removeFromWindow(window)
}
if (touchBar == null) {
window._setTouchBarItems([])
return
}
if (Array.isArray(touchBar)) {
touchBar = new TouchBar(touchBar)
}
touchBar._addToWindow(window)
}
constructor (items) {
super()