Skip to content

Commit

Permalink
DiscordRPC: Fix timestamps
Browse files Browse the repository at this point in the history
  • Loading branch information
n1ckoates committed Sep 15, 2024
1 parent aad737e commit 26bac42
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions plugins/DiscordRPC/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,11 @@ export const onTimeUpdate = async (currentTime?: number) => {
} else {
// Playback/Time
if (mediaItem.duration !== undefined && currentTime !== undefined) {
const newStartTime = Math.floor(Date.now() / 1000);
const newEndTime = Math.floor((Date.now() + (mediaItem.duration - currentTime) * 1000) / 1000);
const newStartTime = Date.now() - currentTime * 1000;
const newEndTime = newStartTime + mediaItem.duration * 1000;

// Use old timestamps if the difference is less than 100ms, to prevent unnecessary updates
if (newEndTime - previousEndTime < 100) {
if (newEndTime - previousEndTime < 100 && newStartTime - previousStartTime < 100) {
activity.startTimestamp = previousStartTime;
activity.endTimestamp = previousEndTime;
} else {
Expand Down

0 comments on commit 26bac42

Please sign in to comment.