From 17b2818b701779931fa105f2b51c9ca9661a11b8 Mon Sep 17 00:00:00 2001 From: Rick van Lieshout Date: Sun, 24 Mar 2024 16:13:21 +0100 Subject: [PATCH] Refactored nowPlaying code to always display the current state, even when the built-in UI is updated. fixes #351 #356 #370 --- CHANGELOG.md | 4 ++++ src/preload.ts | 18 ++++++++++++------ 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 374f167..2849118 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - TIDAL will now close the previous notification if a new one is sent whilst the old is still visible. [#364](https://github.com/Mastermindzh/tidal-hifi/pull/364) - Updated developer documentation to get started in README [#365](https://github.com/Mastermindzh/tidal-hifi/pull/365) - Links in the about window now open in the user's default browser. fixes [#360](https://github.com/Mastermindzh/tidal-hifi/issues/360) +- Refactored "nowPlaying" code to always display the current state, even when the built-in UI is updated. + - fixes [#351](https://github.com/Mastermindzh/tidal-hifi/issues/351) + - fixes [#356](https://github.com/Mastermindzh/tidal-hifi/issues/356) + - fixes [#370](https://github.com/Mastermindzh/tidal-hifi/issues/370) ## [5.9.0] diff --git a/src/preload.ts b/src/preload.ts index 885a012..9bf463b 100644 --- a/src/preload.ts +++ b/src/preload.ts @@ -26,7 +26,8 @@ let player: Player; let currentPlayStatus = MediaStatus.paused; let currentListenBrainzDelayId: ReturnType; let scrobbleWaitingForDelay = false; -let wasJustPausedOrResumed = false; + +let currentlyPlaying = MediaStatus.paused; let currentMediaInfo: Options; let currentNotification: Electron.Notification; @@ -185,7 +186,6 @@ function getUpdateFrequency() { * Play or pause the current song */ function playPause() { - wasJustPausedOrResumed = true; const play = elements.get("play"); if (play) { @@ -361,7 +361,11 @@ function updateMediaInfo(options: Options, notify: boolean) { ipcRenderer.send(globalEvents.updateInfo, options); if (settingsStore.get(settings.notifications) && notify) { if (currentNotification) currentNotification.close(); - currentNotification = new Notification({ title: options.title, body: options.artists, icon: options.icon }); + currentNotification = new Notification({ + title: options.title, + body: options.artists, + icon: options.icon, + }); currentNotification.show(); } updateMpris(options); @@ -518,10 +522,12 @@ setInterval(function () { const current = elements.getText("current"); const currentStatus = getCurrentlyPlayingStatus(); + const playStateChanged = currentStatus != currentlyPlaying; + // update info if song changed or was just paused/resumed - if (titleOrArtistsChanged || wasJustPausedOrResumed) { - if (wasJustPausedOrResumed) { - wasJustPausedOrResumed = false; + if (titleOrArtistsChanged || playStateChanged) { + if (playStateChanged) { + currentlyPlaying = currentStatus; } skipArtistsIfFoundInSkippedArtistsList(artistsArray);