|
1 | | -const {app, BrowserWindow, Notification, ipcMain} = require('electron'); |
| 1 | +const {app, BrowserWindow, Notification, ipcMain, TouchBar, nativeImage} = require('electron'); |
| 2 | +const {TouchBarLabel, TouchBarButton} = TouchBar |
2 | 3 | const urlLib = require('url'); |
3 | 4 | const http = require('http'); |
4 | 5 | const path = require('path'); |
@@ -74,6 +75,9 @@ class XiamiPlayer { |
74 | 75 | // load xiami player page. |
75 | 76 | this.window.loadURL(playerUrl); |
76 | 77 |
|
| 78 | + // set the touch bar. |
| 79 | + this.window.setTouchBar(this.createTouchBar()); |
| 80 | + |
77 | 81 | // inject the custom layout. |
78 | 82 | this.window.webContents.on('dom-ready', () => { |
79 | 83 |
|
@@ -174,6 +178,26 @@ class XiamiPlayer { |
174 | 178 | this.window.webContents.executeJavaScript("document.querySelector('.prev-btn').dispatchEvent(new MouseEvent('click'));"); |
175 | 179 | } |
176 | 180 |
|
| 181 | + /** |
| 182 | + * Create the touch bar for macOS |
| 183 | + */ |
| 184 | + createTouchBar() { |
| 185 | + return new TouchBar([ |
| 186 | + new TouchBarButton({ |
| 187 | + icon: nativeImage.createFromNamedImage('NSTouchBarRewindTemplate', [-1, 0, 1]), |
| 188 | + click: () => this.previous() |
| 189 | + }), |
| 190 | + new TouchBarButton({ |
| 191 | + icon: nativeImage.createFromNamedImage('NSTouchBarPlayPauseTemplate', [-1, 0, 1]), |
| 192 | + click: () => this.toggle() |
| 193 | + }), |
| 194 | + new TouchBarButton({ |
| 195 | + icon: nativeImage.createFromNamedImage('NSTouchBarFastForwardTemplate', [-1, 0, 1]), |
| 196 | + click: () => this.next() |
| 197 | + }) |
| 198 | + ]); |
| 199 | + } |
| 200 | + |
177 | 201 | /** |
178 | 202 | * Add the listener to monitor the play time. |
179 | 203 | */ |
|
0 commit comments