mirror of
https://github.com/electron/electron.git
synced 2026-01-11 00:18:02 -05:00
Add static helper to bind touch bar to window
This commit is contained in:
@@ -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)
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
@@ -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()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user