add stats to Connection struct

This commit is contained in:
krolxon 2024-05-10 22:50:44 +05:30
parent 8a5c7877bd
commit 0c8cfe3a9c
2 changed files with 10 additions and 1 deletions

View File

@ -19,6 +19,7 @@ pub struct Connection {
pub repeat: bool, pub repeat: bool,
pub random: bool, pub random: bool,
pub current_song: Song, pub current_song: Song,
pub stats: mpd::Stats,
} }
impl Connection { impl Connection {
@ -43,6 +44,7 @@ impl Connection {
let volume: u8 = status.volume as u8; let volume: u8 = status.volume as u8;
let repeat = status.repeat; let repeat = status.repeat;
let random = status.random; let random = status.random;
let stats = conn.stats().unwrap_or_default();
let current_song = conn let current_song = conn
.currentsong() .currentsong()
@ -58,6 +60,7 @@ impl Connection {
repeat, repeat,
random, random,
current_song, current_song,
stats,
}) })
} }
@ -81,6 +84,7 @@ impl Connection {
.currentsong() .currentsong()
.unwrap_or_else(|_| Some(empty_song.clone())) .unwrap_or_else(|_| Some(empty_song.clone()))
.unwrap_or(empty_song); .unwrap_or(empty_song);
let stats = self.conn.stats().unwrap_or_default();
// Playback State // Playback State
match status.state { match status.state {
@ -103,7 +107,12 @@ impl Connection {
// Random mode // Random mode
self.random = status.random; self.random = status.random;
// Current song
self.current_song = current_song; self.current_song = current_song;
//
self.stats = stats;
} }
/// Get progress ratio of current playing song /// Get progress ratio of current playing song

View File

@ -46,7 +46,7 @@ pub fn render(app: &mut App, frame: &mut Frame) {
/// Draws the directory /// Draws the directory
fn draw_directory_browser(frame: &mut Frame, app: &mut App, size: Rect) { fn draw_directory_browser(frame: &mut Frame, app: &mut App, size: Rect) {
let total_songs = app.conn.conn.stats().unwrap().songs.to_string(); let total_songs = app.conn.stats.songs.to_string();
let rows = app.browser.filetree.iter().enumerate().map(|(i, (t, s))| { let rows = app.browser.filetree.iter().enumerate().map(|(i, (t, s))| {
if t == "file" { if t == "file" {