fixed the discord end time stamp issue. fixes #282

This commit is contained in:
Rick van Lieshout 2024-01-07 15:42:00 +01:00
parent 5e82c18d8a
commit 5240f1eeeb
8 changed files with 54 additions and 15 deletions

View File

@ -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.

View File

@ -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 = [];

View File

@ -23,6 +23,7 @@ export const settings = {
discord: {
detailsPrefix: "discord.detailsPrefix",
buttonText: "discord.buttonText",
includeTimestamps: "discord.includeTimestamps",
},
ListenBrainz: {
root: "ListenBrainz",

View File

@ -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);
});

View File

@ -216,6 +216,17 @@
</label>
</div>
<div id="discord_options">
<div class="group__option" class="hidden">
<div class="group__description">
<h4>Include timestamps</h4>
<p>Show current/end playtime in the Discord client</p>
</div>
<label class="switch">
<input id="discord_include_timestamps" type="checkbox" />
<span class="switch__slider"></span>
</label>
</div>
<div class="group__option" class="hidden">
<div class="group__description">
<h4>Details prefix</h4>

View File

@ -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']",

View File

@ -30,30 +30,38 @@ const observer = () => {
settingsStore.get<string, string>(settings.discord.detailsPrefix) ?? "Listening to ";
const buttonText =
settingsStore.get<string, string>(settings.discord.buttonText) ?? "Play on TIDAL";
if (mediaInfo.url) {
rpc.setActivity({
const includeTimestamps =
settingsStore.get<string, boolean>(settings.discord.includeTimestamps) ?? true;
let activity = {
...idleStatus,
...{
startTimestamp: includeTimestamps ? now : undefined,
endTimestamp: includeTimestamps ? remaining : undefined,
},
};
if (mediaInfo.url) {
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);
}
};

View File

@ -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
);
},
},
});