From f9dd91d54d29ca6c3866cd8a940dff01c2301163 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Wed, 1 Mar 2017 11:12:22 -0800 Subject: [PATCH] Add static helper to bind touch bar to window --- lib/browser/api/browser-window.js | 20 +++----------------- lib/browser/api/touch-bar.js | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+), 17 deletions(-) diff --git a/lib/browser/api/browser-window.js b/lib/browser/api/browser-window.js index 3c936d2af500..4b3f70139f0d 100644 --- a/lib/browser/api/browser-window.js +++ b/lib/browser/api/browser-window.js @@ -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) } }) diff --git a/lib/browser/api/touch-bar.js b/lib/browser/api/touch-bar.js index 6f6a31fd25ae..93cfb8988da2 100644 --- a/lib/browser/api/touch-bar.js +++ b/lib/browser/api/touch-bar.js @@ -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()