From c2a1be9cd35c044a63fcf546ffd0a41fff5e9044 Mon Sep 17 00:00:00 2001 From: Mustafa Salih <37256744+MustafaSalih1993@users.noreply.github.com> Date: Sun, 9 May 2021 22:14:29 +0300 Subject: added limits 30 chars foreach the title and artist in spotify block, closes: #53 (#54) --- src/utils/spotify.rs | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/utils/spotify.rs b/src/utils/spotify.rs index 9e5c5da..c48471d 100644 --- a/src/utils/spotify.rs +++ b/src/utils/spotify.rs @@ -3,8 +3,8 @@ use crate::types::ThreadsData; use dbus::blocking::stdintf::org_freedesktop_dbus::Properties; use dbus::{arg, blocking::Connection}; use std::time::Duration; -// getting spotify current artist and title. +// getting spotify current artist and title. pub fn get_spotify() -> ThreadsData { let empty_data = ThreadsData::Spotify(String::from("")); let conn = match Connection::new_session() { @@ -27,13 +27,25 @@ pub fn get_spotify() -> ThreadsData { let artist: Option<&Vec> = arg::prop_cast(&metadata, "xesam:artist"); let title = match title { - Some(title) => title, + Some(title) => { + if title.len() > 30 { + &title[..30] + } else { + title.as_str() + } + } _ => "", }; let artist = match artist { Some(artist_vec) => match artist_vec.first() { - Some(name) => name, + Some(name) => { + if name.len() > 30 { + &name[..30] + } else { + name.as_str() + } + } _ => "", }, None => "", -- cgit v1.2.3