Skip to content

Commit

Permalink
feat: support show image
Browse files Browse the repository at this point in the history
  • Loading branch information
Decodetalkers committed Aug 6, 2024
1 parent 037e4fc commit f0db933
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 11 deletions.
40 changes: 40 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,4 @@ alsa = "0.9.0"
gio = "0.20.0"
regex = "1.10.5"
xdg = "2.5.2"
url = "2.5.2"
39 changes: 29 additions & 10 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use iced::widget::{button, container, row, slider, text, Space};
use iced::widget::{button, container, image, row, slider, text, Space};
use iced::{executor, Event, Font};
use iced::{Command, Element, Length, Theme};
use iced_layershell::actions::{
Expand Down Expand Up @@ -186,6 +186,11 @@ impl LalaMusicBar {
.as_ref()
.map(|data| data.metadata.xesam_title.as_str())
.unwrap_or("No Video here");
let art_url = self
.service_data
.as_ref()
.and_then(|data| url::Url::parse(&data.metadata.mpris_arturl).ok())
.and_then(|url| url.to_file_path().ok());
let title = container(
text(title)
.size(20)
Expand Down Expand Up @@ -244,15 +249,29 @@ impl LalaMusicBar {
.center_x();

let sound_slider = self.sound_slider();
let col = row![
button("L").on_press(Message::ToggleLauncher),
title,
Space::with_width(Length::Fill),
buttons,
sound_slider,
Space::with_width(Length::Fixed(10.)),
]
.spacing(10);
let col = if let Some(art_url) = art_url {
row![
button("L").on_press(Message::ToggleLauncher),
Space::with_width(Length::Fixed(5.)),
image(image::Handle::from_path(art_url)),
title,
Space::with_width(Length::Fill),
buttons,
sound_slider,
Space::with_width(Length::Fixed(10.)),
]
.spacing(10)
} else {
row![
button("L").on_press(Message::ToggleLauncher),
title,
Space::with_width(Length::Fill),
buttons,
sound_slider,
Space::with_width(Length::Fixed(10.)),
]
.spacing(10)
};

container(col)
.width(Length::Fill)
Expand Down
2 changes: 1 addition & 1 deletion src/zbus_mpirs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const PLAYCTLD: &str = "org.mpris.MediaPlayer2.playerctld";
#[derive(Debug, Clone)]
pub struct Metadata {
mpris_trackid: OwnedObjectPath,
mpris_arturl: String,
pub mpris_arturl: String,
pub xesam_title: String,
xesam_album: String,
xesam_artist: Vec<String>,
Expand Down

0 comments on commit f0db933

Please sign in to comment.