|
|
|
@ -9,16 +9,24 @@ export function createTray(win) {
|
|
|
|
|
height: 20,
|
|
|
|
|
width: 20,
|
|
|
|
|
});
|
|
|
|
|
let tray = new Tray(icon);
|
|
|
|
|
|
|
|
|
|
tray.setToolTip('YesPlayMusic');
|
|
|
|
|
|
|
|
|
|
tray.on('click', () => {
|
|
|
|
|
let contextMenu = Menu.buildFromTemplate([
|
|
|
|
|
//setContextMenu破坏了预期的click行为
|
|
|
|
|
//在linux下,鼠标左右键都会呼出contextMenu
|
|
|
|
|
//所以此处单独为linux添加一个 显示主面板 选项
|
|
|
|
|
...(process.platform === 'linux'
|
|
|
|
|
? [
|
|
|
|
|
{
|
|
|
|
|
label: '显示主面板',
|
|
|
|
|
click: () => {
|
|
|
|
|
win.show();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
tray.on('right-click', () => {
|
|
|
|
|
const contextMenu = Menu.buildFromTemplate([
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
type: 'separator',
|
|
|
|
|
},
|
|
|
|
|
]
|
|
|
|
|
: []),
|
|
|
|
|
{
|
|
|
|
|
label: '播放/暂停',
|
|
|
|
|
icon: nativeImage.createFromPath(
|
|
|
|
@ -79,9 +87,27 @@ export function createTray(win) {
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
]);
|
|
|
|
|
let tray = new Tray(icon);
|
|
|
|
|
tray.setToolTip('YesPlayMusic');
|
|
|
|
|
|
|
|
|
|
if (process.platform === 'linux') {
|
|
|
|
|
//linux下托盘的实现方式比较迷惑
|
|
|
|
|
//right-click无法在linux下使用
|
|
|
|
|
//click在默认行为下会弹出一个contextMenu,里面的唯一选项才会调用click事件
|
|
|
|
|
//setContextMenu应该是目前唯一能在linux下使用托盘菜单api
|
|
|
|
|
//但是无法区分鼠标左右键
|
|
|
|
|
|
|
|
|
|
tray.setContextMenu(contextMenu);
|
|
|
|
|
} else {
|
|
|
|
|
//windows and macos
|
|
|
|
|
tray.on('click', () => {
|
|
|
|
|
win.show();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
tray.on('right-click', () => {
|
|
|
|
|
tray.popUpContextMenu(contextMenu);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return tray;
|
|
|
|
|
}
|
|
|
|
|