Krolyxon
Commit 0c8cfe3

rmptui0c8cfe3

add stats to Connection struct

Author
krolxon
Date
2024-05-10 22:50 +0530
Parent
8a5c787
Commit
0c8cfe3a9cf727d670550e4ed1ec65b60e6e6e35

+10 −1

2 files changed

  1. M src/connection.rs +9 −0
  2. M src/ui.rs +1 −1
M src/connection.rs View
@@ -19,6 +19,7 @@ pub struct Connection {
1919 pub repeat: bool,
2020 pub random: bool,
2121 pub current_song: Song,
22+ pub stats: mpd::Stats,
2223 }
2324
2425 impl Connection {
@@ -43,6 +44,7 @@ impl Connection {
4344 let volume: u8 = status.volume as u8;
4445 let repeat = status.repeat;
4546 let random = status.random;
47+ let stats = conn.stats().unwrap_or_default();
4648
4749 let current_song = conn
4850 .currentsong()
@@ -58,6 +60,7 @@ impl Connection {
5860 repeat,
5961 random,
6062 current_song,
63+ stats,
6164 })
6265 }
6366
@@ -81,6 +84,7 @@ impl Connection {
8184 .currentsong()
8285 .unwrap_or_else(|_| Some(empty_song.clone()))
8386 .unwrap_or(empty_song);
87+ let stats = self.conn.stats().unwrap_or_default();
8488
8589 // Playback State
8690 match status.state {
@@ -103,7 +107,12 @@ impl Connection {
103107 // Random mode
104108 self.random = status.random;
105109
110+ // Current song
106111 self.current_song = current_song;
112+
113+ //
114+
115+ self.stats = stats;
107116 }
108117
109118 /// Get progress ratio of current playing song
M src/ui.rs View
@@ -46,7 +46,7 @@ pub fn render(app: &mut App, frame: &mut Frame) {
4646
4747 /// Draws the directory
4848 fn draw_directory_browser(frame: &mut Frame, app: &mut App, size: Rect) {
49− let total_songs = app.conn.conn.stats().unwrap().songs.to_string();
49+ let total_songs = app.conn.stats.songs.to_string();
5050
5151 let rows = app.browser.filetree.iter().enumerate().map(|(i, (t, s))| {
5252 if t == "file" {