fix: touchbar icon display | 修复 touchbar 图标显示问号
fix: touchbar icon display | 修复 touchbar 图标显示问号
BIN
public/img/touchbar/backward.png
Normal file
After Width: | Height: | Size: 801 B |
BIN
public/img/touchbar/forward.png
Normal file
After Width: | Height: | Size: 779 B |
BIN
public/img/touchbar/like.png
Normal file
After Width: | Height: | Size: 1.1 KiB |
BIN
public/img/touchbar/like_fill.png
Normal file
After Width: | Height: | Size: 871 B |
BIN
public/img/touchbar/next_up.png
Normal file
After Width: | Height: | Size: 855 B |
BIN
public/img/touchbar/pause.png
Normal file
After Width: | Height: | Size: 499 B |
BIN
public/img/touchbar/play.png
Normal file
After Width: | Height: | Size: 746 B |
BIN
public/img/touchbar/route_next.png
Normal file
After Width: | Height: | Size: 656 B |
BIN
public/img/touchbar/route_prev.png
Normal file
After Width: | Height: | Size: 610 B |
BIN
public/img/touchbar/search.png
Normal file
After Width: | Height: | Size: 1.1 KiB |
|
@ -1,70 +1,81 @@
|
||||||
const { TouchBar, ipcMain } = require("electron");
|
const { TouchBar, nativeImage, ipcMain } = require("electron");
|
||||||
const { TouchBarButton, TouchBarSpacer } = TouchBar;
|
const { TouchBarButton, TouchBarSpacer } = TouchBar;
|
||||||
|
const path = require("path");
|
||||||
|
|
||||||
export function createTouchBar(window) {
|
export function createTouchBar(window) {
|
||||||
const renderer = window.webContents;
|
const renderer = window.webContents;
|
||||||
|
|
||||||
// use SF Symbols as label, you probably will see a instead of real icon
|
// Icon follow touchbar design guideline.
|
||||||
|
// See: https://developer.apple.com/design/human-interface-guidelines/macos/touch-bar/touch-bar-icons-and-images/
|
||||||
|
// Icon Resource: https://devimages-cdn.apple.com/design/resources/
|
||||||
|
function getNativeIcon(name) {
|
||||||
|
return nativeImage.createFromPath(
|
||||||
|
path.join(__static, "img/touchbar/", name)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
const previousPage = new TouchBarButton({
|
const previousPage = new TouchBarButton({
|
||||||
label: "",
|
|
||||||
click: () => {
|
click: () => {
|
||||||
renderer.send("routerGo", "back");
|
renderer.send("routerGo", "back");
|
||||||
},
|
},
|
||||||
|
icon: getNativeIcon("page_prev.png"),
|
||||||
});
|
});
|
||||||
|
|
||||||
const nextPage = new TouchBarButton({
|
const nextPage = new TouchBarButton({
|
||||||
label: "",
|
|
||||||
click: () => {
|
click: () => {
|
||||||
renderer.send("routerGo", "forward");
|
renderer.send("routerGo", "forward");
|
||||||
},
|
},
|
||||||
|
icon: getNativeIcon("page_next.png"),
|
||||||
});
|
});
|
||||||
|
|
||||||
const searchButton = new TouchBarButton({
|
const searchButton = new TouchBarButton({
|
||||||
label: "",
|
|
||||||
click: () => {
|
click: () => {
|
||||||
renderer.send("search");
|
renderer.send("search");
|
||||||
},
|
},
|
||||||
|
icon: getNativeIcon("search.png"),
|
||||||
});
|
});
|
||||||
|
|
||||||
const playButton = new TouchBarButton({
|
const playButton = new TouchBarButton({
|
||||||
label: "",
|
|
||||||
click: () => {
|
click: () => {
|
||||||
renderer.send("play");
|
renderer.send("play");
|
||||||
},
|
},
|
||||||
|
icon: getNativeIcon("play.png"),
|
||||||
});
|
});
|
||||||
|
|
||||||
const previousTrackButton = new TouchBarButton({
|
const previousTrackButton = new TouchBarButton({
|
||||||
label: "",
|
|
||||||
click: () => {
|
click: () => {
|
||||||
renderer.send("previous");
|
renderer.send("previous");
|
||||||
},
|
},
|
||||||
|
icon: getNativeIcon("backward.png"),
|
||||||
});
|
});
|
||||||
|
|
||||||
const nextTrackButton = new TouchBarButton({
|
const nextTrackButton = new TouchBarButton({
|
||||||
label: "",
|
|
||||||
click: () => {
|
click: () => {
|
||||||
renderer.send("next");
|
renderer.send("next");
|
||||||
},
|
},
|
||||||
|
icon: getNativeIcon("forward.png"),
|
||||||
});
|
});
|
||||||
|
|
||||||
const likeButton = new TouchBarButton({
|
const likeButton = new TouchBarButton({
|
||||||
label: "",
|
|
||||||
click: () => {
|
click: () => {
|
||||||
renderer.send("like");
|
renderer.send("like");
|
||||||
},
|
},
|
||||||
|
icon: getNativeIcon("like.png"),
|
||||||
});
|
});
|
||||||
|
|
||||||
const nextUpButton = new TouchBarButton({
|
const nextUpButton = new TouchBarButton({
|
||||||
label: "",
|
|
||||||
click: () => {
|
click: () => {
|
||||||
renderer.send("nextUp");
|
renderer.send("nextUp");
|
||||||
},
|
},
|
||||||
|
icon: getNativeIcon("next_up.png"),
|
||||||
});
|
});
|
||||||
|
|
||||||
ipcMain.on("player", (e, { playing, likedCurrentTrack }) => {
|
ipcMain.on("player", (e, { playing, likedCurrentTrack }) => {
|
||||||
playButton.label = playing === true ? "" : "";
|
playButton.icon =
|
||||||
likeButton.label = likedCurrentTrack ? "" : "";
|
playing === true ? getNativeIcon("pause.png") : getNativeIcon("play.png");
|
||||||
|
likeButton.icon = likedCurrentTrack
|
||||||
|
? getNativeIcon("like_fill.png")
|
||||||
|
: getNativeIcon("like.png");
|
||||||
});
|
});
|
||||||
|
|
||||||
const touchBar = new TouchBar({
|
const touchBar = new TouchBar({
|
||||||
|
|
|
@ -67,7 +67,6 @@ export function createTray(win) {
|
||||||
app.exit();
|
app.exit();
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
|
||||||
]);
|
]);
|
||||||
|
|
||||||
tray.popUpContextMenu(contextMenu);
|
tray.popUpContextMenu(contextMenu);
|
||||||
|
|