2021-04-19 23:08:19 +02:00
|
|
|
const { setTitle } = require("./scripts/window-functions");
|
2022-08-07 16:05:48 +02:00
|
|
|
const { dialog, process, Notification } = require("@electron/remote");
|
2019-11-03 11:18:01 +01:00
|
|
|
const { store, settings } = require("./scripts/settings");
|
2019-10-22 21:25:57 +02:00
|
|
|
const { ipcRenderer } = require("electron");
|
2022-08-07 16:05:48 +02:00
|
|
|
const { app } = require("@electron/remote");
|
2019-10-22 21:25:57 +02:00
|
|
|
const { downloadFile } = require("./scripts/download");
|
2019-10-30 23:42:08 +01:00
|
|
|
const statuses = require("./constants/statuses");
|
2019-10-30 22:49:04 +01:00
|
|
|
const hotkeys = require("./scripts/hotkeys");
|
|
|
|
const globalEvents = require("./constants/globalEvents");
|
2023-01-22 21:18:20 +01:00
|
|
|
const { skipArtists } = require("./constants/settings");
|
2019-10-22 21:25:57 +02:00
|
|
|
const notificationPath = `${app.getPath("userData")}/notification.jpg`;
|
2022-04-21 17:49:11 +02:00
|
|
|
const appName = "Tidal Hifi";
|
2019-11-03 18:52:15 +01:00
|
|
|
let currentSong = "";
|
2020-11-29 10:55:01 +01:00
|
|
|
let player;
|
2021-04-19 23:08:19 +02:00
|
|
|
let currentPlayStatus = statuses.paused;
|
2019-10-20 22:47:01 +02:00
|
|
|
|
|
|
|
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"]',
|
2021-05-30 15:40:27 +02:00
|
|
|
artists: '*[data-test^="grid-item-detail-text-title-artist"]',
|
2019-10-20 22:47:01 +02:00
|
|
|
home: '*[data-test="menu--home"]',
|
|
|
|
back: '[class^="backwardButton"]',
|
|
|
|
forward: '[class^="forwardButton"]',
|
|
|
|
search: '[class^="searchField"]',
|
|
|
|
shuffle: '*[data-test="shuffle"]',
|
|
|
|
repeat: '*[data-test="repeat"]',
|
|
|
|
block: '[class="blockButton"]',
|
|
|
|
account: '*[data-test^="profile-image-button"]',
|
|
|
|
settings: '*[data-test^="open-settings"]',
|
2019-10-22 21:25:57 +02:00
|
|
|
media: '*[data-test="current-media-imagery"]',
|
2021-01-10 13:52:22 +01:00
|
|
|
image: "img",
|
2021-04-20 21:56:02 +02:00
|
|
|
current: '*[data-test="current-time"]',
|
2022-06-18 10:26:21 +02:00
|
|
|
duration: '*[data-test="duration"]',
|
2021-04-20 21:56:02 +02:00
|
|
|
bar: '*[data-test="progress-bar"]',
|
2021-05-30 15:40:27 +02:00
|
|
|
footer: "#footerPlayer",
|
2021-12-28 17:31:10 +01:00
|
|
|
album_header_title: '.header-details [data-test="title"]',
|
|
|
|
playing_title: 'span[data-test="table-cell-title"].css-geqnfr',
|
|
|
|
album_name_cell: '[data-test="table-cell-album"]',
|
|
|
|
tracklist_row: '[data-test="tracklist-row"]',
|
2022-03-31 17:37:12 +02:00
|
|
|
volume: '*[data-test="volume"]',
|
2019-10-22 21:25:57 +02:00
|
|
|
/**
|
|
|
|
* Get an element from the dom
|
|
|
|
* @param {*} key key in elements object to fetch
|
|
|
|
*/
|
2020-10-04 11:52:08 +02:00
|
|
|
get: function (key) {
|
2019-10-20 22:47:01 +02:00
|
|
|
return window.document.querySelector(this[key.toLowerCase()]);
|
|
|
|
},
|
|
|
|
|
2019-10-22 21:25:57 +02:00
|
|
|
/**
|
|
|
|
* Get the icon of the current song
|
|
|
|
*/
|
2020-10-04 11:52:08 +02:00
|
|
|
getSongIcon: function () {
|
2019-10-22 21:25:57 +02:00
|
|
|
const figure = this.get("media");
|
|
|
|
|
|
|
|
if (figure) {
|
|
|
|
const mediaElement = figure.querySelector(this["image"]);
|
|
|
|
if (mediaElement) {
|
2021-12-19 13:18:39 +01:00
|
|
|
return mediaElement.src.replace("80x80", "640x640");
|
2019-10-22 21:25:57 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return "";
|
|
|
|
},
|
|
|
|
|
2023-04-23 21:24:04 +02:00
|
|
|
/**
|
|
|
|
* returns an array of all artists in the current song
|
|
|
|
* @returns {Array} artists
|
|
|
|
*/
|
|
|
|
getArtistsArray: function () {
|
2021-05-30 15:40:27 +02:00
|
|
|
const footer = this.get("footer");
|
|
|
|
|
|
|
|
if (footer) {
|
2023-04-23 21:24:04 +02:00
|
|
|
const artists = footer.querySelectorAll(this.artists);
|
|
|
|
if (artists)
|
|
|
|
return Array.from(artists).map((artist) => artist.textContent);
|
2021-05-30 15:40:27 +02:00
|
|
|
}
|
2023-04-23 21:24:04 +02:00
|
|
|
return [];
|
|
|
|
},
|
2021-05-30 15:40:27 +02:00
|
|
|
|
2023-04-23 21:24:04 +02:00
|
|
|
/**
|
|
|
|
* unify the artists array into a string separated by commas
|
|
|
|
* @param {Array} artistsArray
|
|
|
|
* @returns {String} artists
|
|
|
|
*/
|
|
|
|
getArtistsString: function (artistsArray) {
|
|
|
|
if (artistsArray.length > 0)
|
|
|
|
return artistsArray.join(", ");
|
2021-05-30 15:40:27 +02:00
|
|
|
return "unknown artist(s)";
|
|
|
|
},
|
|
|
|
|
2021-12-28 17:31:10 +01:00
|
|
|
getAlbumName: function () {
|
|
|
|
//If listening to an album, get its name from the header title
|
2022-01-23 10:55:50 +01:00
|
|
|
if (window.location.href.includes("/album/")) {
|
2021-12-28 17:31:10 +01:00
|
|
|
const albumName = window.document.querySelector(this.album_header_title);
|
2022-01-23 10:55:50 +01:00
|
|
|
if (albumName) {
|
2021-12-28 17:31:10 +01:00
|
|
|
return albumName.textContent;
|
|
|
|
}
|
|
|
|
//If listening to a playlist or a mix, get album name from the list
|
2022-01-23 10:55:50 +01:00
|
|
|
} else if (
|
|
|
|
window.location.href.includes("/playlist/") ||
|
|
|
|
window.location.href.includes("/mix/")
|
|
|
|
) {
|
|
|
|
if (currentPlayStatus === statuses.playing) {
|
2021-12-28 17:31:10 +01:00
|
|
|
const row = window.document.querySelector(this.playing_title).closest(this.tracklist_row);
|
2022-01-23 10:55:50 +01:00
|
|
|
if (row) {
|
|
|
|
return row.querySelector(this.album_name_cell).textContent;
|
2021-12-28 17:31:10 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return "";
|
|
|
|
},
|
|
|
|
|
2022-03-31 17:37:12 +02:00
|
|
|
isMuted: function () {
|
|
|
|
return this.get("volume").getAttribute("aria-checked") === "false"; // it's muted if aria-checked is false
|
|
|
|
},
|
|
|
|
|
2019-10-22 21:25:57 +02:00
|
|
|
/**
|
|
|
|
* Shorthand function to get the text of a dom element
|
|
|
|
* @param {*} key key in elements object to fetch
|
|
|
|
*/
|
2020-10-04 11:52:08 +02:00
|
|
|
getText: function (key) {
|
2019-10-22 21:25:57 +02:00
|
|
|
const element = this.get(key);
|
|
|
|
return element ? element.textContent : "";
|
2019-10-20 22:47:01 +02:00
|
|
|
},
|
|
|
|
|
2019-10-22 21:25:57 +02:00
|
|
|
/**
|
|
|
|
* Shorthand function to click a dom element
|
|
|
|
* @param {*} key key in elements object to fetch
|
|
|
|
*/
|
2020-10-04 11:52:08 +02:00
|
|
|
click: function (key) {
|
2019-10-20 22:47:01 +02:00
|
|
|
this.get(key).click();
|
|
|
|
return this;
|
|
|
|
},
|
2019-10-22 21:25:57 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Shorthand function to focus a dom element
|
|
|
|
* @param {*} key key in elements object to fetch
|
|
|
|
*/
|
2020-10-04 11:52:08 +02:00
|
|
|
focus: function (key) {
|
2019-10-20 22:47:01 +02:00
|
|
|
return this.get(key).focus();
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Play or pause the current song
|
|
|
|
*/
|
|
|
|
function playPause() {
|
|
|
|
const play = elements.get("play");
|
|
|
|
|
|
|
|
if (play) {
|
|
|
|
elements.click("play");
|
|
|
|
} else {
|
|
|
|
elements.click("pause");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add hotkeys for when tidal is focused
|
|
|
|
* Reflects the desktop hotkeys found on:
|
|
|
|
* https://defkey.com/tidal-desktop-shortcuts
|
|
|
|
*/
|
|
|
|
function addHotKeys() {
|
2021-01-10 13:52:22 +01:00
|
|
|
if (store.get(settings.enableCustomHotkeys)) {
|
|
|
|
hotkeys.add("Control+p", function () {
|
|
|
|
elements.click("account").click("settings");
|
|
|
|
});
|
|
|
|
hotkeys.add("Control+l", function () {
|
|
|
|
handleLogout();
|
|
|
|
});
|
2019-10-20 22:47:01 +02:00
|
|
|
|
2021-01-10 13:52:22 +01:00
|
|
|
hotkeys.add("Control+h", function () {
|
|
|
|
elements.click("home");
|
|
|
|
});
|
2019-10-20 22:47:01 +02:00
|
|
|
|
2021-01-10 13:52:22 +01:00
|
|
|
hotkeys.add("backspace", function () {
|
|
|
|
elements.click("back");
|
|
|
|
});
|
2019-10-20 22:47:01 +02:00
|
|
|
|
2021-01-10 13:52:22 +01:00
|
|
|
hotkeys.add("shift+backspace", function () {
|
|
|
|
elements.click("forward");
|
|
|
|
});
|
2019-10-20 22:47:01 +02:00
|
|
|
|
2021-01-10 13:52:22 +01:00
|
|
|
hotkeys.add("control+u", function () {
|
|
|
|
// reloading window without cache should show the update bar if applicable
|
|
|
|
window.location.reload(true);
|
|
|
|
});
|
2019-10-20 22:47:01 +02:00
|
|
|
|
2021-01-10 13:52:22 +01:00
|
|
|
hotkeys.add("control+r", function () {
|
|
|
|
elements.click("repeat");
|
|
|
|
});
|
|
|
|
}
|
2019-11-03 18:52:15 +01:00
|
|
|
|
2021-01-10 13:52:22 +01:00
|
|
|
// always add the hotkey for the settings window
|
|
|
|
hotkeys.add("control+=", function () {
|
2019-11-03 18:52:15 +01:00
|
|
|
ipcRenderer.send(globalEvents.showSettings);
|
|
|
|
});
|
2022-01-23 11:02:28 +01:00
|
|
|
hotkeys.add("control+0", function () {
|
|
|
|
ipcRenderer.send(globalEvents.showSettings);
|
|
|
|
});
|
2019-10-20 22:47:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This function will ask the user whether he/she wants to log out.
|
|
|
|
* It will log the user out if he/she selects "yes"
|
|
|
|
*/
|
|
|
|
function handleLogout() {
|
|
|
|
const logoutOptions = ["Cancel", "Yes, please", "No, thanks"];
|
|
|
|
|
|
|
|
dialog.showMessageBox(
|
|
|
|
null,
|
|
|
|
{
|
|
|
|
type: "question",
|
|
|
|
title: "Logging out",
|
|
|
|
message: "Are you sure you want to log out?",
|
|
|
|
buttons: logoutOptions,
|
|
|
|
defaultId: 2,
|
|
|
|
},
|
2020-10-04 11:52:08 +02:00
|
|
|
function (response) {
|
2019-10-20 22:47:01 +02:00
|
|
|
if (logoutOptions.indexOf("Yes, please") == response) {
|
2021-04-19 20:59:37 +02:00
|
|
|
for (let i = 0; i < window.localStorage.length; i++) {
|
|
|
|
const key = window.localStorage.key(i);
|
2019-10-20 22:47:01 +02:00
|
|
|
if (key.startsWith("_TIDAL_activeSession")) {
|
|
|
|
window.localStorage.removeItem(key);
|
|
|
|
i = window.localStorage.length + 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
window.location.reload();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-01-23 10:55:50 +01:00
|
|
|
function addFullScreenListeners() {
|
2022-04-21 17:49:11 +02:00
|
|
|
window.document.addEventListener("fullscreenchange", () => {
|
2022-01-23 10:55:50 +01:00
|
|
|
ipcRenderer.send(globalEvents.refreshMenuBar);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-10-20 22:47:01 +02:00
|
|
|
/**
|
|
|
|
* Add ipc event listeners.
|
|
|
|
* Some actions triggered outside of the site need info from the site.
|
|
|
|
*/
|
|
|
|
function addIPCEventListeners() {
|
|
|
|
window.addEventListener("DOMContentLoaded", () => {
|
2022-04-21 17:49:11 +02:00
|
|
|
ipcRenderer.on("globalEvent", (_event, args) => {
|
2019-10-22 21:25:57 +02:00
|
|
|
switch (args) {
|
2019-10-30 22:49:04 +01:00
|
|
|
case globalEvents.playPause:
|
2019-10-22 21:25:57 +02:00
|
|
|
playPause();
|
|
|
|
break;
|
2019-10-30 22:49:04 +01:00
|
|
|
case globalEvents.next:
|
2019-10-22 21:25:57 +02:00
|
|
|
elements.click("next");
|
|
|
|
break;
|
2019-10-30 22:49:04 +01:00
|
|
|
case globalEvents.previous:
|
2019-10-22 21:25:57 +02:00
|
|
|
elements.click("previous");
|
|
|
|
break;
|
2019-10-30 22:49:04 +01:00
|
|
|
case globalEvents.play:
|
|
|
|
elements.click("play");
|
|
|
|
break;
|
|
|
|
case globalEvents.pause:
|
|
|
|
elements.click("pause");
|
|
|
|
break;
|
2019-10-22 21:25:57 +02:00
|
|
|
}
|
|
|
|
});
|
2019-10-20 22:47:01 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-10-30 23:42:08 +01:00
|
|
|
/**
|
|
|
|
* Update the current status of tidal (e.g playing or paused)
|
|
|
|
*/
|
2021-04-19 23:08:19 +02:00
|
|
|
function getCurrentlyPlayingStatus() {
|
2020-10-04 11:52:08 +02:00
|
|
|
let pause = elements.get("pause");
|
2021-04-19 23:08:19 +02:00
|
|
|
let status = undefined;
|
2020-10-04 11:52:08 +02:00
|
|
|
|
|
|
|
// if pause button is visible tidal is playing
|
|
|
|
if (pause) {
|
2019-10-30 23:42:08 +01:00
|
|
|
status = statuses.playing;
|
2020-10-04 11:52:08 +02:00
|
|
|
} else {
|
|
|
|
status = statuses.paused;
|
|
|
|
}
|
2021-04-19 23:08:19 +02:00
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2021-11-29 22:43:51 +01:00
|
|
|
/**
|
|
|
|
* Convert the duration from MM:SS to seconds
|
|
|
|
* @param {*} duration
|
|
|
|
*/
|
|
|
|
function convertDuration(duration) {
|
|
|
|
const parts = duration.split(":");
|
|
|
|
return parseInt(parts[1]) + 60 * parseInt(parts[0]);
|
|
|
|
}
|
|
|
|
|
2021-04-19 23:08:19 +02:00
|
|
|
/**
|
|
|
|
* Update Tidal-hifi's media info
|
|
|
|
*
|
|
|
|
* @param {*} options
|
|
|
|
*/
|
|
|
|
function updateMediaInfo(options, notify) {
|
|
|
|
if (options) {
|
|
|
|
ipcRenderer.send(globalEvents.updateInfo, options);
|
2022-01-23 10:55:50 +01:00
|
|
|
if (store.get(settings.notifications) && notify) {
|
|
|
|
new Notification({ title: options.title, body: options.message, icon: options.icon }).show();
|
2021-12-28 17:31:10 +01:00
|
|
|
}
|
2020-11-29 10:55:01 +01:00
|
|
|
if (player) {
|
2021-04-19 23:08:19 +02:00
|
|
|
player.metadata = {
|
|
|
|
...player.metadata,
|
|
|
|
...{
|
|
|
|
"xesam:title": options.title,
|
2021-11-29 22:43:51 +01:00
|
|
|
"xesam:artist": [options.message],
|
2021-12-28 17:31:10 +01:00
|
|
|
"xesam:album": options.album,
|
2021-04-19 23:08:19 +02:00
|
|
|
"mpris:artUrl": options.image,
|
2021-11-29 22:43:51 +01:00
|
|
|
"mpris:length": convertDuration(options.duration) * 1000 * 1000,
|
2023-04-20 19:11:22 +02:00
|
|
|
"mpris:trackid": "/org/mpris/MediaPlayer2/track/" + getTrackID(),
|
2021-04-19 23:08:19 +02:00
|
|
|
},
|
|
|
|
};
|
|
|
|
player.playbackStatus = options.status == statuses.paused ? "Paused" : "Playing";
|
2020-11-29 10:55:01 +01:00
|
|
|
}
|
2019-10-30 23:42:08 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-22 11:33:57 +02:00
|
|
|
/**
|
|
|
|
* Checks if Tidal is playing a video or song by grabbing the "a" element from the title.
|
2022-08-07 16:05:48 +02:00
|
|
|
* If it's a song it returns the track URL, if not it will return undefined
|
2021-04-22 11:33:57 +02:00
|
|
|
*/
|
2022-08-07 16:05:48 +02:00
|
|
|
function getTrackURL() {
|
2023-04-21 11:26:10 +02:00
|
|
|
const id = getTrackID();
|
|
|
|
return `https://tidal.com/browse/track/${id}`;
|
2021-04-22 11:33:57 +02:00
|
|
|
}
|
|
|
|
|
2023-04-20 19:11:22 +02:00
|
|
|
function getTrackID() {
|
|
|
|
const URLelement = elements.get("title").querySelector("a");
|
|
|
|
if (URLelement !== null) {
|
2023-04-21 11:26:10 +02:00
|
|
|
const id = URLelement.href.replace(/\D/g, "");
|
2023-04-20 19:11:22 +02:00
|
|
|
return id;
|
|
|
|
}
|
|
|
|
|
|
|
|
return window.location;
|
|
|
|
}
|
|
|
|
|
2019-10-20 22:47:01 +02:00
|
|
|
/**
|
2019-10-22 21:25:57 +02:00
|
|
|
* Watch for song changes and update title + notify
|
2019-10-20 22:47:01 +02:00
|
|
|
*/
|
2020-10-04 11:52:08 +02:00
|
|
|
setInterval(function () {
|
2019-10-20 22:47:01 +02:00
|
|
|
const title = elements.getText("title");
|
2023-04-23 21:24:04 +02:00
|
|
|
const artistsArray = elements.getArtistsArray();
|
|
|
|
const artistsString = elements.getArtistsString(artistsArray);
|
|
|
|
skipArtistsIfFoundInSkippedArtistsList(artistsArray);
|
2023-01-20 22:15:36 +01:00
|
|
|
|
2021-12-28 17:31:10 +01:00
|
|
|
const album = elements.getAlbumName();
|
2021-04-20 21:56:02 +02:00
|
|
|
const current = elements.getText("current");
|
|
|
|
const duration = elements.getText("duration");
|
2023-04-23 21:24:04 +02:00
|
|
|
const songDashArtistTitle = `${title} - ${artistsString}`;
|
2021-04-19 23:08:19 +02:00
|
|
|
const currentStatus = getCurrentlyPlayingStatus();
|
|
|
|
const options = {
|
|
|
|
title,
|
2023-04-23 21:24:04 +02:00
|
|
|
message: artistsString,
|
2021-12-28 17:31:10 +01:00
|
|
|
album: album,
|
2021-04-19 23:08:19 +02:00
|
|
|
status: currentStatus,
|
2022-08-07 16:05:48 +02:00
|
|
|
url: getTrackURL(),
|
|
|
|
current,
|
|
|
|
duration,
|
2022-01-23 10:55:50 +01:00
|
|
|
"app-name": appName,
|
2021-04-19 23:08:19 +02:00
|
|
|
};
|
2019-10-22 21:25:57 +02:00
|
|
|
|
2021-04-19 23:08:19 +02:00
|
|
|
const titleOrArtistChanged = currentSong !== songDashArtistTitle;
|
2019-10-30 23:42:08 +01:00
|
|
|
|
2022-08-07 16:05:48 +02:00
|
|
|
// update title, url and play info with new info
|
|
|
|
setTitle(songDashArtistTitle);
|
|
|
|
getTrackURL();
|
|
|
|
currentSong = songDashArtistTitle;
|
|
|
|
currentPlayStatus = currentStatus;
|
|
|
|
|
|
|
|
const image = elements.getSongIcon();
|
|
|
|
|
|
|
|
new Promise((resolve) => {
|
|
|
|
if (image.startsWith("http")) {
|
|
|
|
options.image = image;
|
|
|
|
downloadFile(image, notificationPath).then(
|
|
|
|
() => {
|
|
|
|
options.icon = notificationPath;
|
|
|
|
resolve();
|
|
|
|
},
|
|
|
|
() => {
|
|
|
|
// if the image can't be downloaded then continue without it
|
|
|
|
resolve();
|
|
|
|
}
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
// if the image can't be found on the page continue without it
|
|
|
|
resolve();
|
2021-04-20 22:15:34 +02:00
|
|
|
}
|
2022-08-07 16:05:48 +02:00
|
|
|
}).then(
|
|
|
|
() => {
|
|
|
|
updateMediaInfo(options, titleOrArtistChanged);
|
|
|
|
},
|
|
|
|
() => {}
|
|
|
|
);
|
2022-03-31 17:37:12 +02:00
|
|
|
|
2023-01-22 21:18:20 +01:00
|
|
|
/**
|
|
|
|
* automatically skip a song if the artists are found in the list of artists to skip
|
2023-04-23 21:24:04 +02:00
|
|
|
* @param {*} artists array of artists
|
2023-01-22 21:18:20 +01:00
|
|
|
*/
|
|
|
|
function skipArtistsIfFoundInSkippedArtistsList(artists) {
|
|
|
|
if (store.get(skipArtists)) {
|
|
|
|
const skippedArtists = store.get(settings.skippedArtists);
|
2023-04-23 21:24:04 +02:00
|
|
|
if (skippedArtists.length > 0) {
|
|
|
|
const artistsToSkip = skippedArtists.map((artist) => artist);
|
|
|
|
const artistNames = Object.values(artists).map((artist) => artist);
|
|
|
|
const foundArtist = artistNames.some((artist) => artistsToSkip.includes(artist));
|
|
|
|
if (foundArtist) {
|
|
|
|
elements.click("next");
|
|
|
|
}
|
2023-01-22 21:18:20 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-04-21 11:26:10 +02:00
|
|
|
}, 100);
|
2019-10-20 22:47:01 +02:00
|
|
|
|
2020-11-29 10:55:01 +01:00
|
|
|
if (process.platform === "linux" && store.get(settings.mpris)) {
|
|
|
|
try {
|
|
|
|
const Player = require("mpris-service");
|
|
|
|
player = Player({
|
|
|
|
name: "tidal-hifi",
|
|
|
|
identity: "tidal-hifi",
|
|
|
|
supportedUriSchemes: ["file"],
|
|
|
|
supportedMimeTypes: [
|
|
|
|
"audio/mpeg",
|
|
|
|
"audio/flac",
|
|
|
|
"audio/x-flac",
|
|
|
|
"application/ogg",
|
|
|
|
"audio/wav",
|
|
|
|
],
|
|
|
|
supportedInterfaces: ["player"],
|
|
|
|
desktopEntry: "tidal-hifi",
|
|
|
|
});
|
|
|
|
|
|
|
|
// Events
|
|
|
|
var events = {
|
|
|
|
next: "next",
|
|
|
|
previous: "previous",
|
|
|
|
pause: "pause",
|
|
|
|
playpause: "playpause",
|
|
|
|
stop: "stop",
|
|
|
|
play: "play",
|
|
|
|
loopStatus: "repeat",
|
|
|
|
shuffle: "shuffle",
|
|
|
|
seek: "seek",
|
|
|
|
};
|
|
|
|
Object.keys(events).forEach(function (eventName) {
|
|
|
|
player.on(eventName, function () {
|
|
|
|
const eventValue = events[eventName];
|
|
|
|
switch (events[eventValue]) {
|
|
|
|
case events.playpause:
|
|
|
|
playPause();
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
elements.click(eventValue);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
2021-11-29 22:43:51 +01:00
|
|
|
// Override get position function
|
|
|
|
player.getPosition = function () {
|
|
|
|
return convertDuration(elements.getText("current")) * 1000 * 1000;
|
|
|
|
};
|
2020-11-29 10:55:01 +01:00
|
|
|
|
|
|
|
player.on("quit", function () {
|
|
|
|
app.quit();
|
|
|
|
});
|
|
|
|
} catch (exception) {
|
|
|
|
console.log("player api not working");
|
|
|
|
}
|
|
|
|
}
|
2020-10-04 11:52:08 +02:00
|
|
|
|
2019-10-20 22:47:01 +02:00
|
|
|
addHotKeys();
|
|
|
|
addIPCEventListeners();
|
2022-01-23 10:55:50 +01:00
|
|
|
addFullScreenListeners();
|