Skip to content

Commit

Permalink
Refactored nowPlaying code to always display the current state, even …
Browse files Browse the repository at this point in the history
…when the built-in UI is updated. fixes #351 #356 #370
  • Loading branch information
Mastermindzh committed Mar 24, 2024
1 parent 4ef76c2 commit 17b2818
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down
18 changes: 12 additions & 6 deletions src/preload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ let player: Player;
let currentPlayStatus = MediaStatus.paused;
let currentListenBrainzDelayId: ReturnType<typeof setTimeout>;
let scrobbleWaitingForDelay = false;
let wasJustPausedOrResumed = false;

let currentlyPlaying = MediaStatus.paused;
let currentMediaInfo: Options;
let currentNotification: Electron.Notification;

Expand Down Expand Up @@ -185,7 +186,6 @@ function getUpdateFrequency() {
* Play or pause the current song
*/
function playPause() {
wasJustPausedOrResumed = true;
const play = elements.get("play");

if (play) {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);

Expand Down

0 comments on commit 17b2818

Please sign in to comment.