mirror of
https://github.com/Zedfrigg/ironbar.git
synced 2025-07-01 10:41:03 +02:00
parent
15f0857859
commit
5772711192
5 changed files with 28 additions and 24 deletions
|
@ -26,7 +26,7 @@ async_once = "0.2.6"
|
||||||
indexmap = "1.9.1"
|
indexmap = "1.9.1"
|
||||||
futures-util = "0.3.21"
|
futures-util = "0.3.21"
|
||||||
chrono = "0.4.19"
|
chrono = "0.4.19"
|
||||||
reqwest = {version = "0.11.14", features = ["default"] }
|
reqwest = {version = "0.11.14" }
|
||||||
regex = { version = "1.6.0", default-features = false, features = ["std"] }
|
regex = { version = "1.6.0", default-features = false, features = ["std"] }
|
||||||
stray = { version = "0.1.2" }
|
stray = { version = "0.1.2" }
|
||||||
dirs = "4.0.0"
|
dirs = "4.0.0"
|
||||||
|
|
|
@ -22,7 +22,7 @@ pub struct Track {
|
||||||
pub disc: Option<u64>,
|
pub disc: Option<u64>,
|
||||||
pub genre: Option<String>,
|
pub genre: Option<String>,
|
||||||
pub track: Option<u64>,
|
pub track: Option<u64>,
|
||||||
pub cover_path: Option<PathBuf>,
|
pub cover_path: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
|
|
|
@ -121,12 +121,16 @@ impl MpdClient {
|
||||||
fn convert_song(song: &Song, music_dir: &Path) -> Track {
|
fn convert_song(song: &Song, music_dir: &Path) -> Track {
|
||||||
let (track, disc) = song.number();
|
let (track, disc) = song.number();
|
||||||
|
|
||||||
let cover_path = music_dir.join(
|
let cover_path = music_dir
|
||||||
song.file_path()
|
.join(
|
||||||
.parent()
|
song.file_path()
|
||||||
.expect("Song path should not be root")
|
.parent()
|
||||||
.join("cover.jpg"),
|
.expect("Song path should not be root")
|
||||||
);
|
.join("cover.jpg"),
|
||||||
|
)
|
||||||
|
.into_os_string()
|
||||||
|
.into_string()
|
||||||
|
.ok();
|
||||||
|
|
||||||
Track {
|
Track {
|
||||||
title: song.title().map(std::string::ToString::to_string),
|
title: song.title().map(std::string::ToString::to_string),
|
||||||
|
@ -136,7 +140,7 @@ impl MpdClient {
|
||||||
genre: try_get_first_tag(song, &Tag::Genre).map(std::string::ToString::to_string),
|
genre: try_get_first_tag(song, &Tag::Genre).map(std::string::ToString::to_string),
|
||||||
disc: Some(disc),
|
disc: Some(disc),
|
||||||
track: Some(track),
|
track: Some(track),
|
||||||
cover_path: Some(cover_path),
|
cover_path,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,6 @@ use color_eyre::Result;
|
||||||
use lazy_static::lazy_static;
|
use lazy_static::lazy_static;
|
||||||
use mpris::{DBusError, Event, Metadata, PlaybackStatus, Player, PlayerFinder};
|
use mpris::{DBusError, Event, Metadata, PlaybackStatus, Player, PlayerFinder};
|
||||||
use std::collections::HashSet;
|
use std::collections::HashSet;
|
||||||
use std::path::PathBuf;
|
|
||||||
use std::sync::{Arc, Mutex};
|
use std::sync::{Arc, Mutex};
|
||||||
use std::thread::sleep;
|
use std::thread::sleep;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
@ -260,10 +259,7 @@ impl From<Metadata> for Track {
|
||||||
.and_then(mpris::MetadataValue::as_str_array)
|
.and_then(mpris::MetadataValue::as_str_array)
|
||||||
.and_then(|arr| arr.first().map(|val| (*val).to_string())),
|
.and_then(|arr| arr.first().map(|val| (*val).to_string())),
|
||||||
track: value.track_number().map(|track| track as u64),
|
track: value.track_number().map(|track| track as u64),
|
||||||
cover_path: value
|
cover_path: value.art_url().map(|s| s.to_string()),
|
||||||
.art_url()
|
|
||||||
.map(|path| path.replace("file://", ""))
|
|
||||||
.map(PathBuf::from),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,16 +1,16 @@
|
||||||
mod config;
|
mod config;
|
||||||
|
|
||||||
|
use std::path::PathBuf;
|
||||||
use crate::clients::music::{self, MusicClient, PlayerState, PlayerUpdate, Status, Track};
|
use crate::clients::music::{self, MusicClient, PlayerState, PlayerUpdate, Status, Track};
|
||||||
|
use crate::image::ImageProvider;
|
||||||
use crate::modules::{Module, ModuleInfo, ModuleUpdateEvent, ModuleWidget, WidgetContext};
|
use crate::modules::{Module, ModuleInfo, ModuleUpdateEvent, ModuleWidget, WidgetContext};
|
||||||
use crate::popup::Popup;
|
use crate::popup::Popup;
|
||||||
use crate::{send_async, try_send};
|
use crate::{send_async, try_send};
|
||||||
use color_eyre::Result;
|
use color_eyre::Result;
|
||||||
use glib::Continue;
|
use glib::Continue;
|
||||||
use gtk::gdk_pixbuf::Pixbuf;
|
|
||||||
use gtk::prelude::*;
|
use gtk::prelude::*;
|
||||||
use gtk::{Button, Image, Label, Orientation, Scale};
|
use gtk::{Button, IconTheme, Label, Orientation, Scale};
|
||||||
use regex::Regex;
|
use regex::Regex;
|
||||||
use std::path::PathBuf;
|
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
use tokio::spawn;
|
use tokio::spawn;
|
||||||
|
@ -213,13 +213,15 @@ impl Module<Button> for MusicModule {
|
||||||
tx: Sender<Self::ReceiveMessage>,
|
tx: Sender<Self::ReceiveMessage>,
|
||||||
rx: glib::Receiver<Self::SendMessage>,
|
rx: glib::Receiver<Self::SendMessage>,
|
||||||
) -> Option<gtk::Box> {
|
) -> Option<gtk::Box> {
|
||||||
|
let icon_theme = IconTheme::new();
|
||||||
|
|
||||||
let container = gtk::Box::builder()
|
let container = gtk::Box::builder()
|
||||||
.orientation(Orientation::Horizontal)
|
.orientation(Orientation::Horizontal)
|
||||||
.spacing(10)
|
.spacing(10)
|
||||||
.name("popup-music")
|
.name("popup-music")
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
let album_image = Image::builder()
|
let album_image = gtk::Image::builder()
|
||||||
.width_request(128)
|
.width_request(128)
|
||||||
.height_request(128)
|
.height_request(128)
|
||||||
.name("album-art")
|
.name("album-art")
|
||||||
|
@ -304,16 +306,18 @@ impl Module<Button> for MusicModule {
|
||||||
let new_cover = update.song.cover_path;
|
let new_cover = update.song.cover_path;
|
||||||
if prev_cover != new_cover {
|
if prev_cover != new_cover {
|
||||||
prev_cover = new_cover.clone();
|
prev_cover = new_cover.clone();
|
||||||
match new_cover.map(|cover_path| {
|
let res = match new_cover.map(|cover_path| ImageProvider::parse(cover_path, &icon_theme, 128))
|
||||||
Pixbuf::from_file_at_scale(cover_path, 128, 128, true)
|
{
|
||||||
}) {
|
Some(Ok(image)) => image.load_into_image(album_image.clone()),
|
||||||
Some(Ok(pixbuf)) => album_image.set_from_pixbuf(Some(&pixbuf)),
|
|
||||||
Some(Err(err)) => {
|
Some(Err(err)) => {
|
||||||
error!("{:?}", err);
|
|
||||||
album_image.set_from_pixbuf(None);
|
album_image.set_from_pixbuf(None);
|
||||||
|
Err(err)
|
||||||
}
|
}
|
||||||
None => album_image.set_from_pixbuf(None),
|
None => Ok(album_image.set_from_pixbuf(None)),
|
||||||
};
|
};
|
||||||
|
if let Err(err) = res {
|
||||||
|
error!("{err:?}");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
title_label
|
title_label
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue