diff options
author | Mustafa Salih <37256744+MustafaSalih1993@users.noreply.github.com> | 2021-02-03 03:43:31 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-02-03 03:43:31 +0300 |
commit | c4cd23f471fe8d6fdac7ddca436b477c16031373 (patch) | |
tree | bb25b89e1f1186d2f06a7b1ad12bbf26c6d23cac /src/utils/spotify.rs | |
parent | 303808ea191f4c8d047c14a77a1bd322d4dcc081 (diff) | |
parent | 0359a01cc89b1bbcf0bd08799d2c8dfd09f609d0 (diff) |
Merge pull request #44 from MustafaSalih1993/dev
removed some doublicated code
Diffstat (limited to 'src/utils/spotify.rs')
-rw-r--r-- | src/utils/spotify.rs | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/src/utils/spotify.rs b/src/utils/spotify.rs index a73128d..9e5c5da 100644 --- a/src/utils/spotify.rs +++ b/src/utils/spotify.rs @@ -1,14 +1,15 @@ use crate::config::CONFIG; +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. -// FIXME: I know im lazy asshole, this error handling looks ugly, i dont like it too, need to fix soon. -pub fn get_spotify() -> String { + +pub fn get_spotify() -> ThreadsData { + let empty_data = ThreadsData::Spotify(String::from("")); let conn = match Connection::new_session() { Ok(conn) => conn, - _ => return String::from(""), + _ => return empty_data, }; let p = conn.with_proxy( @@ -19,7 +20,7 @@ pub fn get_spotify() -> String { let metadata: arg::PropMap = match p.get("org.mpris.MediaPlayer2.Player", "Metadata") { Ok(data) => data, - _ => return String::from(""), + _ => return empty_data, }; let title: Option<&String> = arg::prop_cast(&metadata, "xesam:title"); @@ -38,8 +39,9 @@ pub fn get_spotify() -> String { None => "", }; - format!( + let data = format!( " {} {} - {} {}", CONFIG.spotify.icon, artist, title, CONFIG.seperator - ) + ); + ThreadsData::Spotify(data) } |