mirror of
https://github.com/Mastermindzh/tidal-hifi.git
synced 2025-09-14 07:39:25 +02:00
Compare commits
7 Commits
renovate/s
...
d3e126d86b
Author | SHA1 | Date | |
---|---|---|---|
d3e126d86b | |||
d36bc7480f | |||
f608d42747 | |||
286c7789c0 | |||
d67f62c0dc | |||
01c5ec7ebb | |||
b2afd44dd6 |
@@ -1,16 +1,10 @@
|
||||
{
|
||||
"plugins": [
|
||||
"stylelint-prettier"
|
||||
],
|
||||
"extends": [
|
||||
"stylelint-config-standard-scss"
|
||||
],
|
||||
"ignoreFiles": [
|
||||
"src/themes/**.scss"
|
||||
],
|
||||
"plugins": ["stylelint-prettier"],
|
||||
"extends": ["stylelint-config-standard-scss"],
|
||||
"ignoreFiles": ["src/themes/**.scss"],
|
||||
"rules": {
|
||||
"prettier/prettier": true,
|
||||
"scss/at-extend-no-missing-placeholder": null,
|
||||
"no-descending-specificity": null
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -21,6 +21,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
|
||||
- Added all missing swagger/openApi info with the help of [Times-Z](https://github.com/Times-Z)
|
||||
- Updated most dependency versions
|
||||
|
||||
- This includes Electron 31!
|
||||
|
||||
- Added a channel selector so we can now use Tidal's staging environment directly from the app
|
||||
@@ -112,10 +113,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
|
||||
- Updated Electron to 28.1.1 (fixes [325](https://github.com/Mastermindzh/tidal-hifi/issues/325))
|
||||
- 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`
|
||||
@@ -136,10 +139,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
- Added settings to customize the Discord rich presence information
|
||||
- Discord settings are now also collapsible like the ListenBrainz ones are
|
||||
- Restyled settings menu to include version number and useful links on the about page
|
||||

|
||||

|
||||
- The ListenBrainz integration has been extended with a configurable (5 seconds by default) delay in song reporting so that it doesn't spam the API when you are cycling through songs.
|
||||
- Custom CSS now also applies to settings window
|
||||

|
||||

|
||||
|
||||
## [5.6.0]
|
||||
|
||||
|
@@ -8,4 +8,3 @@ Only the very latest 😄.
|
||||
|
||||
If you find a vulnerability just add it as an issue.
|
||||
If there's an especially bad vulnerability that you don't want to make public just send me a private message (email, discord, wherever).
|
||||
|
||||
|
6
package-lock.json
generated
6
package-lock.json
generated
@@ -6015,9 +6015,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/micromatch": {
|
||||
"version": "4.0.7",
|
||||
"resolved": "https://registry.npmjs.org/micromatch/-/micromatch-4.0.7.tgz",
|
||||
"integrity": "sha512-LPP/3KorzCwBxfeUuZmaR6bG2kdeHSbe0P2tY3FLRU4vYrjYz5hI4QZwV0njUx3jeuKe67YukQ1LSPZBKDqO/Q==",
|
||||
"version": "4.0.8",
|
||||
"resolved": "https://registry.npmjs.org/micromatch/-/micromatch-4.0.8.tgz",
|
||||
"integrity": "sha512-PXwfBhYu0hBCPw8Dn0E+WDYb7af3dSLVWKi3HGv84IdF4TyFoC0ysxFd0Goxw7nSv4T/PzEJQxsYsEiFCKo2BA==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
|
@@ -23,6 +23,7 @@
|
||||
"build-mac": "npm run builder -- -c ./build/electron-builder.yml -m",
|
||||
"build-base": "npm run builder -- -c ./build/electron-builder.base.yml",
|
||||
"prebuilder": "npm run compile",
|
||||
"prettier": "prettier . --write",
|
||||
"builder": "electron-builder --publish=never",
|
||||
"sass": "sass ./src/pages/settings/settings.scss ./src/pages/settings/settings.css && sass --no-source-map src/themes:themes",
|
||||
"style-lint": "npx stylelint **/*.scss",
|
||||
@@ -80,4 +81,4 @@
|
||||
"typescript": "^5.5.3"
|
||||
},
|
||||
"prettier": "@mastermindzh/prettier-config"
|
||||
}
|
||||
}
|
||||
|
295
src/TidalControllers/DomTidalController.ts
Normal file
295
src/TidalControllers/DomTidalController.ts
Normal file
@@ -0,0 +1,295 @@
|
||||
import { MediaStatus } from "../models/mediaStatus";
|
||||
import { RepeatState } from "../models/repeatState";
|
||||
import { TidalController } from "./TidalController";
|
||||
|
||||
export class DomTidalController implements TidalController {
|
||||
private currentPlayStatus = MediaStatus.paused;
|
||||
|
||||
/**
|
||||
* Convert the duration from MM:SS to seconds
|
||||
* @param {*} duration
|
||||
*/
|
||||
private convertDuration(duration: string) {
|
||||
const parts = duration.split(":");
|
||||
return parseInt(parts[1]) + 60 * parseInt(parts[0]);
|
||||
}
|
||||
|
||||
private readonly elements = {
|
||||
play: '*[data-test="play"]',
|
||||
pause: '*[data-test="pause"]',
|
||||
next: '*[data-test="next"]',
|
||||
previous: 'button[data-test="previous"]',
|
||||
title: '*[data-test^="footer-track-title"]',
|
||||
artists: '*[data-test^="grid-item-detail-text-title-artist"]',
|
||||
home: '*[data-test="menu--home"]',
|
||||
back: '[title^="Back"]',
|
||||
forward: '[title^="Next"]',
|
||||
search: '[class^="searchField"]',
|
||||
shuffle: '*[data-test="shuffle"]',
|
||||
repeat: '*[data-test="repeat"]',
|
||||
account: '*[data-test^="profile-image-button"]',
|
||||
settings: '*[data-test^="sidebar-menu-button"]',
|
||||
openSettings: '*[data-test^="open-settings"]',
|
||||
media: '*[data-test="current-media-imagery"]',
|
||||
image: "img",
|
||||
current: '*[data-test="current-time"]',
|
||||
duration: '*[class^=playbackControlsContainer] *[data-test="duration"]',
|
||||
bar: '*[data-test="progress-bar"]',
|
||||
footer: "#footerPlayer",
|
||||
mediaItem: "[data-type='mediaItem']",
|
||||
album_header_title: '*[class^="playingFrom"] span:nth-child(2)',
|
||||
playing_from: '*[class^="playingFrom"] span:nth-child(2)',
|
||||
queue_album: "*[class^=playQueueItemsContainer] *[class^=groupTitle] span:nth-child(2)",
|
||||
currentlyPlaying: "[class^='isPlayingIcon'], [data-test-is-playing='true']",
|
||||
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
|
||||
*/
|
||||
get: function (key: string) {
|
||||
return globalThis.document.querySelector(this[key.toLowerCase()]);
|
||||
},
|
||||
|
||||
/**
|
||||
* Get the icon of the current media
|
||||
*/
|
||||
getSongIcon: function () {
|
||||
const figure = this.get("media");
|
||||
|
||||
if (figure) {
|
||||
const mediaElement = figure.querySelector(this["image"]);
|
||||
if (mediaElement) {
|
||||
return mediaElement.src.replace("80x80", "640x640");
|
||||
}
|
||||
}
|
||||
|
||||
return "";
|
||||
},
|
||||
|
||||
/**
|
||||
* returns an array of all artists in the current media
|
||||
* @returns {Array} artists
|
||||
*/
|
||||
getArtistsArray: function () {
|
||||
const footer = this.get("footer");
|
||||
|
||||
if (footer) {
|
||||
const artists = footer.querySelectorAll(this.artists);
|
||||
if (artists)
|
||||
return Array.from(artists).map((artist) => (artist as HTMLElement).textContent);
|
||||
}
|
||||
return [];
|
||||
},
|
||||
|
||||
/**
|
||||
* unify the artists array into a string separated by commas
|
||||
* @param {Array} artistsArray
|
||||
* @returns {String} artists
|
||||
*/
|
||||
getArtistsString: function (artistsArray: string[]) {
|
||||
if (artistsArray.length > 0) return artistsArray.join(", ");
|
||||
return "unknown artist(s)";
|
||||
},
|
||||
|
||||
getAlbumName: function () {
|
||||
//If listening to an album, get its name from the header title
|
||||
if (globalThis.location.href.includes("/album/")) {
|
||||
const albumName = globalThis.document.querySelector(this.album_header_title);
|
||||
if (albumName) {
|
||||
return albumName.textContent;
|
||||
}
|
||||
//If listening to a playlist or a mix, get album name from the list
|
||||
} else if (
|
||||
globalThis.location.href.includes("/playlist/") ||
|
||||
globalThis.location.href.includes("/mix/")
|
||||
) {
|
||||
if (this.currentPlayStatus === MediaStatus.playing) {
|
||||
// find the currently playing element from the list (which might be in an album icon), traverse back up to the mediaItem (row) and select the album cell.
|
||||
// document.querySelector("[class^='isPlayingIcon'], [data-test-is-playing='true']").closest('[data-type="mediaItem"]').querySelector('[class^="album"]').textContent
|
||||
const row = window.document.querySelector(this.currentlyPlaying).closest(this.mediaItem);
|
||||
if (row) {
|
||||
return row.querySelector(this.album_name_cell).textContent;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// see whether we're on the queue page and get it from there
|
||||
const queueAlbumName = this.getText("queue_album");
|
||||
if (queueAlbumName) {
|
||||
return queueAlbumName;
|
||||
}
|
||||
|
||||
return "";
|
||||
},
|
||||
|
||||
isMuted: function () {
|
||||
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
|
||||
*/
|
||||
getText: function (key: string) {
|
||||
const element = this.get(key);
|
||||
return element ? element.textContent : "";
|
||||
},
|
||||
|
||||
/**
|
||||
* Shorthand function to click a dom element
|
||||
* @param {*} key key in elements object to fetch
|
||||
*/
|
||||
click: function (key: string) {
|
||||
this.get(key).click();
|
||||
return this;
|
||||
},
|
||||
|
||||
/**
|
||||
* Shorthand function to focus a dom element
|
||||
* @param {*} key key in elements object to fetch
|
||||
*/
|
||||
focus: function (key: string) {
|
||||
return this.get(key).focus();
|
||||
},
|
||||
};
|
||||
|
||||
playPause = (): void => {
|
||||
const play = this.elements.get("play");
|
||||
|
||||
if (play) {
|
||||
this.elements.click("play");
|
||||
} else {
|
||||
this.elements.click("pause");
|
||||
}
|
||||
};
|
||||
|
||||
goToHome(): void {
|
||||
this.elements.click("home");
|
||||
}
|
||||
|
||||
openSettings(): void {
|
||||
this.elements.click("settings");
|
||||
setTimeout(() => {
|
||||
this.elements.click("openSettings");
|
||||
}, 100);
|
||||
}
|
||||
|
||||
toggleFavorite(): void {
|
||||
this.elements.click("favorite");
|
||||
}
|
||||
|
||||
back(): void {
|
||||
this.elements.click("back");
|
||||
}
|
||||
forward(): void {
|
||||
this.elements.click("forward");
|
||||
}
|
||||
repeat(): void {
|
||||
this.elements.click("repeat");
|
||||
}
|
||||
|
||||
next(): void {
|
||||
this.elements.click("next");
|
||||
}
|
||||
previous(): void {
|
||||
this.elements.click("previous");
|
||||
}
|
||||
toggleShuffle(): void {
|
||||
this.elements.click("shuffle");
|
||||
}
|
||||
getCurrentlyPlayingStatus() {
|
||||
const pause = this.elements.get("pause");
|
||||
|
||||
// if pause button is visible tidal is playing
|
||||
if (pause) {
|
||||
return MediaStatus.playing;
|
||||
} else {
|
||||
return MediaStatus.paused;
|
||||
}
|
||||
}
|
||||
|
||||
getCurrentShuffleState() {
|
||||
const shuffle = this.elements.get("shuffle");
|
||||
return shuffle?.getAttribute("aria-checked") === "true";
|
||||
}
|
||||
|
||||
getCurrentRepeatState() {
|
||||
const repeat = this.elements.get("repeat");
|
||||
switch (repeat?.getAttribute("data-type")) {
|
||||
case "button__repeatAll":
|
||||
return RepeatState.all;
|
||||
case "button__repeatSingle":
|
||||
return RepeatState.single;
|
||||
default:
|
||||
return RepeatState.off;
|
||||
}
|
||||
}
|
||||
|
||||
play(): void {
|
||||
this.playPause();
|
||||
}
|
||||
pause(): void {
|
||||
this.playPause();
|
||||
}
|
||||
stop(): void {
|
||||
this.playPause();
|
||||
}
|
||||
|
||||
getCurrentPosition() {
|
||||
return this.elements.getText("current");
|
||||
}
|
||||
getCurrentPositionInSeconds(): number {
|
||||
return this.convertDuration(this.getCurrentPosition()) * 1000 * 1000;
|
||||
}
|
||||
|
||||
getTrackId(): string {
|
||||
const URLelement = this.elements.get("title").querySelector("a");
|
||||
if (URLelement !== null) {
|
||||
const id = URLelement.href.replace(/\D/g, "");
|
||||
return id;
|
||||
}
|
||||
|
||||
return window.location.toString();
|
||||
}
|
||||
|
||||
getCurrentTime(): string {
|
||||
return this.elements.getText("current");
|
||||
}
|
||||
getDuration(): string {
|
||||
return this.elements.getText("duration");
|
||||
}
|
||||
|
||||
getAlbumName(): string {
|
||||
return this.elements.getAlbumName();
|
||||
}
|
||||
getTitle(): string {
|
||||
return this.elements.getText("title");
|
||||
}
|
||||
getArtists(): string[] {
|
||||
return this.elements.getArtistsArray();
|
||||
}
|
||||
|
||||
getArtistsString(): string {
|
||||
return this.elements.getArtistsString(this.getArtists());
|
||||
}
|
||||
getPlayingFrom(): string {
|
||||
return this.elements.getText("playing_from");
|
||||
}
|
||||
|
||||
isFavorite(): boolean {
|
||||
return this.elements.isFavorite();
|
||||
}
|
||||
getSongIcon(): string {
|
||||
return this.elements.getSongIcon();
|
||||
}
|
||||
setPlayStatus(status: MediaStatus): void {
|
||||
this.currentPlayStatus = status;
|
||||
}
|
||||
}
|
133
src/TidalControllers/MediaSessionTidalController.ts
Normal file
133
src/TidalControllers/MediaSessionTidalController.ts
Normal file
@@ -0,0 +1,133 @@
|
||||
import { MediaStatus } from "../models/mediaStatus";
|
||||
import { RepeatState } from "../models/repeatState";
|
||||
import { DomTidalController } from "./DomTidalController";
|
||||
import { TidalController } from "./TidalController";
|
||||
|
||||
export class MediaSessionTidalController implements TidalController {
|
||||
public domMediaController: TidalController;
|
||||
|
||||
constructor() {
|
||||
this.domMediaController = new DomTidalController();
|
||||
}
|
||||
// example of using the original domMediaController as a fallback
|
||||
goToHome(): void {
|
||||
this.domMediaController.goToHome();
|
||||
}
|
||||
|
||||
setPlayStatus(status: MediaStatus): void {
|
||||
globalThis.alert("Method not implemented: " + status);
|
||||
throw new Error("Method not implemented.");
|
||||
}
|
||||
getDuration(): string {
|
||||
globalThis.alert("Method not implemented");
|
||||
throw new Error("Method not implemented.");
|
||||
}
|
||||
getAlbumName(): string {
|
||||
globalThis.alert("Method not implemented");
|
||||
throw new Error("Method not implemented.");
|
||||
}
|
||||
getTitle(): string {
|
||||
globalThis.alert("Method not implemented");
|
||||
throw new Error("Method not implemented.");
|
||||
}
|
||||
getArtists(): string[] {
|
||||
globalThis.alert("Method not implemented");
|
||||
throw new Error("Method not implemented.");
|
||||
}
|
||||
getArtistsString(): string {
|
||||
globalThis.alert("Method not implemented");
|
||||
throw new Error("Method not implemented.");
|
||||
}
|
||||
getPlayingFrom(): string {
|
||||
globalThis.alert("Method not implemented");
|
||||
throw new Error("Method not implemented.");
|
||||
}
|
||||
isFavorite(): boolean {
|
||||
globalThis.alert("Method not implemented");
|
||||
throw new Error("Method not implemented.");
|
||||
}
|
||||
getSongIcon(): string {
|
||||
globalThis.alert("Method not implemented");
|
||||
throw new Error("Method not implemented.");
|
||||
}
|
||||
getCurrentTime(): string {
|
||||
globalThis.alert("Method not implemented");
|
||||
throw new Error("Method not implemented.");
|
||||
}
|
||||
getCurrentPosition(): string {
|
||||
globalThis.alert("Method not implemented");
|
||||
throw new Error("Method not implemented.");
|
||||
}
|
||||
getCurrentPositionInSeconds(): number {
|
||||
globalThis.alert("Method not implemented");
|
||||
throw new Error("Method not implemented.");
|
||||
}
|
||||
getTrackId(): string {
|
||||
globalThis.alert("Method not implemented");
|
||||
throw new Error("Method not implemented.");
|
||||
}
|
||||
play(): void {
|
||||
globalThis.alert("Method not implemented");
|
||||
throw new Error("Method not implemented.");
|
||||
}
|
||||
pause(): void {
|
||||
globalThis.alert("Method not implemented");
|
||||
throw new Error("Method not implemented.");
|
||||
}
|
||||
stop(): void {
|
||||
globalThis.alert("Method not implemented");
|
||||
throw new Error("Method not implemented.");
|
||||
}
|
||||
getCurrentShuffleState(): boolean {
|
||||
globalThis.alert("Method not implemented");
|
||||
throw new Error("Method not implemented.");
|
||||
}
|
||||
getCurrentRepeatState(): RepeatState {
|
||||
globalThis.alert("Method not implemented");
|
||||
throw new Error("Method not implemented.");
|
||||
}
|
||||
getCurrentlyPlayingStatus(): MediaStatus {
|
||||
globalThis.alert("Method not implemented");
|
||||
throw new Error("Method not implemented.");
|
||||
}
|
||||
back(): void {
|
||||
globalThis.alert("Method not implemented");
|
||||
throw new Error("Method not implemented.");
|
||||
}
|
||||
forward(): void {
|
||||
globalThis.alert("Method not implemented");
|
||||
throw new Error("Method not implemented.");
|
||||
}
|
||||
repeat(): void {
|
||||
globalThis.alert("Method not implemented");
|
||||
throw new Error("Method not implemented.");
|
||||
}
|
||||
next(): void {
|
||||
globalThis.alert("Method not implemented");
|
||||
throw new Error("Method not implemented.");
|
||||
}
|
||||
previous(): void {
|
||||
globalThis.alert("Method not implemented");
|
||||
throw new Error("Method not implemented.");
|
||||
}
|
||||
toggleShuffle(): void {
|
||||
globalThis.alert("Method not implemented");
|
||||
throw new Error("Method not implemented.");
|
||||
}
|
||||
openSettings(): void {
|
||||
globalThis.alert("Method not implemented");
|
||||
throw new Error("Method not implemented.");
|
||||
}
|
||||
toggleFavorite(): void {
|
||||
globalThis.alert("Method not implemented");
|
||||
throw new Error("Method not implemented.");
|
||||
}
|
||||
playPause(): void {
|
||||
globalThis.alert("Method not implemented");
|
||||
throw new Error("Method not implemented.");
|
||||
}
|
||||
hookup(): void {
|
||||
globalThis.alert("Method not implemented");
|
||||
throw new Error("Method not implemented.");
|
||||
}
|
||||
}
|
47
src/TidalControllers/TidalController.ts
Normal file
47
src/TidalControllers/TidalController.ts
Normal file
@@ -0,0 +1,47 @@
|
||||
import { MediaStatus } from "../models/mediaStatus";
|
||||
import { RepeatState } from "../models/repeatState";
|
||||
|
||||
export interface TidalController {
|
||||
goToHome(): void;
|
||||
openSettings(): void;
|
||||
|
||||
/**
|
||||
* Play or pause the current media
|
||||
*/
|
||||
playPause(): void;
|
||||
play(): void;
|
||||
pause(): void;
|
||||
stop(): void;
|
||||
toggleFavorite(): void;
|
||||
back(): void;
|
||||
forward(): void;
|
||||
repeat(): void;
|
||||
next(): void;
|
||||
previous(): void;
|
||||
toggleShuffle(): void;
|
||||
|
||||
/**
|
||||
* Update the current status of tidal (e.g playing or paused)
|
||||
*/
|
||||
getCurrentlyPlayingStatus(): MediaStatus;
|
||||
getCurrentShuffleState(): boolean;
|
||||
getCurrentRepeatState(): RepeatState;
|
||||
getCurrentPosition(): string;
|
||||
getCurrentPositionInSeconds(): number;
|
||||
getTrackId(): string;
|
||||
getCurrentTime(): string;
|
||||
getDuration(): string;
|
||||
getAlbumName(): string;
|
||||
getTitle(): string;
|
||||
getArtists(): string[];
|
||||
getArtistsString(): string;
|
||||
getPlayingFrom(): string;
|
||||
getSongIcon(): string;
|
||||
|
||||
isFavorite(): boolean;
|
||||
// add an observable to react on instead of a hookup function
|
||||
// onMediaChange(): any;
|
||||
|
||||
// this can probably be removed after ^
|
||||
setPlayStatus(status: MediaStatus): void;
|
||||
}
|
File diff suppressed because it is too large
Load Diff
306
src/preload.ts
306
src/preload.ts
@@ -21,11 +21,13 @@ import { addHotkey } from "./scripts/hotkeys";
|
||||
import { ObjectToDotNotation } from "./scripts/objectUtilities";
|
||||
import { settingsStore } from "./scripts/settings";
|
||||
import { setTitle } from "./scripts/window-functions";
|
||||
import { DomTidalController } from "./TidalControllers/DomTidalController";
|
||||
import { MediaSessionTidalController } from "./TidalControllers/MediaSessionTidalController";
|
||||
import { TidalController } from "./TidalControllers/TidalController";
|
||||
|
||||
const notificationPath = `${app.getPath("userData")}/notification.jpg`;
|
||||
let currentSong = "";
|
||||
let player: Player;
|
||||
let currentPlayStatus = MediaStatus.paused;
|
||||
let currentListenBrainzDelayId: ReturnType<typeof setTimeout>;
|
||||
let scrobbleWaitingForDelay = false;
|
||||
|
||||
@@ -35,150 +37,15 @@ let currentShuffleState = false;
|
||||
let currentMediaInfo: MediaInfo;
|
||||
let currentNotification: Electron.Notification;
|
||||
|
||||
const elements = {
|
||||
play: '*[data-test="play"]',
|
||||
pause: '*[data-test="pause"]',
|
||||
next: '*[data-test="next"]',
|
||||
previous: 'button[data-test="previous"]',
|
||||
title: '*[data-test^="footer-track-title"]',
|
||||
artists: '*[data-test^="grid-item-detail-text-title-artist"]',
|
||||
home: '*[data-test="menu--home"]',
|
||||
back: '[title^="Back"]',
|
||||
forward: '[title^="Next"]',
|
||||
search: '[class^="searchField"]',
|
||||
shuffle: '*[data-test="shuffle"]',
|
||||
repeat: '*[data-test="repeat"]',
|
||||
account: '*[data-test^="profile-image-button"]',
|
||||
settings: '*[data-test^="sidebar-menu-button"]',
|
||||
openSettings: '*[data-test^="open-settings"]',
|
||||
media: '*[data-test="current-media-imagery"]',
|
||||
image: "img",
|
||||
current: '*[data-test="current-time"]',
|
||||
duration: '*[class^=playbackControlsContainer] *[data-test="duration"]',
|
||||
bar: '*[data-test="progress-bar"]',
|
||||
footer: "#footerPlayer",
|
||||
mediaItem: "[data-type='mediaItem']",
|
||||
album_header_title: '*[class^="playingFrom"] span:nth-child(2)',
|
||||
playing_from: '*[class^="playingFrom"] span:nth-child(2)',
|
||||
queue_album: "*[class^=playQueueItemsContainer] *[class^=groupTitle] span:nth-child(2)",
|
||||
currentlyPlaying: "[class^='isPlayingIcon'], [data-test-is-playing='true']",
|
||||
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
|
||||
*/
|
||||
get: function (key: string) {
|
||||
return window.document.querySelector(this[key.toLowerCase()]);
|
||||
},
|
||||
let tidalController: TidalController;
|
||||
|
||||
/**
|
||||
* Get the icon of the current media
|
||||
*/
|
||||
getSongIcon: function () {
|
||||
const figure = this.get("media");
|
||||
|
||||
if (figure) {
|
||||
const mediaElement = figure.querySelector(this["image"]);
|
||||
if (mediaElement) {
|
||||
return mediaElement.src.replace("80x80", "640x640");
|
||||
}
|
||||
}
|
||||
|
||||
return "";
|
||||
},
|
||||
|
||||
/**
|
||||
* returns an array of all artists in the current media
|
||||
* @returns {Array} artists
|
||||
*/
|
||||
getArtistsArray: function () {
|
||||
const footer = this.get("footer");
|
||||
|
||||
if (footer) {
|
||||
const artists = footer.querySelectorAll(this.artists);
|
||||
if (artists) return Array.from(artists).map((artist) => (artist as HTMLElement).textContent);
|
||||
}
|
||||
return [];
|
||||
},
|
||||
|
||||
/**
|
||||
* unify the artists array into a string separated by commas
|
||||
* @param {Array} artistsArray
|
||||
* @returns {String} artists
|
||||
*/
|
||||
getArtistsString: function (artistsArray: string[]) {
|
||||
if (artistsArray.length > 0) return artistsArray.join(", ");
|
||||
return "unknown artist(s)";
|
||||
},
|
||||
|
||||
getAlbumName: function () {
|
||||
//If listening to an album, get its name from the header title
|
||||
if (window.location.href.includes("/album/")) {
|
||||
const albumName = window.document.querySelector(this.album_header_title);
|
||||
if (albumName) {
|
||||
return albumName.textContent;
|
||||
}
|
||||
//If listening to a playlist or a mix, get album name from the list
|
||||
} else if (
|
||||
window.location.href.includes("/playlist/") ||
|
||||
window.location.href.includes("/mix/")
|
||||
) {
|
||||
if (currentPlayStatus === MediaStatus.playing) {
|
||||
// find the currently playing element from the list (which might be in an album icon), traverse back up to the mediaItem (row) and select the album cell.
|
||||
// document.querySelector("[class^='isPlayingIcon'], [data-test-is-playing='true']").closest('[data-type="mediaItem"]').querySelector('[class^="album"]').textContent
|
||||
const row = window.document.querySelector(this.currentlyPlaying).closest(this.mediaItem);
|
||||
if (row) {
|
||||
return row.querySelector(this.album_name_cell).textContent;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// see whether we're on the queue page and get it from there
|
||||
const queueAlbumName = elements.getText("queue_album");
|
||||
if (queueAlbumName) {
|
||||
return queueAlbumName;
|
||||
}
|
||||
|
||||
return "";
|
||||
},
|
||||
|
||||
isMuted: function () {
|
||||
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
|
||||
*/
|
||||
getText: function (key: string) {
|
||||
const element = this.get(key);
|
||||
return element ? element.textContent : "";
|
||||
},
|
||||
|
||||
/**
|
||||
* Shorthand function to click a dom element
|
||||
* @param {*} key key in elements object to fetch
|
||||
*/
|
||||
click: function (key: string) {
|
||||
this.get(key).click();
|
||||
return this;
|
||||
},
|
||||
|
||||
/**
|
||||
* Shorthand function to focus a dom element
|
||||
* @param {*} key key in elements object to fetch
|
||||
*/
|
||||
focus: function (key: string) {
|
||||
return this.get(key).focus();
|
||||
},
|
||||
};
|
||||
// TODO: replace with setting
|
||||
// eslint-disable-next-line no-constant-condition
|
||||
if (true) {
|
||||
tidalController = new DomTidalController();
|
||||
} else {
|
||||
tidalController = new MediaSessionTidalController();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the update frequency from the store
|
||||
@@ -195,19 +62,6 @@ function getUpdateFrequency() {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Play or pause the current media
|
||||
*/
|
||||
function playPause() {
|
||||
const play = elements.get("play");
|
||||
|
||||
if (play) {
|
||||
elements.click("play");
|
||||
} else {
|
||||
elements.click("pause");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears the old listenbrainz data on launch
|
||||
*/
|
||||
@@ -220,30 +74,26 @@ ListenBrainzStore.clear();
|
||||
*/
|
||||
function addHotKeys() {
|
||||
if (settingsStore.get(settings.enableCustomHotkeys)) {
|
||||
addHotkey("Control+p", function () {
|
||||
elements.click("settings");
|
||||
setTimeout(() => {
|
||||
elements.click("openSettings");
|
||||
}, 100);
|
||||
addHotkey("Control+p", () => {
|
||||
tidalController.openSettings();
|
||||
});
|
||||
addHotkey("Control+l", function () {
|
||||
addHotkey("Control+l", () => {
|
||||
handleLogout();
|
||||
});
|
||||
|
||||
addHotkey("Control+a", function () {
|
||||
elements.click("favorite");
|
||||
addHotkey("Control+a", () => {
|
||||
tidalController.toggleFavorite();
|
||||
});
|
||||
|
||||
addHotkey("Control+h", function () {
|
||||
elements.click("home");
|
||||
addHotkey("Control+h", () => {
|
||||
tidalController.goToHome();
|
||||
});
|
||||
|
||||
addHotkey("backspace", function () {
|
||||
elements.click("back");
|
||||
tidalController.back();
|
||||
});
|
||||
|
||||
addHotkey("shift+backspace", function () {
|
||||
elements.click("forward");
|
||||
tidalController.forward();
|
||||
});
|
||||
|
||||
addHotkey("control+u", function () {
|
||||
@@ -252,7 +102,7 @@ function addHotKeys() {
|
||||
});
|
||||
|
||||
addHotkey("control+r", function () {
|
||||
elements.click("repeat");
|
||||
tidalController.repeat();
|
||||
});
|
||||
addHotkey("control+w", async function () {
|
||||
const url = SharingService.getUniversalLink(getTrackURL());
|
||||
@@ -319,22 +169,22 @@ function addIPCEventListeners() {
|
||||
case globalEvents.playPause:
|
||||
case globalEvents.play:
|
||||
case globalEvents.pause:
|
||||
playPause();
|
||||
tidalController.playPause();
|
||||
break;
|
||||
case globalEvents.next:
|
||||
elements.click("next");
|
||||
tidalController.next();
|
||||
break;
|
||||
case globalEvents.previous:
|
||||
elements.click("previous");
|
||||
tidalController.previous();
|
||||
break;
|
||||
case globalEvents.toggleFavorite:
|
||||
elements.click("favorite");
|
||||
tidalController.toggleFavorite();
|
||||
break;
|
||||
case globalEvents.toggleShuffle:
|
||||
elements.click("shuffle");
|
||||
tidalController.toggleShuffle();
|
||||
break;
|
||||
case globalEvents.toggleRepeat:
|
||||
elements.click("repeat");
|
||||
tidalController.repeat();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@@ -343,39 +193,6 @@ function addIPCEventListeners() {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the current status of tidal (e.g playing or paused)
|
||||
*/
|
||||
function getCurrentlyPlayingStatus() {
|
||||
const pause = elements.get("pause");
|
||||
let status = undefined;
|
||||
|
||||
// if pause button is visible tidal is playing
|
||||
if (pause) {
|
||||
status = MediaStatus.playing;
|
||||
} else {
|
||||
status = MediaStatus.paused;
|
||||
}
|
||||
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
|
||||
@@ -455,16 +272,35 @@ function addMPRIS() {
|
||||
const eventValue = events[eventName];
|
||||
switch (events[eventValue]) {
|
||||
case events.playpause:
|
||||
playPause();
|
||||
tidalController.playPause();
|
||||
break;
|
||||
case events.next:
|
||||
tidalController.next();
|
||||
break;
|
||||
case events.previous:
|
||||
tidalController.previous();
|
||||
break;
|
||||
case events.pause:
|
||||
tidalController.pause();
|
||||
break;
|
||||
case events.stop:
|
||||
tidalController.stop();
|
||||
break;
|
||||
case events.play:
|
||||
tidalController.play();
|
||||
break;
|
||||
case events.loopStatus:
|
||||
tidalController.repeat();
|
||||
break;
|
||||
case events.shuffle:
|
||||
tidalController.toggleShuffle();
|
||||
break;
|
||||
default:
|
||||
elements.click(eventValue);
|
||||
}
|
||||
});
|
||||
});
|
||||
// Override get position function
|
||||
player.getPosition = function () {
|
||||
return convertDuration(elements.getText("current")) * 1000 * 1000;
|
||||
return tidalController.getCurrentPositionInSeconds();
|
||||
};
|
||||
player.on("quit", function () {
|
||||
app.quit();
|
||||
@@ -485,7 +321,7 @@ function updateMpris(mediaInfo: MediaInfo) {
|
||||
"xesam:album": mediaInfo.album,
|
||||
"mpris:artUrl": mediaInfo.image,
|
||||
"mpris:length": convertDuration(mediaInfo.duration) * 1000 * 1000,
|
||||
"mpris:trackid": "/org/mpris/MediaPlayer2/track/" + getTrackID(),
|
||||
"mpris:trackid": "/org/mpris/MediaPlayer2/track/" + tidalController.getTrackId(),
|
||||
},
|
||||
...ObjectToDotNotation(mediaInfo, "custom:"),
|
||||
};
|
||||
@@ -528,34 +364,24 @@ function updateListenBrainz(mediaInfo: MediaInfo) {
|
||||
* If it's a song it returns the track URL, if not it will return undefined
|
||||
*/
|
||||
function getTrackURL() {
|
||||
const id = getTrackID();
|
||||
const id = tidalController.getTrackId();
|
||||
return `https://tidal.com/browse/track/${id}`;
|
||||
}
|
||||
|
||||
function getTrackID() {
|
||||
const URLelement = elements.get("title").querySelector("a");
|
||||
if (URLelement !== null) {
|
||||
const id = URLelement.href.replace(/\D/g, "");
|
||||
return id;
|
||||
}
|
||||
|
||||
return window.location;
|
||||
}
|
||||
|
||||
/**
|
||||
* Watch for song changes and update title + notify
|
||||
*/
|
||||
setInterval(function () {
|
||||
const title = elements.getText("title");
|
||||
const artistsArray = elements.getArtistsArray();
|
||||
const artistsString = elements.getArtistsString(artistsArray);
|
||||
const title = tidalController.getTitle();
|
||||
const artistsArray = tidalController.getArtists();
|
||||
const artistsString = tidalController.getArtistsString();
|
||||
const songDashArtistTitle = `${title} - ${artistsString}`;
|
||||
const staticTitle = "TIDAL Hi-Fi";
|
||||
const titleOrArtistsChanged = currentSong !== songDashArtistTitle;
|
||||
const current = elements.getText("current");
|
||||
const currentStatus = getCurrentlyPlayingStatus();
|
||||
const shuffleState = getCurrentShuffleState();
|
||||
const repeatState = getCurrentRepeatState();
|
||||
const current = tidalController.getCurrentTime();
|
||||
const currentStatus = tidalController.getCurrentlyPlayingStatus();
|
||||
const shuffleState = tidalController.getCurrentShuffleState();
|
||||
const repeatState = tidalController.getCurrentRepeatState();
|
||||
|
||||
const playStateChanged = currentStatus != currentlyPlaying;
|
||||
const shuffleStateChanged = shuffleState != currentShuffleState;
|
||||
@@ -570,13 +396,13 @@ setInterval(function () {
|
||||
if (repeatStateChanged) currentRepeatState = repeatState;
|
||||
|
||||
skipArtistsIfFoundInSkippedArtistsList(artistsArray);
|
||||
const album = elements.getAlbumName();
|
||||
const duration = elements.getText("duration");
|
||||
const album = tidalController.getAlbumName();
|
||||
const duration = tidalController.getDuration();
|
||||
const options: MediaInfo = {
|
||||
title,
|
||||
artists: artistsString,
|
||||
album: album,
|
||||
playingFrom: elements.getText("playing_from"),
|
||||
playingFrom: tidalController.getPlayingFrom(),
|
||||
status: currentStatus,
|
||||
url: getTrackURL(),
|
||||
current,
|
||||
@@ -585,7 +411,7 @@ setInterval(function () {
|
||||
durationInSeconds: convertDurationToSeconds(duration),
|
||||
image: "",
|
||||
icon: "",
|
||||
favorite: elements.isFavorite(),
|
||||
favorite: tidalController.isFavorite(),
|
||||
|
||||
player: {
|
||||
status: currentStatus,
|
||||
@@ -600,9 +426,9 @@ setInterval(function () {
|
||||
: setTitle(songDashArtistTitle);
|
||||
getTrackURL();
|
||||
currentSong = songDashArtistTitle;
|
||||
currentPlayStatus = currentStatus;
|
||||
tidalController.setPlayStatus(currentStatus);
|
||||
|
||||
const image = elements.getSongIcon();
|
||||
const image = tidalController.getSongIcon();
|
||||
|
||||
new Promise<void>((resolve) => {
|
||||
if (image.startsWith("http")) {
|
||||
@@ -644,7 +470,7 @@ setInterval(function () {
|
||||
const artistNames = Object.values(artists).map((artist) => artist);
|
||||
const foundArtist = artistNames.some((artist) => artistsToSkip.includes(artist));
|
||||
if (foundArtist) {
|
||||
elements.click("next");
|
||||
tidalController.next();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -26,7 +26,7 @@ const defaultPresence = {
|
||||
largeImageKey: "tidal-hifi-icon",
|
||||
largeImageText: `TIDAL Hi-Fi ${app.getVersion()}`,
|
||||
instance: false,
|
||||
type: ACTIVITY_LISTENING
|
||||
type: ACTIVITY_LISTENING,
|
||||
};
|
||||
|
||||
const updateActivity = () => {
|
||||
@@ -118,15 +118,17 @@ const getActivity = (): SetActivity => {
|
||||
const connectWithRetry = async (retryCount = 0) => {
|
||||
try {
|
||||
await rpc.login();
|
||||
Logger.log('Connected to Discord');
|
||||
Logger.log("Connected to Discord");
|
||||
rpc.on("ready", updateActivity);
|
||||
Object.values(globalEvents).forEach(event => ipcMain.on(event, observer));
|
||||
Object.values(globalEvents).forEach((event) => ipcMain.on(event, observer));
|
||||
} catch (error) {
|
||||
if (retryCount < MAX_RETRIES) {
|
||||
Logger.log(`Failed to connect to Discord, retrying in ${RETRY_DELAY/1000} seconds... (Attempt ${retryCount + 1}/${MAX_RETRIES})`);
|
||||
Logger.log(
|
||||
`Failed to connect to Discord, retrying in ${RETRY_DELAY / 1000} seconds... (Attempt ${retryCount + 1}/${MAX_RETRIES})`
|
||||
);
|
||||
setTimeout(() => connectWithRetry(retryCount + 1), RETRY_DELAY);
|
||||
} else {
|
||||
Logger.log('Failed to connect to Discord after maximum retry attempts');
|
||||
Logger.log("Failed to connect to Discord after maximum retry attempts");
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -135,7 +137,7 @@ const connectWithRetry = async (retryCount = 0) => {
|
||||
* Set up the discord rpc and listen on globalEvents.updateInfo
|
||||
*/
|
||||
export const initRPC = () => {
|
||||
rpc = new Client({ transport: {type: "ipc"}, clientId });
|
||||
rpc = new Client({ transport: { type: "ipc" }, clientId });
|
||||
connectWithRetry();
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user