diff --git a/src/main.rs b/src/main.rs index d8bdd94..9d5f95f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -72,9 +72,6 @@ impl eframe::App for JpmmvApp .max_width(240.0) ); }); - - - ui.style_mut().text_styles.insert( egui::TextStyle::Body, @@ -101,17 +98,40 @@ impl eframe::App for JpmmvApp ui.add_space(20.0); - ui.style_mut().text_styles.insert( - egui::TextStyle::Button, - egui::FontId::new(24.0, eframe::epaint::FontFamily::Proportional), - ); - - // if ui.button("Skip").clicked() - if ui.add(egui::Button::image_and_text(egui::include_image!("../assets/Next.png"), "")).clicked() - { - player_interface::next_track(); - self.force_query = true - } + ui.horizontal(|ui| { + // if ui.button("Skip").clicked() + let next_img = egui::Image::new(egui::include_image!("../assets/Next.png")) + .max_width(100.0); + + if ui.add_sized([48.0, 48.0], egui::ImageButton::new(next_img).frame(false)).clicked() + { + player_interface::next_track(); + self.force_query = true + } + + let play_img = egui::Image::new(egui::include_image!("../assets/Play.png")); + let pause_img = egui::Image::new(egui::include_image!("../assets/Pause.png")); + + if self.current_metadata.is_playing + { + if ui.add_sized([48.0, 48.0], egui::ImageButton::new(pause_img).frame(false)).clicked() + { + player_interface::pause(); + self.force_query = true + } + } + else + { + if ui.add_sized([48.0, 48.0], egui::ImageButton::new(play_img).frame(false)).clicked() + { + player_interface::play(); + self.force_query = true + } + } + + + }); + }); }); }); diff --git a/src/player_interface.rs b/src/player_interface.rs index 8589c3d..cb1374a 100644 --- a/src/player_interface.rs +++ b/src/player_interface.rs @@ -8,6 +8,7 @@ pub struct SongMetadata pub artist: String, pub album: String, pub art_url: String, + pub is_playing: bool, } impl SongMetadata { @@ -18,6 +19,7 @@ impl SongMetadata artist: "NONE".to_string(), album: "NONE".to_string(), art_url: "NONE".to_string(), + is_playing: true, } } } @@ -32,6 +34,10 @@ pub fn get_song_metadata() -> SongMetadata let result = run_command(&command); + let command = format!("{} {}", COM_START, "status"); + let status = run_command(&command).to_ascii_lowercase(); + let status = status.trim(); + let mut sm = SongMetadata::new(); let split: Vec<&str> = result.split(',').collect(); @@ -46,6 +52,12 @@ pub fn get_song_metadata() -> SongMetadata sm.album = split[2].to_string(); sm.art_url = split[3].to_string(); sm.art_url = sm.art_url.trim().to_string(); + sm.is_playing = if status == "paused" { + false + } else { + true + }; + // let test_url = sm.art_url.trim_start_matches("file://").to_string(); // let test_url = test_url.trim(); @@ -90,6 +102,18 @@ pub fn next_track() let _ = run_command(&command); } +pub fn play() +{ + let command = format!("{} {}", COM_START, "play"); + let _ = run_command(&command); +} + +pub fn pause() +{ + let command = format!("{} {}", COM_START, "pause"); + let _ = run_command(&command); +} + fn run_command(command: &str) -> String {