From 2d94b4bf496e55f4ca5bbc9345a08f085c282b6f Mon Sep 17 00:00:00 2001 From: ThatGravyBoat Date: Mon, 6 May 2024 03:50:41 -0230 Subject: [PATCH 1/3] Add shuffle and repeat to current state api --- src/models/mediaInfo.ts | 2 ++ src/models/mediaPlayerInfo.ts | 8 +++++++ src/models/repeatState.ts | 5 +++++ src/preload.ts | 41 +++++++++++++++++++++++++++++++---- src/scripts/mediaInfo.ts | 11 ++++++++++ 5 files changed, 63 insertions(+), 4 deletions(-) create mode 100644 src/models/mediaPlayerInfo.ts create mode 100644 src/models/repeatState.ts diff --git a/src/models/mediaInfo.ts b/src/models/mediaInfo.ts index 7a87760..7fcd5e9 100644 --- a/src/models/mediaInfo.ts +++ b/src/models/mediaInfo.ts @@ -1,4 +1,5 @@ import { MediaStatus } from "./mediaStatus"; +import {MediaPlayerInfo} from "./mediaPlayerInfo"; export interface MediaInfo { title: string; @@ -13,4 +14,5 @@ export interface MediaInfo { durationInSeconds?: number; image: string; favorite: boolean; + player: MediaPlayerInfo; } diff --git a/src/models/mediaPlayerInfo.ts b/src/models/mediaPlayerInfo.ts new file mode 100644 index 0000000..70e57f6 --- /dev/null +++ b/src/models/mediaPlayerInfo.ts @@ -0,0 +1,8 @@ +import {RepeatState} from "./repeatState"; +import {MediaStatus} from "./mediaStatus"; + +export interface MediaPlayerInfo { + status: MediaStatus; + shuffle: boolean; + repeat: RepeatState; +} diff --git a/src/models/repeatState.ts b/src/models/repeatState.ts new file mode 100644 index 0000000..4b54619 --- /dev/null +++ b/src/models/repeatState.ts @@ -0,0 +1,5 @@ +export enum RepeatState { + off = "off", + all = "all", + single = "single", +} diff --git a/src/preload.ts b/src/preload.ts index 4127a7a..61187ec 100644 --- a/src/preload.ts +++ b/src/preload.ts @@ -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"; @@ -29,6 +30,8 @@ let currentListenBrainzDelayId: ReturnType; let scrobbleWaitingForDelay = false; let currentlyPlaying = MediaStatus.paused; +let currentRepeatState: RepeatState = RepeatState.off; +let currentShuffleState = false; let currentMediaInfo: Options; let currentNotification: Electron.Notification; @@ -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 @@ -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(); @@ -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 diff --git a/src/scripts/mediaInfo.ts b/src/scripts/mediaInfo.ts index 9cfada4..6e2b56e 100644 --- a/src/scripts/mediaInfo.ts +++ b/src/scripts/mediaInfo.ts @@ -1,5 +1,6 @@ import { MediaInfo } from "../models/mediaInfo"; import { MediaStatus } from "../models/mediaStatus"; +import {RepeatState} from "../models/repeatState"; export const mediaInfo = { title: "", @@ -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) => { @@ -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); }; /** From 5f8cf33249b88afbb65f2e0f09e618dcbda24f0e Mon Sep 17 00:00:00 2001 From: ThatGravyBoat Date: Mon, 6 May 2024 03:55:09 -0230 Subject: [PATCH 2/3] Fix mismatched import styling --- src/models/mediaInfo.ts | 2 +- src/models/mediaPlayerInfo.ts | 4 ++-- src/preload.ts | 2 +- src/scripts/mediaInfo.ts | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/models/mediaInfo.ts b/src/models/mediaInfo.ts index 7fcd5e9..1db49fe 100644 --- a/src/models/mediaInfo.ts +++ b/src/models/mediaInfo.ts @@ -1,5 +1,5 @@ import { MediaStatus } from "./mediaStatus"; -import {MediaPlayerInfo} from "./mediaPlayerInfo"; +import { MediaPlayerInfo } from "./mediaPlayerInfo"; export interface MediaInfo { title: string; diff --git a/src/models/mediaPlayerInfo.ts b/src/models/mediaPlayerInfo.ts index 70e57f6..fd997f5 100644 --- a/src/models/mediaPlayerInfo.ts +++ b/src/models/mediaPlayerInfo.ts @@ -1,5 +1,5 @@ -import {RepeatState} from "./repeatState"; -import {MediaStatus} from "./mediaStatus"; +import { RepeatState } from "./repeatState"; +import { MediaStatus } from "./mediaStatus"; export interface MediaPlayerInfo { status: MediaStatus; diff --git a/src/preload.ts b/src/preload.ts index 61187ec..eb01332 100644 --- a/src/preload.ts +++ b/src/preload.ts @@ -19,7 +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"; +import { RepeatState } from "./models/repeatState"; const notificationPath = `${app.getPath("userData")}/notification.jpg`; const appName = "TIDAL Hi-Fi"; diff --git a/src/scripts/mediaInfo.ts b/src/scripts/mediaInfo.ts index 6e2b56e..fba1973 100644 --- a/src/scripts/mediaInfo.ts +++ b/src/scripts/mediaInfo.ts @@ -1,6 +1,6 @@ import { MediaInfo } from "../models/mediaInfo"; import { MediaStatus } from "../models/mediaStatus"; -import {RepeatState} from "../models/repeatState"; +import { RepeatState } from "../models/repeatState"; export const mediaInfo = { title: "", From a0f9faa7535480a901e0a4e89e442994da9f4976 Mon Sep 17 00:00:00 2001 From: Rick van Lieshout Date: Tue, 14 May 2024 22:53:07 +0200 Subject: [PATCH 3/3] chore: updating versions --- CHANGELOG.md | 4 ++++ package-lock.json | 4 ++-- package.json | 2 +- src/pages/settings/settings.html | 2 +- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2ebc0af..4c9d55d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/package-lock.json b/package-lock.json index 79084a3..7695c24 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "tidal-hifi", - "version": "5.11.0", + "version": "5.12.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "tidal-hifi", - "version": "5.11.0", + "version": "5.12.0", "license": "MIT", "dependencies": { "@electron/remote": "^2.1.2", diff --git a/package.json b/package.json index d5d33e0..2a48818 100644 --- a/package.json +++ b/package.json @@ -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": { diff --git a/src/pages/settings/settings.html b/src/pages/settings/settings.html index f27bd28..fe20bbb 100644 --- a/src/pages/settings/settings.html +++ b/src/pages/settings/settings.html @@ -433,7 +433,7 @@

TIDAL Hi-Fi

5.11.0 + href="https://github.com/Mastermindzh/tidal-hifi/releases/tag/5.12.0">5.12.0