mirror of
https://github.com/jeffvli/feishin.git
synced 2026-05-07 04:20:12 +02:00
b8228844df
* Added simple macOS dock menu similar to tray menu * Enhanced and moved dock menu to darwin folder and enabled mpris on macOS to support play/pause state * Added missing property sortName to silence TS error
58 lines
1.4 KiB
TypeScript
58 lines
1.4 KiB
TypeScript
import { app, ipcMain, Menu } from 'electron';
|
|
|
|
import { getMainWindow } from '/@/main/index';
|
|
import { PlayerStatus } from '/@/shared/types/types';
|
|
|
|
let currentStatus: PlayerStatus = PlayerStatus.PAUSED;
|
|
|
|
const updateDockMenu = () => {
|
|
if (!app.dock) return;
|
|
|
|
const isPlaying = currentStatus === PlayerStatus.PLAYING;
|
|
|
|
const dockMenu = Menu.buildFromTemplate([
|
|
{
|
|
click: () => {
|
|
getMainWindow()?.webContents.send('renderer-player-play-pause');
|
|
},
|
|
label: isPlaying ? 'Pause' : 'Play',
|
|
},
|
|
{
|
|
type: 'separator',
|
|
},
|
|
{
|
|
click: () => {
|
|
getMainWindow()?.webContents.send('renderer-player-next');
|
|
},
|
|
label: 'Next',
|
|
},
|
|
{
|
|
click: () => {
|
|
getMainWindow()?.webContents.send('renderer-player-previous');
|
|
},
|
|
label: 'Previous',
|
|
},
|
|
{
|
|
type: 'separator',
|
|
},
|
|
{
|
|
click: () => {
|
|
getMainWindow()?.webContents.send('renderer-player-stop');
|
|
},
|
|
label: 'Stop',
|
|
},
|
|
]);
|
|
|
|
app.dock.setMenu(dockMenu);
|
|
};
|
|
|
|
ipcMain.on('update-playback', (_event, status: PlayerStatus) => {
|
|
currentStatus = status;
|
|
updateDockMenu();
|
|
});
|
|
|
|
// Initialize dock menu after app is ready
|
|
app.whenReady().then(() => {
|
|
updateDockMenu();
|
|
});
|