Skip to content

Commit

Permalink
fix(mpris): fix mpris position
Browse files Browse the repository at this point in the history
- fix #2225
  • Loading branch information
JellyBrick committed Jul 14, 2024
1 parent 363d869 commit 7de7303
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/plugins/shortcuts/mpris.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,18 +102,21 @@ function registerMPRIS(win: BrowserWindow) {
return videoId.replace(/-/g, '_MINUS_');
};

const player = setupMPRIS();

const seekTo = (event: Position) => {
if (
currentSongInfo?.videoId &&
event.trackId.endsWith(correctId(currentSongInfo.videoId))
) {
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));

const player = setupMPRIS();
player.setPosition(player.getPosition() + offset);
};

ipcMain.on('ytmd:player-api-loaded', () => {
win.webContents.send('ytmd:setup-seeked-listener', 'mpris');
Expand All @@ -126,7 +129,10 @@ function registerMPRIS(win: BrowserWindow) {
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) => {
player.setPosition(secToMicro(t));
Expand Down

0 comments on commit 7de7303

Please sign in to comment.