From 2dd96dd48e8c134c9d4c8c29fac1bc12d998332e Mon Sep 17 00:00:00 2001 From: Autumn Date: Tue, 30 Jul 2024 21:26:35 +1000 Subject: [PATCH 1/4] Add option to disable the discord rpc idle text --- src/constants/settings.ts | 1 + src/pages/settings/preload.ts | 4 ++++ src/pages/settings/settings.html | 11 +++++++++++ src/scripts/discord.ts | 8 ++++++++ src/scripts/settings.ts | 1 + 5 files changed, 25 insertions(+) diff --git a/src/constants/settings.ts b/src/constants/settings.ts index 73539cf..78fce85 100644 --- a/src/constants/settings.ts +++ b/src/constants/settings.ts @@ -30,6 +30,7 @@ export const settings = { buttonText: "discord.buttonText", includeTimestamps: "discord.includeTimestamps", showSong: "discord.showSong", + showIdle: "discord.showIdle", idleText: "discord.idleText", usingText: "discord.usingText", }, diff --git a/src/pages/settings/preload.ts b/src/pages/settings/preload.ts index 81a537e..498988b 100644 --- a/src/pages/settings/preload.ts +++ b/src/pages/settings/preload.ts @@ -58,6 +58,7 @@ let adBlock: HTMLInputElement, discord_include_timestamps: HTMLInputElement, discord_button_text: HTMLInputElement, discord_show_song: HTMLInputElement, + discord_show_idle: HTMLInputElement, discord_idle_text: HTMLInputElement, discord_using_text: HTMLInputElement; @@ -151,6 +152,7 @@ function refreshSettings() { discord_include_timestamps.checked = settingsStore.get(settings.discord.includeTimestamps); discord_button_text.value = settingsStore.get(settings.discord.buttonText); discord_show_song.checked = settingsStore.get(settings.discord.showSong); + discord_show_idle.checked = settingsStore.get(settings.discord.showIdle); discord_idle_text.value = settingsStore.get(settings.discord.idleText); discord_using_text.value = settingsStore.get(settings.discord.usingText); @@ -269,6 +271,7 @@ window.addEventListener("DOMContentLoaded", () => { listenbrainz_delay = get("listenbrainz_delay"); discord_button_text = get("discord_button_text"); discord_show_song = get("discord_show_song"); + discord_show_idle = get("discord_show_idle"); discord_using_text = get("discord_using_text"); discord_idle_text = get("discord_idle_text"); @@ -312,6 +315,7 @@ window.addEventListener("DOMContentLoaded", () => { settings.discord.showSong, switchesWithSettings.discord_show_song ); + addInputListener(discord_show_idle, settings.discord.showIdle); addInputListener(discord_idle_text, settings.discord.idleText); addInputListener(discord_using_text, settings.discord.usingText); }); diff --git a/src/pages/settings/settings.html b/src/pages/settings/settings.html index 59592b2..2e502a2 100644 --- a/src/pages/settings/settings.html +++ b/src/pages/settings/settings.html @@ -227,6 +227,17 @@

Discord RPC

+
+
+

Show Idle Text

+

Should the idle text be shown when idle?

+
+ +
+

Idle Text

diff --git a/src/scripts/discord.ts b/src/scripts/discord.ts index 8e7c943..0408807 100644 --- a/src/scripts/discord.ts +++ b/src/scripts/discord.ts @@ -14,6 +14,10 @@ export let rpc: Client; const observer = () => { if (rpc) { + const showIdle = settingsStore.get(settings.discord.showIdle) ?? true; + if (mediaInfo.status === MediaStatus.paused && !showIdle) { + rpc.clearActivity(); + } else rpc.setActivity(getActivity()); } }; @@ -90,6 +94,10 @@ export const initRPC = () => { rpc.login({ clientId }).then( () => { rpc.on("ready", () => { + const showIdle = settingsStore.get(settings.discord.showIdle) ?? true; + if (mediaInfo.status === MediaStatus.paused && !showIdle) { + rpc.clearActivity(); + } else rpc.setActivity(getActivity()); }); ipcMain.on(globalEvents.updateInfo, observer); diff --git a/src/scripts/settings.ts b/src/scripts/settings.ts index 4ed3167..0d78af9 100644 --- a/src/scripts/settings.ts +++ b/src/scripts/settings.ts @@ -43,6 +43,7 @@ export const settingsStore = new Store({ enableDiscord: false, discord: { showSong: true, + showIdle: true, idleText: "Browsing Tidal", usingText: "Playing media on TIDAL", includeTimestamps: true, From ffcb563b3512d2328ac18af717d7a5628dfbaf1f Mon Sep 17 00:00:00 2001 From: Will Hurley Date: Thu, 1 Aug 2024 12:10:37 +0100 Subject: [PATCH 2/4] Fix Discord RPC album length < 2 --- src/scripts/discord.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/scripts/discord.ts b/src/scripts/discord.ts index 8e7c943..3e79973 100644 --- a/src/scripts/discord.ts +++ b/src/scripts/discord.ts @@ -60,7 +60,12 @@ const getActivity = (): Presence => { presence.state = mediaInfo.artists ? mediaInfo.artists : "unknown artist(s)"; presence.largeImageKey = mediaInfo.image; if (mediaInfo.album) { - presence.largeImageText = mediaInfo.album; + if (mediaInfo.album.length < 2) { // Fix for DiscordRPC 2 character minimum + presence.largeImageText = mediaInfo.album + " "; + } + else { + presence.largeImageText = mediaInfo.album; + } } presence.buttons = [{ label: buttonText, url: mediaInfo.url }]; } else { From 2c1c76d2d0692a4c4a20cd222362873e0fd3279a Mon Sep 17 00:00:00 2001 From: Rick van Lieshout Date: Sat, 10 Aug 2024 14:20:13 +0200 Subject: [PATCH 3/4] fix: all discord fields are now padded to 2+ chars --- CHANGELOG.md | 5 +++ package-lock.json | 4 +-- package.json | 4 +-- src/pages/settings/settings.html | 4 +-- src/scripts/discord.ts | 59 ++++++++++++++++++++------------ src/scripts/settings.ts | 3 ++ 6 files changed, 51 insertions(+), 28 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 12bc7a3..a15b799 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). +## [5.16.0] + +- Fix issue #449 Discord RPC stuck on "Browsing Tidal". +- Fix issue #448 Add option to disable the discord rpc idle text + ## [5.15.0] - Added all missing swagger/openApi info with the help of [Times-Z](https://github.com/Times-Z) diff --git a/package-lock.json b/package-lock.json index ed9a725..faeb135 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "tidal-hifi", - "version": "5.15.0", + "version": "5.16.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "tidal-hifi", - "version": "5.15.0", + "version": "5.16.0", "license": "MIT", "dependencies": { "@electron/remote": "^2.1.2", diff --git a/package.json b/package.json index b2a06fd..d7878de 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "tidal-hifi", - "version": "5.15.0", + "version": "5.16.0", "description": "Tidal on Electron with widevine(hifi) support", "main": "ts-dist/main.js", "scripts": { @@ -81,4 +81,4 @@ "typescript": "^5.5.3" }, "prettier": "@mastermindzh/prettier-config" -} \ No newline at end of file +} diff --git a/src/pages/settings/settings.html b/src/pages/settings/settings.html index 2e502a2..30e839b 100644 --- a/src/pages/settings/settings.html +++ b/src/pages/settings/settings.html @@ -468,7 +468,7 @@

Upload new themes

TIDAL Hi-Fi

5.15.0 + href="https://github.com/Mastermindzh/tidal-hifi/releases/tag/5.16.0">5.16.0
- \ No newline at end of file + diff --git a/src/scripts/discord.ts b/src/scripts/discord.ts index 991c584..4a162a6 100644 --- a/src/scripts/discord.ts +++ b/src/scripts/discord.ts @@ -14,11 +14,7 @@ export let rpc: Client; const observer = () => { if (rpc) { - const showIdle = settingsStore.get(settings.discord.showIdle) ?? true; - if (mediaInfo.status === MediaStatus.paused && !showIdle) { - rpc.clearActivity(); - } else - rpc.setActivity(getActivity()); + updateActivity(); } }; @@ -28,6 +24,15 @@ const defaultPresence = { instance: false, }; +const updateActivity = () => { + const showIdle = settingsStore.get(settings.discord.showIdle) ?? true; + if (mediaInfo.status === MediaStatus.paused && !showIdle) { + rpc.clearActivity(); + } else { + rpc.setActivity(getActivity()); + } +}; + const getActivity = (): Presence => { const presence: Presence = { ...defaultPresence }; @@ -58,23 +63,33 @@ const getActivity = (): Presence => { return { includeTimestamps, detailsPrefix, buttonText }; } + /** + * Pad a string using spaces to at least 2 characters + * @param input string to pad with 2 characters + * @returns + */ + function pad(input: string): string { + return input.padEnd(2, " "); + } + function setPresenceFromMediaInfo(detailsPrefix: string, buttonText: string) { + // discord requires a minimum of 2 characters + const title = pad(mediaInfo.title); + const album = pad(mediaInfo.album); + const artists = pad(mediaInfo.artists); + if (mediaInfo.url) { - presence.details = `${detailsPrefix}${mediaInfo.title}`; - presence.state = mediaInfo.artists ? mediaInfo.artists : "unknown artist(s)"; + presence.details = `${detailsPrefix}${title}`; + presence.state = artists ? artists : "unknown artist(s)"; presence.largeImageKey = mediaInfo.image; - if (mediaInfo.album) { - if (mediaInfo.album.length < 2) { // Fix for DiscordRPC 2 character minimum - presence.largeImageText = mediaInfo.album + " "; - } - else { - presence.largeImageText = mediaInfo.album; - } + if (album) { + presence.largeImageText = album; } + presence.buttons = [{ label: buttonText, url: mediaInfo.url }]; } else { - presence.details = `Watching ${mediaInfo.title}`; - presence.state = mediaInfo.artists; + presence.details = `Watching ${title}`; + presence.state = artists; } } @@ -99,13 +114,13 @@ export const initRPC = () => { rpc.login({ clientId }).then( () => { rpc.on("ready", () => { - const showIdle = settingsStore.get(settings.discord.showIdle) ?? true; - if (mediaInfo.status === MediaStatus.paused && !showIdle) { - rpc.clearActivity(); - } else - rpc.setActivity(getActivity()); + updateActivity(); + }); + + const { updateInfo, play, pause, playPause } = globalEvents; + [updateInfo, play, pause, playPause].forEach((status) => { + ipcMain.on(status, observer); }); - ipcMain.on(globalEvents.updateInfo, observer); }, () => { Logger.log("Can't connect to Discord, is it running?"); diff --git a/src/scripts/settings.ts b/src/scripts/settings.ts index 0d78af9..4e5323a 100644 --- a/src/scripts/settings.ts +++ b/src/scripts/settings.ts @@ -116,6 +116,9 @@ export const settingsStore = new Store({ { key: settings.advanced.tidalUrl, value: "https://listen.tidal.com" }, ]); }, + "5.16.0": (migrationStore) => { + buildMigration("5.16.0", migrationStore, [{ key: settings.discord.showIdle, value: "true" }]); + }, }, }); From 4f72e1b35df17c10b04e310c2d15d41e2fdca44c Mon Sep 17 00:00:00 2001 From: Rick van Lieshout Date: Sat, 10 Aug 2024 14:46:08 +0200 Subject: [PATCH 4/4] fix: Notifications are now send at the end of the update process, allowing other events to happen sooner. --- CHANGELOG.md | 1 + src/features/api/swagger.json | 2 +- src/preload.ts | 32 ++++++++++++++++++++++---------- 3 files changed, 24 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a15b799..a63b2a7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Fix issue #449 Discord RPC stuck on "Browsing Tidal". - Fix issue #448 Add option to disable the discord rpc idle text +- Notifications are now send at the end of the update process, allowing other events to happen sooner. ## [5.15.0] diff --git a/src/features/api/swagger.json b/src/features/api/swagger.json index 01d3d08..740d696 100644 --- a/src/features/api/swagger.json +++ b/src/features/api/swagger.json @@ -2,7 +2,7 @@ "openapi": "3.1.0", "info": { "title": "TIDAL Hi-Fi API", - "version": "5.15.0", + "version": "5.16.0", "description": "", "license": { "name": "MIT", diff --git a/src/preload.ts b/src/preload.ts index e1661c3..814044b 100644 --- a/src/preload.ts +++ b/src/preload.ts @@ -394,18 +394,30 @@ function updateMediaInfo(mediaInfo: MediaInfo, notify: boolean) { if (mediaInfo) { currentMediaInfo = mediaInfo; ipcRenderer.send(globalEvents.updateInfo, mediaInfo); - if (settingsStore.get(settings.notifications) && notify) { - if (currentNotification) currentNotification.close(); - currentNotification = new Notification({ - title: mediaInfo.title, - body: mediaInfo.artists, - icon: mediaInfo.icon, - }); - currentNotification.show(); - } - updateMpris(mediaInfo); updateListenBrainz(mediaInfo); + if (notify) { + sendNotification(mediaInfo); + } + } +} + +/** + * send a desktop notification if enabled in settings + * @param mediaInfo + * @param notify Whether to notify + */ +async function sendNotification(mediaInfo: MediaInfo) { + if (settingsStore.get(settings.notifications)) { + if (currentNotification) { + currentNotification.close(); + } + currentNotification = new Notification({ + title: mediaInfo.title, + body: mediaInfo.artists, + icon: mediaInfo.icon, + }); + currentNotification.show(); } }