diff options
| author | krolxon <krolyxon@tutanota.com> | 2024-05-12 20:37:32 +0530 |
|---|---|---|
| committer | krolxon <krolyxon@tutanota.com> | 2024-05-12 20:37:32 +0530 |
| commit | 98cfe4eb264efd575ba0eaab7e6debe8ef8d40af (patch) | |
| tree | 8a1d1be3927308ffb95127300742289c06bd06a5 /src/event/handler.rs | |
| parent | 8c4d19f84961bba2f34726e491daf2fa2d981e1d (diff) | |
fix #3
Diffstat (limited to 'src/event/handler.rs')
| -rwxr-xr-x | src/event/handler.rs | 30 |
1 files changed, 19 insertions, 11 deletions
diff --git a/src/event/handler.rs b/src/event/handler.rs index 1d54f4b..9d54ea9 100755 --- a/src/event/handler.rs +++ b/src/event/handler.rs @@ -58,18 +58,24 @@ pub fn handle_key_events(key_event: KeyEvent, app: &mut App) -> AppResult<()> { // Fast forward KeyCode::Char('f') => { - let place = app.conn.conn.status().unwrap().song.unwrap().pos; - let (pos, _) = app.conn.conn.status().unwrap().time.unwrap(); - let pos = Duration::from_secs(pos.as_secs().wrapping_add(2)); - app.conn.conn.seek(place, pos)?; + if !app.queue_list.list.is_empty() { + let status = app.conn.conn.status().unwrap_or_default(); + let place = status.song.unwrap_or_default().pos; + let (pos, _) = status.time.unwrap_or_default(); + let pos = Duration::from_secs(pos.as_secs().wrapping_add(2)); + app.conn.conn.seek(place, pos)?; + } } // backward KeyCode::Char('b') => { - let place = app.conn.conn.status().unwrap().song.unwrap().pos; - let (pos, _) = app.conn.conn.status().unwrap().time.unwrap(); - let pos = Duration::from_secs(pos.as_secs().wrapping_add(2)); - app.conn.conn.seek(place, pos)?; + if !app.queue_list.list.is_empty() { + let status = app.conn.conn.status().unwrap_or_default(); + let place = status.song.unwrap_or_default().pos; + let (pos, _) = status.time.unwrap_or_default(); + let pos = Duration::from_secs(pos.as_secs().wrapping_sub(2)); + app.conn.conn.seek(place, pos)?; + } } // Cycle through tabs @@ -267,9 +273,11 @@ pub fn handle_key_events(key_event: KeyEvent, app: &mut App) -> AppResult<()> { // add to current playlist KeyCode::Enter | KeyCode::Char('l') | KeyCode::Right | KeyCode::Char(' ') => { // app.update_queue(); - app.conn - .load_playlist(app.pl_list.list.get(app.pl_list.index).unwrap())?; - app.conn.update_status(); + if !app.pl_list.list.is_empty() { + app.conn + .load_playlist(app.pl_list.list.get(app.pl_list.index).unwrap())?; + app.conn.update_status(); + } } _ => {} } |
