Krolyxon
Commit ebc4428

rmptuiebc4428

remove unnecessary variables from Connection

Author
krolxon
Date
2024-06-01 16:27 +0530
Parent
971b336
Commit
ebc44289ccb35e5ae839998949eefdf9b620be10

+9 −29

2 files changed

  1. M src/connection.rs +4 −24
  2. M src/ui.rs +5 −5
M src/connection.rs View
@@ -13,9 +13,6 @@ pub struct Connection {
1313 pub state: String,
1414 pub elapsed: Duration,
1515 pub total_duration: Duration,
16− pub volume: u8,
17− pub repeat: bool,
18− pub random: bool,
1916 pub current_song: Song,
2017 pub stats: mpd::Stats,
2118 pub status: mpd::Status,
@@ -34,17 +31,10 @@ impl Connection {
3431 ..Default::default()
3532 };
3633
37− let songs_filenames: Vec<String> = conn
38− .listall()?
39− .into_iter()
40− .map(|x| x.file)
41− .collect();
34+ let songs_filenames: Vec<String> = conn.listall()?.into_iter().map(|x| x.file).collect();
4235
4336 let status = conn.status().unwrap();
4437 let (elapsed, total) = status.time.unwrap_or_default();
45− let volume: u8 = status.volume as u8;
46− let repeat = status.repeat;
47− let random = status.random;
4838 let stats = conn.stats().unwrap_or_default();
4939
5040 let current_song = conn
@@ -57,9 +47,6 @@ impl Connection {
5747 state: "Stopped".to_string(),
5848 elapsed,
5949 total_duration: total,
60− volume,
61− repeat,
62− random,
6350 current_song,
6451 stats,
6552 status,
@@ -84,13 +71,15 @@ impl Connection {
8471 /// Update status
8572 pub fn update_status(&mut self) {
8673 let status = self.conn.status().unwrap();
74+ let stats = self.conn.stats().unwrap_or_default();
75+
8776 let empty_song = self.get_song_with_only_filename("No Song playing or in Queue");
77+
8878 let current_song = self
8979 .conn
9080 .currentsong()
9181 .unwrap_or_else(|_| Some(empty_song.clone()))
9282 .unwrap_or(empty_song);
93− let stats = self.conn.stats().unwrap_or_default();
9483
9584 // Status
9685 self.status = status.clone();
@@ -107,15 +96,6 @@ impl Connection {
10796 self.elapsed = elapsed;
10897 self.total_duration = total;
10998
110− // Volume
111− self.volume = status.volume as u8;
112−
113− // Repeat mode
114− self.repeat = status.repeat;
115−
116− // Random mode
117− self.random = status.random;
118−
11999 // Current song
120100 self.current_song = current_song;
121101
M src/ui.rs View
@@ -126,7 +126,7 @@ fn draw_directory_browser(frame: &mut Frame, app: &mut App, size: Rect) {
126126 .alignment(Alignment::Center),
127127 )
128128 .title(
129− Title::from(format!("Volume: {}%", app.conn.volume).green())
129+ Title::from(format!("Volume: {}%", app.conn.status.volume).green())
130130 .alignment(Alignment::Right),
131131 )
132132 .borders(Borders::ALL),
@@ -220,7 +220,7 @@ fn draw_queue(frame: &mut Frame, app: &mut App, size: Rect) {
220220 format!("({} items)", app.queue_list.list.len()).bold(),
221221 ))
222222 .title(
223− Title::from(format!("Volume: {}%", app.conn.volume).green())
223+ Title::from(format!("Volume: {}%", app.conn.status.volume).green())
224224 .alignment(Alignment::Right),
225225 )
226226 .borders(Borders::ALL),
@@ -280,17 +280,17 @@ fn draw_progress_bar(frame: &mut Frame, app: &mut App, size: Rect) {
280280 // Get the current modes
281281 let mut modes_bottom: String = String::new();
282282 // we do this to check if at least one mode is enabled so we can push "[]"
283− if app.conn.repeat | app.conn.random {
283+ if app.conn.status.repeat | app.conn.status.random {
284284 modes_bottom.push('r');
285285 }
286286
287287 if !modes_bottom.is_empty() {
288288 modes_bottom.clear();
289289 modes_bottom.push('[');
290− if app.conn.repeat {
290+ if app.conn.status.repeat {
291291 modes_bottom.push('r');
292292 }
293− if app.conn.random {
293+ if app.conn.status.random {
294294 modes_bottom.push('z');
295295 }
296296 modes_bottom.push(']');