From 7de7303ebb6a2b3deda6a76df85984940e62ec33 Mon Sep 17 00:00:00 2001 From: JellyBrick Date: Mon, 15 Jul 2024 00:14:49 +0900 Subject: [PATCH] fix(mpris): fix mpris position - fix #2225 --- src/plugins/shortcuts/mpris.ts | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/plugins/shortcuts/mpris.ts b/src/plugins/shortcuts/mpris.ts index 5b1ca48132..cdfc9d4b7b 100644 --- a/src/plugins/shortcuts/mpris.ts +++ b/src/plugins/shortcuts/mpris.ts @@ -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'); @@ -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));