Add static helper to bind touch bar to window
This commit is contained in:
parent
51f1c5a557
commit
f9dd91d54d
2 changed files with 21 additions and 17 deletions
|
@ -1,6 +1,7 @@
|
||||||
'use strict'
|
'use strict'
|
||||||
|
|
||||||
const {ipcMain, TouchBar} = require('electron')
|
const electron = require('electron')
|
||||||
|
const {ipcMain} = electron
|
||||||
const {EventEmitter} = require('events')
|
const {EventEmitter} = require('events')
|
||||||
const {BrowserWindow} = process.atomBinding('window')
|
const {BrowserWindow} = process.atomBinding('window')
|
||||||
const v8Util = process.atomBinding('v8_util')
|
const v8Util = process.atomBinding('v8_util')
|
||||||
|
@ -196,23 +197,8 @@ Object.assign(BrowserWindow.prototype, {
|
||||||
capturePage (...args) {
|
capturePage (...args) {
|
||||||
return this.webContents.capturePage(...args)
|
return this.webContents.capturePage(...args)
|
||||||
},
|
},
|
||||||
|
|
||||||
// TouchBar API
|
|
||||||
setTouchBar (touchBar) {
|
setTouchBar (touchBar) {
|
||||||
// This property is set from within TouchBar
|
electron.TouchBar._setOnWindow(touchBar, this)
|
||||||
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)
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,24 @@ const {EventEmitter} = require('events')
|
||||||
let itemIdIncrementor = 1
|
let itemIdIncrementor = 1
|
||||||
|
|
||||||
class TouchBar extends EventEmitter {
|
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) {
|
constructor (items) {
|
||||||
super()
|
super()
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue