From 41c7820dfb8e6bad02d1e5ae948c4335a2a5fa20 Mon Sep 17 00:00:00 2001
From: MrDulfin <mrdulfin@dangoware.org>
Date: Sun, 23 Mar 2025 23:29:40 -0400
Subject: [PATCH] Updated the discord thing again. this time it's not repeating
 the position_tx reciever every time

---
 dmp-core/src/music_controller/connections.rs | 23 +++++++-------------
 1 file changed, 8 insertions(+), 15 deletions(-)

diff --git a/dmp-core/src/music_controller/connections.rs b/dmp-core/src/music_controller/connections.rs
index 438f70a..0c3abfb 100644
--- a/dmp-core/src/music_controller/connections.rs
+++ b/dmp-core/src/music_controller/connections.rs
@@ -198,7 +198,6 @@ fn discord_rpc(client_id: u64, song_tx: Receiver<Song>, state_tx: Receiver<Prism
         .duration_since(UNIX_EPOCH)
         .expect("Time went backwards?")
         .as_secs();
-    let mut tick = Instant::now();
 
     DC_ACTIVE.store(true, Ordering::Relaxed);
 
@@ -218,23 +217,17 @@ fn discord_rpc(client_id: u64, song_tx: Receiver<Song>, state_tx: Receiver<Prism
                     now = SystemTime::now().duration_since(UNIX_EPOCH).expect("Time went backwards?").as_secs();
                 }
             },
-            recv(position_tx) -> pos => {
-                let elapsed = tick.elapsed().as_secs();
-                if elapsed >= 5 {
-                    if let Ok(Some(pos)) = pos {
-                        // set back the start position to where it would be if it hadn't been paused / seeked
-                        now = SystemTime::now()
-                        .duration_since(UNIX_EPOCH)
-                        .expect("Time went backwards?")
-                        .as_secs() - u64::try_from(pos.num_seconds()).unwrap() - 1;
-                        tick = Instant::now();
-                    }
-                }
-
-            }
             default(Duration::from_millis(1000)) => {}
         }
 
+        if let Ok(Some(pos)) = position_tx.recv_timeout(Duration::from_millis(100)) {
+            // set back the start position to where it would be if it hadn't been paused / seeked
+            now = SystemTime::now()
+            .duration_since(UNIX_EPOCH)
+            .expect("Time went backwards?")
+            .as_secs() - u64::try_from(pos.num_seconds()).unwrap();
+        }
+
         client
             .set_activity(|activity| {
                 let activity = activity