From 5240f1eeeb5541cf0a05b37b32885a95d61665f0 Mon Sep 17 00:00:00 2001 From: Rick van Lieshout Date: Sun, 7 Jan 2024 15:42:00 +0100 Subject: [PATCH] fixed the discord end time stamp issue. fixes #282 --- CHANGELOG.md | 9 +++++++-- scripts/verifyElements.js | 6 ++++-- src/constants/settings.ts | 1 + src/pages/settings/preload.ts | 4 ++++ src/pages/settings/settings.html | 11 +++++++++++ src/preload.ts | 2 +- src/scripts/discord.ts | 28 ++++++++++++++++++---------- src/scripts/settings.ts | 8 ++++++++ 8 files changed, 54 insertions(+), 15 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9876797..248b23d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,15 +6,20 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [5.8.0] -- Updated Electron to 28.1.1 for issue [325](https://github.com/Mastermindzh/tidal-hifi/issues/325) +- 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 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` +- Fixed wrong "end time stamp" for currently playing song (fixes [#282](https://github.com/Mastermindzh/tidal-hifi/issues/282)) + - Affected the API + all integrations + - As requested we also added toggle to sync the timestamps to Discord (default = true) + ## [5.7.1] - Fixed mpris not being set up correctly due to capitalization of the instance name. diff --git a/scripts/verifyElements.js b/scripts/verifyElements.js index bc24cac..fc96477 100644 --- a/scripts/verifyElements.js +++ b/scripts/verifyElements.js @@ -16,11 +16,12 @@ search: '[class^="searchField"]', shuffle: '*[data-test="shuffle"]', repeat: '*[data-test="repeat"]', - account: '*[data-test^="profile-image-button"]', + account: '*[class^="profileOptions"]', + settings: '*[data-test^="open-settings"]', media: '*[data-test="current-media-imagery"]', image: "img", current: '*[data-test="current-time"]', - duration: '*[data-test="duration"]', + duration: '*[class^=playbackControlsContainer] *[data-test="duration"]', bar: '*[data-test="progress-bar"]', footer: "#footerPlayer", mediaItem: "[data-type='mediaItem']", @@ -29,6 +30,7 @@ album_name_cell: '[class^="album"]', tracklist_row: '[data-test="tracklist-row"]', volume: '*[data-test="volume"]', + favorite: '*[data-test="footer-favorite-button"]', }; let results = []; diff --git a/src/constants/settings.ts b/src/constants/settings.ts index 70ea358..8750dad 100644 --- a/src/constants/settings.ts +++ b/src/constants/settings.ts @@ -23,6 +23,7 @@ export const settings = { discord: { detailsPrefix: "discord.detailsPrefix", buttonText: "discord.buttonText", + includeTimestamps: "discord.includeTimestamps", }, ListenBrainz: { root: "ListenBrainz", diff --git a/src/pages/settings/preload.ts b/src/pages/settings/preload.ts index f078006..7898a3d 100644 --- a/src/pages/settings/preload.ts +++ b/src/pages/settings/preload.ts @@ -48,6 +48,7 @@ let adBlock: HTMLInputElement, listenbrainz_delay: HTMLInputElement, enableWaylandSupport: HTMLInputElement, discord_details_prefix: HTMLInputElement, + discord_include_timestamps: HTMLInputElement, discord_button_text: HTMLInputElement; addCustomCss(app); @@ -135,6 +136,7 @@ function refreshSettings() { ListenBrainzToken.value = settingsStore.get(settings.ListenBrainz.token); listenbrainz_delay.value = settingsStore.get(settings.ListenBrainz.delay); discord_details_prefix.value = settingsStore.get(settings.discord.detailsPrefix); + discord_include_timestamps.checked = settingsStore.get(settings.discord.includeTimestamps); discord_button_text.value = settingsStore.get(settings.discord.buttonText); // set state of all switches with additional settings @@ -246,6 +248,7 @@ window.addEventListener("DOMContentLoaded", () => { ListenBrainzAPI = get("ListenBrainzAPI"); ListenBrainzToken = get("ListenBrainzToken"); discord_details_prefix = get("discord_details_prefix"); + discord_include_timestamps = get("discord_include_timestamps"); listenbrainz_delay = get("listenbrainz_delay"); discord_button_text = get("discord_button_text"); @@ -280,5 +283,6 @@ window.addEventListener("DOMContentLoaded", () => { addInputListener(ListenBrainzToken, settings.ListenBrainz.token); addInputListener(listenbrainz_delay, settings.ListenBrainz.delay); addInputListener(discord_details_prefix, settings.discord.detailsPrefix); + addInputListener(discord_include_timestamps, settings.discord.includeTimestamps); addInputListener(discord_button_text, settings.discord.buttonText); }); diff --git a/src/pages/settings/settings.html b/src/pages/settings/settings.html index facd174..b250a89 100644 --- a/src/pages/settings/settings.html +++ b/src/pages/settings/settings.html @@ -216,6 +216,17 @@
+
+
+

Include timestamps

+

Show current/end playtime in the Discord client

+
+ +
+

Details prefix

diff --git a/src/preload.ts b/src/preload.ts index aa846a1..e186fa9 100644 --- a/src/preload.ts +++ b/src/preload.ts @@ -45,7 +45,7 @@ const elements = { media: '*[data-test="current-media-imagery"]', image: "img", current: '*[data-test="current-time"]', - duration: '*[data-test="duration"]', + duration: '*[class^=playbackControlsContainer] *[data-test="duration"]', bar: '*[data-test="progress-bar"]', footer: "#footerPlayer", mediaItem: "[data-type='mediaItem']", diff --git a/src/scripts/discord.ts b/src/scripts/discord.ts index 6e87657..31088c7 100644 --- a/src/scripts/discord.ts +++ b/src/scripts/discord.ts @@ -30,30 +30,38 @@ const observer = () => { settingsStore.get(settings.discord.detailsPrefix) ?? "Listening to "; const buttonText = settingsStore.get(settings.discord.buttonText) ?? "Play on TIDAL"; + const includeTimestamps = + settingsStore.get(settings.discord.includeTimestamps) ?? true; + + let activity = { + ...idleStatus, + ...{ + startTimestamp: includeTimestamps ? now : undefined, + endTimestamp: includeTimestamps ? remaining : undefined, + }, + }; if (mediaInfo.url) { - rpc.setActivity({ - ...idleStatus, + activity = { + ...activity, ...{ details: `${detailsPrefix}${mediaInfo.title}`, state: mediaInfo.artists ? mediaInfo.artists : "unknown artist(s)", - startTimestamp: now, - endTimestamp: remaining, largeImageKey: mediaInfo.image, largeImageText: mediaInfo.album ? mediaInfo.album : `${idleStatus.largeImageText}`, buttons: [{ label: buttonText, url: mediaInfo.url }], }, - }); + }; } else { - rpc.setActivity({ - ...idleStatus, + activity = { + ...activity, ...{ details: `Watching ${mediaInfo.title}`, state: mediaInfo.artists, - startTimestamp: now, - endTimestamp: remaining, }, - }); + }; } + + rpc.setActivity(activity); } }; diff --git a/src/scripts/settings.ts b/src/scripts/settings.ts index 0a18c32..10e08bc 100644 --- a/src/scripts/settings.ts +++ b/src/scripts/settings.ts @@ -21,6 +21,7 @@ export const settingsStore = new Store({ discord: { detailsPrefix: "Listening to ", buttonText: "Play on Tidal", + includeTimestamps: true, }, ListenBrainz: { enabled: false, @@ -61,6 +62,13 @@ export const settingsStore = new Store({ migrationStore.get(settings.ListenBrainz.delay) ?? 5000 ); }, + "5.8.0": (migrationStore) => { + console.log("running migrations for 5.8.0"); + migrationStore.set( + settings.discord.includeTimestamps, + migrationStore.get(settings.discord.includeTimestamps) ?? true + ); + }, }, });