From f0db9335c4fccd65ec026c1c66a046a03f5e7c95 Mon Sep 17 00:00:00 2001 From: ShootingStarDragons Date: Wed, 7 Aug 2024 00:30:16 +0859 Subject: [PATCH] feat: support show image --- Cargo.lock | 40 ++++++++++++++++++++++++++++++++++++++++ Cargo.toml | 1 + src/main.rs | 39 +++++++++++++++++++++++++++++---------- src/zbus_mpirs.rs | 2 +- 4 files changed, 71 insertions(+), 11 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 5c4552d..80a5d0d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1160,6 +1160,15 @@ version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "aa9a19cbb55df58761df49b23516a86d432839add4af60fc256da840f66ed35b" +[[package]] +name = "form_urlencoded" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e13624c2627564efccf4934284bdd98cbaa14e79b0b5a141218e507b3a823456" +dependencies = [ + "percent-encoding", +] + [[package]] name = "futures" version = "0.3.30" @@ -1794,6 +1803,16 @@ dependencies = [ "objc2 0.4.1", ] +[[package]] +name = "idna" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "634d9b1461af396cad843f47fdba5597a4f9e6ddd4bfb6ff5d85028c25cb12f6" +dependencies = [ + "unicode-bidi", + "unicode-normalization", +] + [[package]] name = "image" version = "0.24.9" @@ -1956,6 +1975,7 @@ dependencies = [ "tokio", "tracing", "tracing-subscriber", + "url", "xdg", "zbus", ] @@ -3693,6 +3713,15 @@ version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3b09c83c3c29d37506a3e260c08c03743a6bb66a9cd432c6934ab501a190571f" +[[package]] +name = "unicode-normalization" +version = "0.1.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a56d1686db2308d901306f92a263857ef59ea39678a5458e7cb17f01415101f5" +dependencies = [ + "tinyvec", +] + [[package]] name = "unicode-properties" version = "0.1.1" @@ -3729,6 +3758,17 @@ version = "0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f962df74c8c05a667b5ee8bcf162993134c104e96440b663c8daa176dc772d8c" +[[package]] +name = "url" +version = "2.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22784dbdf76fdde8af1aeda5622b546b422b6fc585325248a2bf9f5e41e94d6c" +dependencies = [ + "form_urlencoded", + "idna", + "percent-encoding", +] + [[package]] name = "usvg" version = "0.36.0" diff --git a/Cargo.toml b/Cargo.toml index 127a9f4..03b2cb7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -33,3 +33,4 @@ alsa = "0.9.0" gio = "0.20.0" regex = "1.10.5" xdg = "2.5.2" +url = "2.5.2" diff --git a/src/main.rs b/src/main.rs index 58d8dd2..12a4c7d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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::{ @@ -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) @@ -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) diff --git a/src/zbus_mpirs.rs b/src/zbus_mpirs.rs index b7bc80c..2cbb1bd 100644 --- a/src/zbus_mpirs.rs +++ b/src/zbus_mpirs.rs @@ -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,