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 - Updated dependencies to latest
- added theme files to stylelint ignore - added theme files to stylelint ignore
- fixed other stylelint errors - 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] ## [5.7.1]

View File

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

View File

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

View File

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

View File

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

View File

@ -40,6 +40,9 @@ export const startExpress = (mainWindow: BrowserWindow) => {
if (settingsStore.get(settings.playBackControl)) { if (settingsStore.get(settings.playBackControl)) {
expressApp.get("/play", (req, res) => handleGlobalEvent(res, globalEvents.play)); 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("/pause", (req, res) => handleGlobalEvent(res, globalEvents.pause));
expressApp.get("/next", (req, res) => handleGlobalEvent(res, globalEvents.next)); expressApp.get("/next", (req, res) => handleGlobalEvent(res, globalEvents.next));
expressApp.get("/previous", (req, res) => handleGlobalEvent(res, globalEvents.previous)); expressApp.get("/previous", (req, res) => handleGlobalEvent(res, globalEvents.previous));

View File

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