mirror of
https://github.com/th-ch/youtube-music.git
synced 2026-01-14 20:01:47 +00:00
@ -102,18 +102,21 @@ function registerMPRIS(win: BrowserWindow) {
|
|||||||
return videoId.replace(/-/g, '_MINUS_');
|
return videoId.replace(/-/g, '_MINUS_');
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const player = setupMPRIS();
|
||||||
|
|
||||||
const seekTo = (event: Position) => {
|
const seekTo = (event: Position) => {
|
||||||
if (
|
if (
|
||||||
currentSongInfo?.videoId &&
|
currentSongInfo?.videoId &&
|
||||||
event.trackId.endsWith(correctId(currentSongInfo.videoId))
|
event.trackId.endsWith(correctId(currentSongInfo.videoId))
|
||||||
) {
|
) {
|
||||||
win.webContents.send('ytmd:seek-to', microToSec(event.position ?? 0));
|
win.webContents.send('ytmd:seek-to', microToSec(event.position ?? 0));
|
||||||
|
player.setPosition(event.position ?? 0);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
const seekBy = (offset: number) =>
|
const seekBy = (offset: number) => {
|
||||||
win.webContents.send('ytmd:seek-by', microToSec(offset));
|
win.webContents.send('ytmd:seek-by', microToSec(offset));
|
||||||
|
player.setPosition(player.getPosition() + offset);
|
||||||
const player = setupMPRIS();
|
};
|
||||||
|
|
||||||
ipcMain.on('ytmd:player-api-loaded', () => {
|
ipcMain.on('ytmd:player-api-loaded', () => {
|
||||||
win.webContents.send('ytmd:setup-seeked-listener', 'mpris');
|
win.webContents.send('ytmd:setup-seeked-listener', 'mpris');
|
||||||
@ -126,7 +129,10 @@ function registerMPRIS(win: BrowserWindow) {
|
|||||||
requestQueueInformation();
|
requestQueueInformation();
|
||||||
});
|
});
|
||||||
|
|
||||||
ipcMain.on('ytmd:seeked', (_, t: number) => player.seeked(secToMicro(t)));
|
ipcMain.on('ytmd:seeked', (_, t: number) => {
|
||||||
|
player.setPosition(secToMicro(t));
|
||||||
|
player.seeked(secToMicro(t));
|
||||||
|
});
|
||||||
|
|
||||||
ipcMain.on('ytmd:time-changed', (_, t: number) => {
|
ipcMain.on('ytmd:time-changed', (_, t: number) => {
|
||||||
player.setPosition(secToMicro(t));
|
player.setPosition(secToMicro(t));
|
||||||
|
|||||||
Reference in New Issue
Block a user