Updated the discord thing again. this time it's not repeating the position_tx reciever every time

This commit is contained in:
MrDulfin 2025-03-23 23:29:40 -04:00
parent 7a9ee5c22a
commit 41c7820dfb

View file

@ -198,7 +198,6 @@ fn discord_rpc(client_id: u64, song_tx: Receiver<Song>, state_tx: Receiver<Prism
.duration_since(UNIX_EPOCH) .duration_since(UNIX_EPOCH)
.expect("Time went backwards?") .expect("Time went backwards?")
.as_secs(); .as_secs();
let mut tick = Instant::now();
DC_ACTIVE.store(true, Ordering::Relaxed); 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(); 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)) => {} 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 client
.set_activity(|activity| { .set_activity(|activity| {
let activity = activity let activity = activity