Skip to content

Commit

Permalink
Merge pull request #402 from Mastermindzh/5.12
Browse files Browse the repository at this point in the history
5.12
  • Loading branch information
Mastermindzh authored May 14, 2024
2 parents 6e43cbb + a0f9faa commit 3740ce5
Show file tree
Hide file tree
Showing 9 changed files with 71 additions and 8 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [5.12.0]

- Added Shuffle and Repeat state to API response - By [ThatGravyBoat](https://github.com/ThatGravyBoat)

## [5.11.0]

- Re-implemented the API, added support for duration/current in seconds & shuffle+repeat
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "tidal-hifi",
"version": "5.11.0",
"version": "5.12.0",
"description": "Tidal on Electron with widevine(hifi) support",
"main": "ts-dist/main.js",
"scripts": {
Expand Down
2 changes: 2 additions & 0 deletions src/models/mediaInfo.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { MediaStatus } from "./mediaStatus";
import { MediaPlayerInfo } from "./mediaPlayerInfo";

export interface MediaInfo {
title: string;
Expand All @@ -13,4 +14,5 @@ export interface MediaInfo {
durationInSeconds?: number;
image: string;
favorite: boolean;
player: MediaPlayerInfo;
}
8 changes: 8 additions & 0 deletions src/models/mediaPlayerInfo.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { RepeatState } from "./repeatState";
import { MediaStatus } from "./mediaStatus";

export interface MediaPlayerInfo {
status: MediaStatus;
shuffle: boolean;
repeat: RepeatState;
}
5 changes: 5 additions & 0 deletions src/models/repeatState.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export enum RepeatState {
off = "off",
all = "all",
single = "single",
}
2 changes: 1 addition & 1 deletion src/pages/settings/settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ <h4>Upload new themes</h4>
<h4>TIDAL Hi-Fi</h4>
<div class="about-section__version">
<a target="_blank" rel="noopener"
href="https://github.com/Mastermindzh/tidal-hifi/releases/tag/5.11.0">5.11.0</a>
href="https://github.com/Mastermindzh/tidal-hifi/releases/tag/5.12.0">5.12.0</a>
</div>
<div class="about-section__links">
<a target="_blank" rel="noopener" href="https://github.com/mastermindzh/tidal-hifi/"
Expand Down
41 changes: 37 additions & 4 deletions src/preload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { downloadFile } from "./scripts/download";
import { addHotkey } from "./scripts/hotkeys";
import { settingsStore } from "./scripts/settings";
import { setTitle } from "./scripts/window-functions";
import { RepeatState } from "./models/repeatState";

const notificationPath = `${app.getPath("userData")}/notification.jpg`;
const appName = "TIDAL Hi-Fi";
Expand All @@ -29,6 +30,8 @@ let currentListenBrainzDelayId: ReturnType<typeof setTimeout>;
let scrobbleWaitingForDelay = false;

let currentlyPlaying = MediaStatus.paused;
let currentRepeatState: RepeatState = RepeatState.off;
let currentShuffleState = false;
let currentMediaInfo: Options;
let currentNotification: Electron.Notification;

Expand Down Expand Up @@ -348,6 +351,23 @@ function getCurrentlyPlayingStatus() {
return status;
}

function getCurrentShuffleState() {
const shuffle = elements.get("shuffle");
return shuffle?.getAttribute("aria-checked") === "true";
}

function getCurrentRepeatState() {
const repeat = elements.get("repeat");
switch (repeat?.getAttribute("data-type")) {
case "button__repeatAll":
return RepeatState.all;
case "button__repeatSingle":
return RepeatState.single;
default:
return RepeatState.off;
}
}

/**
* Convert the duration from MM:SS to seconds
* @param {*} duration
Expand Down Expand Up @@ -511,14 +531,21 @@ setInterval(function () {
const titleOrArtistsChanged = currentSong !== songDashArtistTitle;
const current = elements.getText("current");
const currentStatus = getCurrentlyPlayingStatus();
const shuffleState = getCurrentShuffleState();
const repeatState = getCurrentRepeatState();

const playStateChanged = currentStatus != currentlyPlaying;
const shuffleStateChanged = shuffleState != currentShuffleState;
const repeatStateChanged = repeatState != currentRepeatState;

const hasStateChanged = playStateChanged || shuffleStateChanged || repeatStateChanged;

// update info if song changed or was just paused/resumed
if (titleOrArtistsChanged || playStateChanged) {
if (playStateChanged) {
currentlyPlaying = currentStatus;
}
if (titleOrArtistsChanged || hasStateChanged) {
if (playStateChanged) currentlyPlaying = currentStatus;
if (shuffleStateChanged) currentShuffleState = shuffleState;
if (repeatStateChanged) currentRepeatState = repeatState;

skipArtistsIfFoundInSkippedArtistsList(artistsArray);

const album = elements.getAlbumName();
Expand All @@ -537,6 +564,12 @@ setInterval(function () {
image: "",
icon: "",
favorite: elements.isFavorite(),

player: {
status: currentStatus,
shuffle: shuffleState,
repeat: repeatState,
},
};

// update title, url and play info with new info
Expand Down
11 changes: 11 additions & 0 deletions src/scripts/mediaInfo.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { MediaInfo } from "../models/mediaInfo";
import { MediaStatus } from "../models/mediaStatus";
import { RepeatState } from "../models/repeatState";

export const mediaInfo = {
title: "",
Expand All @@ -14,6 +15,12 @@ export const mediaInfo = {
durationInSeconds: 0,
image: "tidal-hifi-icon",
favorite: false,

player: {
status: MediaStatus.paused as string,
shuffle: false,
repeat: RepeatState.off as string,
}
};

export const updateMediaInfo = (arg: MediaInfo) => {
Expand All @@ -29,6 +36,10 @@ export const updateMediaInfo = (arg: MediaInfo) => {
mediaInfo.durationInSeconds = arg.durationInSeconds ?? 0;
mediaInfo.image = propOrDefault(arg.image);
mediaInfo.favorite = arg.favorite;

mediaInfo.player.status = propOrDefault(arg.player?.status);
mediaInfo.player.shuffle = arg.player.shuffle;
mediaInfo.player.repeat = propOrDefault(arg.player?.repeat);
};

/**
Expand Down

0 comments on commit 3740ce5

Please sign in to comment.