From 3cbb047d29a30f6f7a28c246f6c2fb5d3ebdf1fd Mon Sep 17 00:00:00 2001 From: nutty Date: Sun, 9 Aug 2026 23:28:14 +1000 Subject: [PATCH] Fixed session priority --- now-playing/script.js | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/now-playing/script.js b/now-playing/script.js index bd1a5bf..16cf62e 100644 --- a/now-playing/script.js +++ b/now-playing/script.js @@ -379,15 +379,20 @@ async function UpdatePlayerState(data) { } } else { // Fallback when no included list is provided: - // Priority 1: Find any session that is currently playing - targetSession = validSessions.find(s => s.playback_info && s.playback_info.PlaybackStatus === PlaybackStatus.PLAYING); - - // Priority 2: If nothing is playing, use system's current active session ID - if (!targetSession) { + // Priority 1: Check Windows' current focused session ID first + if (data.current_session_id) { targetSession = validSessions.find(s => s.source_app_id === data.current_session_id); } - - // Priority 3: Ultimate fallback to the first valid session available + + // Priority 2: If the current session isn't available/valid, find any session that is currently playing + if (!targetSession || targetSession.playback_info.PlaybackStatus !== PlaybackStatus.PLAYING) { + const playingSession = validSessions.find(s => s.playback_info && s.playback_info.PlaybackStatus === PlaybackStatus.PLAYING); + if (playingSession) { + targetSession = playingSession; + } + } + + // Priority 3: Ultimate fallback to the first valid session available if nothing else matched if (!targetSession && validSessions.length > 0) { targetSession = validSessions[0]; }