TouchBar
Process:
options
Objectitems
( | TouchBarColorPicker | | TouchBarLabel | | TouchBarScrubber | | TouchBarSlider | )[] (optional)- (TouchBarButton | | TouchBarGroup | | TouchBarPopover | | TouchBarSegmentedControl | | TouchBarSpacer | null) (optional)
Creates a new touch bar with the specified items. Use BrowserWindow.setTouchBar
to add the TouchBar
to a window.
Note: The TouchBar API is currently experimental and may change or be removed in future Electron releases.
Tip: If you don’t have a MacBook with Touch Bar, you can use to test Touch Bar usage in your app.
TouchBarButton
A typeof TouchBarButton reference to the TouchBarButton
class.
TouchBarColorPicker
TouchBarGroup
A reference to the TouchBarGroup
class.
TouchBarLabel
A reference to the TouchBarLabel
class.
TouchBarPopover
A reference to the TouchBarPopover
class.
TouchBarScrubber
A reference to the TouchBarScrubber
class.
A reference to the TouchBarSegmentedControl
class.
TouchBarSlider
TouchBarSpacer
A typeof TouchBarSpacer reference to the TouchBarSpacer
class.
TouchBarOtherItemsProxy
A typeof TouchBarOtherItemsProxy reference to the TouchBarOtherItemsProxy
class.
The following properties are available on instances of TouchBar
:
touchBar.escapeItem
A TouchBarItem
that will replace the “esc” button on the touch bar when set. Setting to null
restores the default “esc” button. Changing this value immediately updates the escape item in the touch bar.
Examples
Below is an example of a simple slot machine touch bar game with a button and some labels.
- Save the above file to your computer as
touchbar.js
- Install Electron via
npm install electron
- Run the example inside Electron:
./node_modules/.bin/electron touchbar.js
You should then see a new Electron window and the app running in your touch bar (or touch bar emulator).