Skip to content
This repository was archived by the owner on Feb 5, 2021. It is now read-only.

Commit 34ed8a6

Browse files
committed
Add the basic touch bar support for macOS
1 parent 9670cbb commit 34ed8a6

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"author": "Howard Ju <howard.ju@outlook.com>",
2424
"license": "MIT",
2525
"devDependencies": {
26-
"electron": "~1.7.10",
26+
"electron": "~1.8.2",
2727
"electron-builder": "^19.8.0"
2828
},
2929
"dependencies": {

src/controller/player-controller.js

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
const {app, BrowserWindow, Notification, ipcMain} = require('electron');
1+
const {app, BrowserWindow, Notification, ipcMain, TouchBar, nativeImage} = require('electron');
2+
const {TouchBarLabel, TouchBarButton} = TouchBar
23
const urlLib = require('url');
34
const http = require('http');
45
const path = require('path');
@@ -74,6 +75,9 @@ class XiamiPlayer {
7475
// load xiami player page.
7576
this.window.loadURL(playerUrl);
7677

78+
// set the touch bar.
79+
this.window.setTouchBar(this.createTouchBar());
80+
7781
// inject the custom layout.
7882
this.window.webContents.on('dom-ready', () => {
7983

@@ -174,6 +178,26 @@ class XiamiPlayer {
174178
this.window.webContents.executeJavaScript("document.querySelector('.prev-btn').dispatchEvent(new MouseEvent('click'));");
175179
}
176180

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+
177201
/**
178202
* Add the listener to monitor the play time.
179203
*/

0 commit comments

Comments
 (0)