From cb4c96894946a057fc1b885ef733e03f8c99c202 Mon Sep 17 00:00:00 2001 From: jeffvli Date: Wed, 27 Oct 2021 14:19:32 -0700 Subject: [PATCH] Send current song to MPRIS when auto increment --- src/components/player/Player.tsx | 24 ++++++++++++++++++++++++ src/redux/playQueueSlice.ts | 2 +- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/src/components/player/Player.tsx b/src/components/player/Player.tsx index f2e633d..7251ff5 100644 --- a/src/components/player/Player.tsx +++ b/src/components/player/Player.tsx @@ -22,6 +22,7 @@ import { setCurrentIndex, setFadeData, setPlayerSrc, + getNextPlayerIndex, } from '../../redux/playQueueSlice'; import { setCurrentSeek } from '../../redux/playerSlice'; import cacheSong from '../shared/cacheSong'; @@ -398,6 +399,17 @@ const Player = ({ currentEntryList, children }: any, ref: any) => { dispatch(setIsFading(false)); } + ipcRenderer.send( + 'current-song', + playQueue[currentEntryList][ + getNextPlayerIndex( + playQueue[currentEntryList].length, + playQueue.repeat, + playQueue.player1.index + ) + ] + ); + dispatch(setAutoIncremented(false)); } } @@ -431,6 +443,18 @@ const Player = ({ currentEntryList, children }: any, ref: any) => { dispatch(setPlayerVolume({ player: 2, volume: 0 })); dispatch(setIsFading(false)); } + + ipcRenderer.send( + 'current-song', + playQueue[currentEntryList][ + getNextPlayerIndex( + playQueue[currentEntryList].length, + playQueue.repeat, + playQueue.player2.index + ) + ] + ); + dispatch(setAutoIncremented(false)); } } diff --git a/src/redux/playQueueSlice.ts b/src/redux/playQueueSlice.ts index 2ac5d24..3775552 100644 --- a/src/redux/playQueueSlice.ts +++ b/src/redux/playQueueSlice.ts @@ -168,7 +168,7 @@ const removeItem = (array: any, index: any) => { const entrySelect = (state: PlayQueue) => state.sortedEntry.length > 0 ? 'sortedEntry' : state.shuffle ? 'shuffledEntry' : 'entry'; -const getNextPlayerIndex = (length: number, repeat: string, currentIndex: number) => { +export const getNextPlayerIndex = (length: number, repeat: string, currentIndex: number) => { if (length >= 2 && repeat !== 'one') { if (currentIndex + 1 === length) { return 0;