From 5eb3b8d95fe5df2020f2c1dce4c943b2349d9cc4 Mon Sep 17 00:00:00 2001 From: Mastermindzh Date: Mon, 19 Apr 2021 21:31:12 +0200 Subject: [PATCH 1/3] released version 2.1.0 on the AUR version as well. --- build/linux/arch/.SRCINFO | 6 +++--- build/linux/arch/PKGBUILD | 6 ++---- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/build/linux/arch/.SRCINFO b/build/linux/arch/.SRCINFO index 2218488..6ab8bf3 100644 --- a/build/linux/arch/.SRCINFO +++ b/build/linux/arch/.SRCINFO @@ -1,6 +1,6 @@ pkgbase = tidal-hifi-git pkgdesc = The web version of listen.tidal.com running in electron with hifi support thanks to widevine. - pkgver = 2.0.0 + pkgver = 2.1.0 pkgrel = 1 url = https://github.com/Mastermindzh/tidal-hifi arch = x86_64 @@ -11,9 +11,9 @@ pkgbase = tidal-hifi-git depends = nss depends = gtk3 provides = tidal-hifi - source = https://github.com/Mastermindzh/tidal-hifi/archive/2.0.0.zip + source = https://github.com/Mastermindzh/tidal-hifi/archive/2.1.0.zip source = tidal-hifi.desktop - sha512sums = 68fce020128b637fd37383a5afae71d2e4f3eec2d6b4bfcd7f410dcec18c91327d163deb21750e2251967a31f83b2b16092d11d3ff500a1fecd8c595448f380e + sha512sums = 30b50243e7033219351f7d7f318757e4590e5c78a7031762cf846ae3652b424ab3f54388cba44209e49434d8534edb198e1c65d0b53450b4367636ef0f4653e0 sha512sums = 35f38ac308b871c1822d7f6f760f2fb54c3748cf769822cb0f0dfb90f0f5754ba9316da5e903a0d2e9839de3a43ec76f238f3f2e44021956fa1da19142081349 pkgname = tidal-hifi-git diff --git a/build/linux/arch/PKGBUILD b/build/linux/arch/PKGBUILD index 8fe6a53..bccc869 100644 --- a/build/linux/arch/PKGBUILD +++ b/build/linux/arch/PKGBUILD @@ -2,7 +2,7 @@ _pkgname=tidal-hifi pkgname="$_pkgname-git" -pkgver=2.0.0 +pkgver=2.1.0 pkgrel=1 pkgdesc="The web version of listen.tidal.com running in electron with hifi support thanks to widevine." arch=("x86_64") @@ -15,11 +15,9 @@ provides=("$_pkgname") source=("https://github.com/Mastermindzh/tidal-hifi/archive/$pkgver.zip" "${_pkgname}.desktop") -sha512sums=('68fce020128b637fd37383a5afae71d2e4f3eec2d6b4bfcd7f410dcec18c91327d163deb21750e2251967a31f83b2b16092d11d3ff500a1fecd8c595448f380e' +sha512sums=('30b50243e7033219351f7d7f318757e4590e5c78a7031762cf846ae3652b424ab3f54388cba44209e49434d8534edb198e1c65d0b53450b4367636ef0f4653e0' '35f38ac308b871c1822d7f6f760f2fb54c3748cf769822cb0f0dfb90f0f5754ba9316da5e903a0d2e9839de3a43ec76f238f3f2e44021956fa1da19142081349') - - cdToPkg(){ cd "tidal-hifi-$pkgver" } From ae51f9610ca014699bc70884253c2b6a70c8e398 Mon Sep 17 00:00:00 2001 From: Mastermindzh Date: Mon, 19 Apr 2021 23:08:19 +0200 Subject: [PATCH 2/3] - The discord integration now doesn't send an update every 15 seconds it sends an update whenever the media info changes - consolidated updating the media info changes with the status changes into a single global event --- CHANGELOG.md | 5 ++ package.json | 2 +- src/constants/globalEvents.js | 1 - src/main.js | 9 +-- src/preload.js | 112 ++++++++++++++++++---------------- src/scripts/discord.js | 83 +++++++++++++------------ src/scripts/mediaInfo.js | 14 +---- 7 files changed, 116 insertions(+), 110 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 30dfac4..1bec63d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,11 @@ 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). +## 2.1.1 + +- The discord integration now doesn't send an update every 15 seconds it sends an update whenever the media info changes +- consolidated updating the media info changes with the status changes into a single global event + ## 2.1.0 - [Mar0xy](https://github.com/Mar0xy) added Discord integration. diff --git a/package.json b/package.json index 0b8db6e..f4ba291 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "tidal-hifi", - "version": "2.1.0", + "version": "2.1.1", "description": "Tidal on Electron with widevine(hifi) support", "main": "src/main.js", "scripts": { diff --git a/src/constants/globalEvents.js b/src/constants/globalEvents.js index 191fd12..22f47d4 100644 --- a/src/constants/globalEvents.js +++ b/src/constants/globalEvents.js @@ -7,7 +7,6 @@ const globalEvents = { updateInfo: "update-info", hideSettings: "hideSettings", showSettings: "showSettings", - updateStatus: "update-status", storeChanged: "storeChanged", error: "error", }; diff --git a/src/main.js b/src/main.js index 28ca3c7..45f61f0 100644 --- a/src/main.js +++ b/src/main.js @@ -17,7 +17,6 @@ const mediaInfoModule = require("./scripts/mediaInfo"); const discordModule = require("./scripts/discord"); const globalEvents = require("./constants/globalEvents"); - let mainWindow; let icon = path.join(__dirname, "../assets/icon.png"); @@ -98,7 +97,6 @@ app.on("activate", function () { }); // IPC - ipcMain.on(globalEvents.updateInfo, (event, arg) => { mediaInfoModule.update(arg); }); @@ -110,15 +108,12 @@ ipcMain.on(globalEvents.showSettings, (event, arg) => { showSettingsWindow(); }); -ipcMain.on(globalEvents.updateStatus, (event, arg) => { - mediaInfoModule.updateStatus(arg); -}); ipcMain.on(globalEvents.storeChanged, (event, arg) => { mainWindow.setMenuBarVisibility(store.get(settings.menuBar)); - if(store.get(settings.enableDiscord) && !discordModule.rpc) { + if (store.get(settings.enableDiscord) && !discordModule.rpc) { discordModule.initRPC(); - } else if(!store.get(settings.enableDiscord) && discordModule.rpc) { + } else if (!store.get(settings.enableDiscord) && discordModule.rpc) { discordModule.unRPC(); } }); diff --git a/src/preload.js b/src/preload.js index d2a5c8c..10ad1be 100644 --- a/src/preload.js +++ b/src/preload.js @@ -1,4 +1,4 @@ -const { setTitle, getTitle } = require("./scripts/window-functions"); +const { setTitle } = require("./scripts/window-functions"); const { dialog, process } = require("electron").remote; const { store, settings } = require("./scripts/settings"); const { ipcRenderer } = require("electron"); @@ -11,6 +11,7 @@ const notifier = require("node-notifier"); const notificationPath = `${app.getPath("userData")}/notification.jpg`; let currentSong = ""; let player; +let currentPlayStatus = statuses.paused; const elements = { play: '*[data-test="play"]', @@ -18,7 +19,7 @@ const elements = { next: '*[data-test="next"]', previous: 'button[data-test="previous"]', title: '*[data-test^="footer-track-title"]', - artists: '*[class^="css-14o5h2y"]', + artists: '*[data-test^="grid-item-detail-text-title-artist"]', home: '*[data-test="menu--home"]', back: '[class^="backwardButton"]', forward: '[class^="forwardButton"]', @@ -200,9 +201,9 @@ function addIPCEventListeners() { /** * Update the current status of tidal (e.g playing or paused) */ -function updateStatus() { +function getCurrentlyPlayingStatus() { let pause = elements.get("pause"); - let status; + let status = undefined; // if pause button is visible tidal is playing if (pause) { @@ -210,11 +211,29 @@ function updateStatus() { } else { status = statuses.paused; } + return status; +} + +/** + * Update Tidal-hifi's media info + * + * @param {*} options + */ +function updateMediaInfo(options, notify) { + if (options) { + ipcRenderer.send(globalEvents.updateInfo, options); + store.get(settings.notifications) && notify && notifier.notify(options); - if (status) { - ipcRenderer.send(globalEvents.updateStatus, status); if (player) { - player.playbackStatus = status == statuses.paused ? "Paused" : "Playing"; + player.metadata = { + ...player.metadata, + ...{ + "xesam:title": options.title, + "xesam:artist": [options.artists], + "mpris:artUrl": options.image, + }, + }; + player.playbackStatus = options.status == statuses.paused ? "Paused" : "Playing"; } } } @@ -227,56 +246,47 @@ setInterval(function () { const url = elements.get("url").href.replace(/[^0-9]/g, ""); const artists = elements.getText("artists"); const songDashArtistTitle = `${title} - ${artists}`; + const currentStatus = getCurrentlyPlayingStatus(); + const options = { + title, + message: artists, + status: currentStatus, + url: `https://tidal.com/browse/track/${url}`, + }; - updateStatus(); + const playStatusChanged = currentStatus !== currentPlayStatus; + const titleOrArtistChanged = currentSong !== songDashArtistTitle; - if (getTitle() !== songDashArtistTitle) { + if (titleOrArtistChanged || playStatusChanged) { + // update title and play info with new info setTitle(songDashArtistTitle); + currentSong = songDashArtistTitle; + currentPlayStatus = currentStatus; - if (currentSong !== songDashArtistTitle) { - currentSong = songDashArtistTitle; - const image = elements.getSongIcon(); + const image = elements.getSongIcon(); - const options = { - title, - message: artists, - url: `https://tidal.com/browse/track/${url}`, - }; - new Promise((resolve, reject) => { - if (image.startsWith("http")) { - 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(); - } - }).then( - () => { - ipcRenderer.send(globalEvents.updateInfo, options); - store.get(settings.notifications) && notifier.notify(options); - - if (player) { - player.metadata = { - ...player.metadata, - ...{ - "xesam:title": title, - "xesam:artist": [artists], - "mpris:artUrl": image, - }, - }; + new Promise((resolve) => { + if (image.startsWith("http")) { + 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(); + } + }).then( + () => { + updateMediaInfo(options, titleOrArtistChanged); + }, + () => {} + ); } }, 200); diff --git a/src/scripts/discord.js b/src/scripts/discord.js index cee1485..628d821 100644 --- a/src/scripts/discord.js +++ b/src/scripts/discord.js @@ -1,52 +1,57 @@ const discordrpc = require("discord-rpc"); -const clientId = '833617820704440341'; +const { ipcMain } = require("electron"); +const electron = require("electron"); +const globalEvents = require("../constants/globalEvents"); +const clientId = "833617820704440341"; const mediaInfoModule = require("./mediaInfo"); - const discordModule = []; -let discord; let rpc; +const observer = (event, arg) => { + if (mediaInfoModule.mediaInfo.status == "paused" && rpc) { + rpc.setActivity(idleStatus); + } else if (rpc) { + rpc.setActivity({ + ...idleStatus, + ...{ + details: `Listening to ${mediaInfoModule.mediaInfo.title}`, + state: mediaInfoModule.mediaInfo.artist, + buttons: [{ label: "Play on Tidal", url: mediaInfoModule.mediaInfo.url }], + }, + }); + } +}; const idleStatus = { - details: `Browsing Tidal`, - largeImageKey: 'tidal-hifi-icon', - largeImageText: 'Tidal HiFi 2.0.0', - instance: false, -} + details: `Browsing Tidal`, + largeImageKey: "tidal-hifi-icon", + largeImageText: `Tidal HiFi ${electron.app.getVersion()}`, + instance: false, +}; +/** + * Set up the discord rpc and listen on globalEvents.updateInfo + */ discordModule.initRPC = function () { - rpc = new discordrpc.Client({ transport: 'ipc' }); - rpc.login({ clientId }).catch(console.error); - discordModule.rpc = rpc; + rpc = new discordrpc.Client({ transport: "ipc" }); + rpc.login({ clientId }).catch(console.error); + discordModule.rpc = rpc; - rpc.on('ready', () => { - rpc.setActivity(idleStatus); - }) - - discord = setInterval(() => { - if (mediaInfoModule.mediaInfo.status == 'paused' && rpc) { - rpc.setActivity(idleStatus); - } else if (rpc) { - rpc.setActivity({ - details: `Listening to ${mediaInfoModule.mediaInfo.title}`, - state: mediaInfoModule.mediaInfo.artist, - largeImageKey: 'tidal-hifi-icon', - largeImageText: 'Tidal HiFi 2.0.0', - buttons: [ - { label: "Play on Tidal", url: mediaInfoModule.mediaInfo.url } - ], - instance: false, - }); - } - }, 15e3); -} + rpc.on("ready", () => { + rpc.setActivity(idleStatus); + }); + ipcMain.on(globalEvents.updateInfo, observer); +}; +/** + * Remove any RPC connection with discord and remove the event listener on globalEvents.updateInfo + */ discordModule.unRPC = function () { - clearInterval(discord); - rpc.clearActivity(); - rpc.destroy(); - rpc = false; - discordModule.rpc = rpc; -} + rpc.clearActivity(); + rpc.destroy(); + rpc = false; + discordModule.rpc = rpc; + ipcMain.removeListener(globalEvents.updateInfo, observer); +}; -module.exports = discordModule; \ No newline at end of file +module.exports = discordModule; diff --git a/src/scripts/mediaInfo.js b/src/scripts/mediaInfo.js index 9641e14..e7d7f62 100644 --- a/src/scripts/mediaInfo.js +++ b/src/scripts/mediaInfo.js @@ -5,7 +5,7 @@ const mediaInfo = { artist: "", icon: "", status: statuses.paused, - url: "" + url: "", }; const mediaInfoModule = { mediaInfo, @@ -14,20 +14,12 @@ const mediaInfoModule = { /** * Update artist and song info in the mediaInfo constant */ -mediaInfoModule.update = function(arg) { +mediaInfoModule.update = function (arg) { mediaInfo.title = propOrDefault(arg.title); mediaInfo.artist = propOrDefault(arg.message); mediaInfo.icon = propOrDefault(arg.icon); mediaInfo.url = propOrDefault(arg.url); -}; - -/** - * Update tidal's status in the mediaInfo constant - */ -mediaInfoModule.updateStatus = function(status) { - if (Object.values(statuses).includes(status)) { - mediaInfo.status = status; - } + mediaInfo.status = propOrDefault(arg.status); }; /** From 4fe42a36719b8982ac17a92573252652f5ae388d Mon Sep 17 00:00:00 2001 From: Mastermindzh Date: Mon, 19 Apr 2021 23:39:46 +0200 Subject: [PATCH 3/3] update aur version files --- build/linux/arch/.SRCINFO | 6 +++--- build/linux/arch/PKGBUILD | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/build/linux/arch/.SRCINFO b/build/linux/arch/.SRCINFO index 6ab8bf3..1483db7 100644 --- a/build/linux/arch/.SRCINFO +++ b/build/linux/arch/.SRCINFO @@ -1,6 +1,6 @@ pkgbase = tidal-hifi-git pkgdesc = The web version of listen.tidal.com running in electron with hifi support thanks to widevine. - pkgver = 2.1.0 + pkgver = 2.1.1 pkgrel = 1 url = https://github.com/Mastermindzh/tidal-hifi arch = x86_64 @@ -11,9 +11,9 @@ pkgbase = tidal-hifi-git depends = nss depends = gtk3 provides = tidal-hifi - source = https://github.com/Mastermindzh/tidal-hifi/archive/2.1.0.zip + source = https://github.com/Mastermindzh/tidal-hifi/archive/2.1.1.zip source = tidal-hifi.desktop - sha512sums = 30b50243e7033219351f7d7f318757e4590e5c78a7031762cf846ae3652b424ab3f54388cba44209e49434d8534edb198e1c65d0b53450b4367636ef0f4653e0 + sha512sums = 510c94d9db8573103ee900dcd75b0416ea06ea62af7ed21818d2a5a77ab009a2737c852e7e20b97f846e14b07754a9e5a36ac5b9d0cd0a2a8d0aff3bbc75e622 sha512sums = 35f38ac308b871c1822d7f6f760f2fb54c3748cf769822cb0f0dfb90f0f5754ba9316da5e903a0d2e9839de3a43ec76f238f3f2e44021956fa1da19142081349 pkgname = tidal-hifi-git diff --git a/build/linux/arch/PKGBUILD b/build/linux/arch/PKGBUILD index bccc869..0853b98 100644 --- a/build/linux/arch/PKGBUILD +++ b/build/linux/arch/PKGBUILD @@ -2,7 +2,7 @@ _pkgname=tidal-hifi pkgname="$_pkgname-git" -pkgver=2.1.0 +pkgver=2.1.1 pkgrel=1 pkgdesc="The web version of listen.tidal.com running in electron with hifi support thanks to widevine." arch=("x86_64") @@ -15,7 +15,7 @@ provides=("$_pkgname") source=("https://github.com/Mastermindzh/tidal-hifi/archive/$pkgver.zip" "${_pkgname}.desktop") -sha512sums=('30b50243e7033219351f7d7f318757e4590e5c78a7031762cf846ae3652b424ab3f54388cba44209e49434d8534edb198e1c65d0b53450b4367636ef0f4653e0' +sha512sums=('510c94d9db8573103ee900dcd75b0416ea06ea62af7ed21818d2a5a77ab009a2737c852e7e20b97f846e14b07754a9e5a36ac5b9d0cd0a2a8d0aff3bbc75e622' '35f38ac308b871c1822d7f6f760f2fb54c3748cf769822cb0f0dfb90f0f5754ba9316da5e903a0d2e9839de3a43ec76f238f3f2e44021956fa1da19142081349') cdToPkg(){