added functionality to favorite a song. fixes #323

This commit is contained in:
Rick van Lieshout 2024-01-07 14:58:49 +01:00
parent 1d19857977
commit 5e82c18d8a
7 changed files with 25 additions and 0 deletions

View File

@ -10,6 +10,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Updated dependencies to latest
- added theme files to stylelint ignore
- fixed other stylelint errors
- Added functionality to favorite a song ([fixes #323](https://github.com/Mastermindzh/tidal-hifi/issues/323))
- Added a hotkey to favorite ("Add to collection") songs: Control+a
- Added the "favorite" field in the `mediaInfo` and the API `/current` endpoint
- Added an endpoint to toggle favoriting a song: `http://localhost:47836/favorite/toggle`
## [5.7.1]

View File

@ -12,4 +12,5 @@ export const globalEvents = {
error: "error",
whip: "whip",
log: "log",
toggleFavorite: "toggleFavorite",
};

View File

@ -10,4 +10,5 @@ export interface MediaInfo {
current: string;
duration: string;
image: string;
favorite: boolean;
}

View File

@ -9,4 +9,5 @@ export interface Options {
"app-name": string;
image: string;
icon: string;
favorite: boolean;
}

View File

@ -54,6 +54,7 @@ const elements = {
album_name_cell: '[class^="album"]',
tracklist_row: '[data-test="tracklist-row"]',
volume: '*[data-test="volume"]',
favorite: '*[data-test="footer-favorite-button"]',
/**
* Get an element from the dom
* @param {*} key key in elements object to fetch
@ -131,6 +132,10 @@ const elements = {
return this.get("volume").getAttribute("aria-checked") === "false"; // it's muted if aria-checked is false
},
isFavorite: function () {
return this.get("favorite").getAttribute("aria-checked") === "true";
},
/**
* Shorthand function to get the text of a dom element
* @param {*} key key in elements object to fetch
@ -208,6 +213,10 @@ function addHotKeys() {
handleLogout();
});
addHotkey("Control+a", function () {
elements.click("favorite");
});
addHotkey("Control+h", function () {
elements.click("home");
});
@ -306,6 +315,9 @@ function addIPCEventListeners() {
case globalEvents.pause:
elements.click("pause");
break;
case globalEvents.toggleFavorite:
elements.click("favorite");
break;
default:
break;
}
@ -516,6 +528,7 @@ setInterval(function () {
"app-name": appName,
image: "",
icon: "",
favorite: elements.isFavorite(),
};
const titleOrArtistsChanged = currentSong !== songDashArtistTitle;

View File

@ -40,6 +40,9 @@ export const startExpress = (mainWindow: BrowserWindow) => {
if (settingsStore.get(settings.playBackControl)) {
expressApp.get("/play", (req, res) => handleGlobalEvent(res, globalEvents.play));
expressApp.post("/favorite/toggle", (req, res) =>
handleGlobalEvent(res, globalEvents.toggleFavorite)
);
expressApp.get("/pause", (req, res) => handleGlobalEvent(res, globalEvents.pause));
expressApp.get("/next", (req, res) => handleGlobalEvent(res, globalEvents.next));
expressApp.get("/previous", (req, res) => handleGlobalEvent(res, globalEvents.previous));

View File

@ -11,6 +11,7 @@ export const mediaInfo = {
current: "",
duration: "",
image: "tidal-hifi-icon",
favorite: false,
};
export const updateMediaInfo = (arg: MediaInfo) => {
@ -23,6 +24,7 @@ export const updateMediaInfo = (arg: MediaInfo) => {
mediaInfo.current = propOrDefault(arg.current);
mediaInfo.duration = propOrDefault(arg.duration);
mediaInfo.image = propOrDefault(arg.image);
mediaInfo.favorite = arg.favorite;
};
/**