remove unnecessary variables from Connection
This commit is contained in:
parent
dc3f561de3
commit
7ae0a2cc19
|
|
@ -13,9 +13,6 @@ pub struct Connection {
|
||||||
pub state: String,
|
pub state: String,
|
||||||
pub elapsed: Duration,
|
pub elapsed: Duration,
|
||||||
pub total_duration: Duration,
|
pub total_duration: Duration,
|
||||||
pub volume: u8,
|
|
||||||
pub repeat: bool,
|
|
||||||
pub random: bool,
|
|
||||||
pub current_song: Song,
|
pub current_song: Song,
|
||||||
pub stats: mpd::Stats,
|
pub stats: mpd::Stats,
|
||||||
pub status: mpd::Status,
|
pub status: mpd::Status,
|
||||||
|
|
@ -34,17 +31,10 @@ impl Connection {
|
||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
|
|
||||||
let songs_filenames: Vec<String> = conn
|
let songs_filenames: Vec<String> = conn.listall()?.into_iter().map(|x| x.file).collect();
|
||||||
.listall()?
|
|
||||||
.into_iter()
|
|
||||||
.map(|x| x.file)
|
|
||||||
.collect();
|
|
||||||
|
|
||||||
let status = conn.status().unwrap();
|
let status = conn.status().unwrap();
|
||||||
let (elapsed, total) = status.time.unwrap_or_default();
|
let (elapsed, total) = status.time.unwrap_or_default();
|
||||||
let volume: u8 = status.volume as u8;
|
|
||||||
let repeat = status.repeat;
|
|
||||||
let random = status.random;
|
|
||||||
let stats = conn.stats().unwrap_or_default();
|
let stats = conn.stats().unwrap_or_default();
|
||||||
|
|
||||||
let current_song = conn
|
let current_song = conn
|
||||||
|
|
@ -57,9 +47,6 @@ impl Connection {
|
||||||
state: "Stopped".to_string(),
|
state: "Stopped".to_string(),
|
||||||
elapsed,
|
elapsed,
|
||||||
total_duration: total,
|
total_duration: total,
|
||||||
volume,
|
|
||||||
repeat,
|
|
||||||
random,
|
|
||||||
current_song,
|
current_song,
|
||||||
stats,
|
stats,
|
||||||
status,
|
status,
|
||||||
|
|
@ -84,13 +71,15 @@ impl Connection {
|
||||||
/// Update status
|
/// Update status
|
||||||
pub fn update_status(&mut self) {
|
pub fn update_status(&mut self) {
|
||||||
let status = self.conn.status().unwrap();
|
let status = self.conn.status().unwrap();
|
||||||
|
let stats = self.conn.stats().unwrap_or_default();
|
||||||
|
|
||||||
let empty_song = self.get_song_with_only_filename("No Song playing or in Queue");
|
let empty_song = self.get_song_with_only_filename("No Song playing or in Queue");
|
||||||
|
|
||||||
let current_song = self
|
let current_song = self
|
||||||
.conn
|
.conn
|
||||||
.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();
|
|
||||||
|
|
||||||
// Status
|
// Status
|
||||||
self.status = status.clone();
|
self.status = status.clone();
|
||||||
|
|
@ -107,15 +96,6 @@ impl Connection {
|
||||||
self.elapsed = elapsed;
|
self.elapsed = elapsed;
|
||||||
self.total_duration = total;
|
self.total_duration = total;
|
||||||
|
|
||||||
// Volume
|
|
||||||
self.volume = status.volume as u8;
|
|
||||||
|
|
||||||
// Repeat mode
|
|
||||||
self.repeat = status.repeat;
|
|
||||||
|
|
||||||
// Random mode
|
|
||||||
self.random = status.random;
|
|
||||||
|
|
||||||
// Current song
|
// Current song
|
||||||
self.current_song = current_song;
|
self.current_song = current_song;
|
||||||
|
|
||||||
|
|
|
||||||
10
src/ui.rs
10
src/ui.rs
|
|
@ -126,7 +126,7 @@ fn draw_directory_browser(frame: &mut Frame, app: &mut App, size: Rect) {
|
||||||
.alignment(Alignment::Center),
|
.alignment(Alignment::Center),
|
||||||
)
|
)
|
||||||
.title(
|
.title(
|
||||||
Title::from(format!("Volume: {}%", app.conn.volume).green())
|
Title::from(format!("Volume: {}%", app.conn.status.volume).green())
|
||||||
.alignment(Alignment::Right),
|
.alignment(Alignment::Right),
|
||||||
)
|
)
|
||||||
.borders(Borders::ALL),
|
.borders(Borders::ALL),
|
||||||
|
|
@ -220,7 +220,7 @@ fn draw_queue(frame: &mut Frame, app: &mut App, size: Rect) {
|
||||||
format!("({} items)", app.queue_list.list.len()).bold(),
|
format!("({} items)", app.queue_list.list.len()).bold(),
|
||||||
))
|
))
|
||||||
.title(
|
.title(
|
||||||
Title::from(format!("Volume: {}%", app.conn.volume).green())
|
Title::from(format!("Volume: {}%", app.conn.status.volume).green())
|
||||||
.alignment(Alignment::Right),
|
.alignment(Alignment::Right),
|
||||||
)
|
)
|
||||||
.borders(Borders::ALL),
|
.borders(Borders::ALL),
|
||||||
|
|
@ -280,17 +280,17 @@ fn draw_progress_bar(frame: &mut Frame, app: &mut App, size: Rect) {
|
||||||
// Get the current modes
|
// Get the current modes
|
||||||
let mut modes_bottom: String = String::new();
|
let mut modes_bottom: String = String::new();
|
||||||
// we do this to check if at least one mode is enabled so we can push "[]"
|
// we do this to check if at least one mode is enabled so we can push "[]"
|
||||||
if app.conn.repeat | app.conn.random {
|
if app.conn.status.repeat | app.conn.status.random {
|
||||||
modes_bottom.push('r');
|
modes_bottom.push('r');
|
||||||
}
|
}
|
||||||
|
|
||||||
if !modes_bottom.is_empty() {
|
if !modes_bottom.is_empty() {
|
||||||
modes_bottom.clear();
|
modes_bottom.clear();
|
||||||
modes_bottom.push('[');
|
modes_bottom.push('[');
|
||||||
if app.conn.repeat {
|
if app.conn.status.repeat {
|
||||||
modes_bottom.push('r');
|
modes_bottom.push('r');
|
||||||
}
|
}
|
||||||
if app.conn.random {
|
if app.conn.status.random {
|
||||||
modes_bottom.push('z');
|
modes_bottom.push('z');
|
||||||
}
|
}
|
||||||
modes_bottom.push(']');
|
modes_bottom.push(']');
|
||||||
|
|
|
||||||
Reference in New Issue