Krolyxon
Commit 3f6b2bf

rmptui3f6b2bf

Fix wrong songs playing when queue is not empty if we are playing a song which is in the middle of somewhere in queue. it will play the wrong song, since the index points to wrong song

Author
krolxon
Date
2024-04-24 12:52 +0530
Parent
bf11d59
Commit
3f6b2bfefd54a53e675e0cffc98b704d3b8ad244

+8 −7

3 files changed

  1. M src/app.rs +3 −5
  2. M src/connection.rs +2 −1
  3. M src/list.rs +3 −1
M src/app.rs View
@@ -12,7 +12,6 @@ pub struct App {
1212 /// check if app is running
1313 pub running: bool,
1414 pub conn: Connection,
15− pub play_deque: ContentList<String>,
1615 pub song_list: ContentList<String>,
1716 pub queue_list: ContentList<String>,
1817 pub pl_list: ContentList<String>,
@@ -21,11 +20,11 @@ pub struct App {
2120 impl App {
2221 pub fn builder(addrs: &str) -> AppResult<Self> {
2322 let mut conn = Connection::new(addrs).unwrap();
24− let mut queue = ContentList::new();
23+ let mut queue_list = ContentList::new();
2524 let mut pl_list = ContentList::new();
2625 pl_list.list = Self::get_playlist(&mut conn.conn)?;
2726
28− Self::get_queue(&mut conn, &mut queue.list);
27+ Self::get_queue(&mut conn, &mut queue_list.list);
2928
3029 let mut song_list = ContentList::new();
3130 song_list.list = conn.songs_filenames.clone();
@@ -33,9 +32,8 @@ impl App {
3332 Ok(Self {
3433 running: true,
3534 conn,
36− play_deque: ContentList::new(),
3735 song_list,
38− queue_list: ContentList::new(),
36+ queue_list,
3937 pl_list,
4038 })
4139 }
M src/connection.rs View
@@ -70,10 +70,11 @@ impl Connection {
7070 self.conn.play().unwrap();
7171 } else {
7272 self.conn.push(song)?;
73+ let len: u32 = (self.conn.queue().unwrap().len() - 1).try_into().unwrap();
74+ self.conn.switch(len)?;
7375 if self.conn.status()?.state == State::Stop {
7476 self.conn.play()?;
7577 }
76− self.conn.next().unwrap();
7778 }
7879
7980 Ok(())
M src/list.rs View
@@ -27,7 +27,9 @@ impl<T> ContentList<T> {
2727
2828 /// Go to previous item in list
2929 pub fn prev(&mut self) {
30− if self.index != 0 {
30+ if self.index == 0 {
31+ self.index = self.list.len() - 1;
32+ } else {
3133 self.index -= 1;
3234 }
3335 }