diff options
| author | Ruben Beltran del Rio <git@r.bdr.sh> | 2025-01-26 17:04:00 +0100 |
|---|---|---|
| committer | Ruben Beltran del Rio <git@r.bdr.sh> | 2025-01-26 17:04:00 +0100 |
| commit | 4064639d3c3e25760ef43781feca77332cfbe5eb (patch) | |
| tree | 77ce2883e5569bd4de5e1408b41c9d6d556a11c6 /src/sources | |
| parent | fda55240fb06c55a7552ef7ded8c17ee56ce9f49 (diff) | |
Run lint / format
Diffstat (limited to 'src/sources')
| -rw-r--r-- | src/sources/apple_music.rs | 27 | ||||
| -rw-r--r-- | src/sources/dbus.rs | 11 | ||||
| -rw-r--r-- | src/sources/mod.rs | 15 | ||||
| -rw-r--r-- | src/sources/spotify.rs | 25 |
4 files changed, 40 insertions, 38 deletions
diff --git a/src/sources/apple_music.rs b/src/sources/apple_music.rs index 06412b8..6279a50 100644 --- a/src/sources/apple_music.rs +++ b/src/sources/apple_music.rs @@ -1,8 +1,15 @@ use std::ffi::CStr; use std::io::Result; -use cocoa::{base::{nil, id}, foundation::NSString}; -use objc::{class, msg_send, sel, sel_impl, runtime::{Class, Object}}; +use cocoa::{ + base::{id, nil}, + foundation::NSString, +}; +use objc::{ + class, msg_send, + runtime::{Class, Object}, + sel, sel_impl, +}; use objc_id::Id; use crate::Track; @@ -18,7 +25,6 @@ impl AppleMusic { } impl LyricsSource for AppleMusic { - fn name(&self) -> String { "apple_music".to_string() } @@ -27,17 +33,18 @@ impl LyricsSource for AppleMusic { unsafe { let app: Id<Object> = { let cls = class!(SBApplication); - let bundle_identifier = NSString::alloc(nil).init_str("com.apple.Music"); + let bundle_identifier = NSString::alloc(nil).init_str("com.apple.Music"); let workspace_class = Class::get("NSWorkspace").unwrap(); let shared_workspace: id = msg_send![workspace_class, sharedWorkspace]; let app_url: id = msg_send![shared_workspace, URLForApplicationWithBundleIdentifier:bundle_identifier]; if app_url != nil { - let app: *mut Object = msg_send![cls, applicationWithBundleIdentifier:bundle_identifier]; + let app: *mut Object = + msg_send![cls, applicationWithBundleIdentifier:bundle_identifier]; Id::from_ptr(app) } else { - return None + return None; } }; @@ -53,11 +60,7 @@ impl LyricsSource for AppleMusic { let name = CStr::from_ptr(name_ptr).to_string_lossy().into_owned(); let artist = CStr::from_ptr(artist_ptr).to_string_lossy().into_owned(); - - return Some(Track { - name, - artist - }) + return Some(Track { name, artist }); } } } @@ -76,5 +79,3 @@ impl LyricsSource for AppleMusic { Ok(()) } } - - diff --git a/src/sources/dbus.rs b/src/sources/dbus.rs index 57c5853..2f6bccd 100644 --- a/src/sources/dbus.rs +++ b/src/sources/dbus.rs @@ -1,5 +1,5 @@ -use std::io::Result; use mpris::PlayerFinder; +use std::io::Result; use crate::Track; @@ -14,24 +14,19 @@ impl Dbus { } impl LyricsSource for Dbus { - fn name(&self) -> String { "dbus".to_string() } fn current_track(&self) -> Option<Track> { - let player = PlayerFinder::new().ok()? - .find_active().ok()?; + let player = PlayerFinder::new().ok()?.find_active().ok()?; let metadata = player.get_metadata().ok()?; let name = metadata.title()?.to_string(); let artists = metadata.artists()?; let artist = artists.get(0)?.to_string(); - Some(Track { - name, - artist - }) + Some(Track { name, artist }) } fn disable(&self) -> Result<()> { diff --git a/src/sources/mod.rs b/src/sources/mod.rs index 087a87f..47c25d0 100644 --- a/src/sources/mod.rs +++ b/src/sources/mod.rs @@ -1,4 +1,4 @@ -use std::io::{Result, Error, ErrorKind::Other}; +use std::io::{Error, ErrorKind::Other, Result}; #[cfg(target_os = "macos")] mod apple_music; @@ -29,14 +29,17 @@ pub trait LyricsSource { } pub fn list() -> Vec<String> { - available_sources().into_iter().map(|source| source.name()).collect() + available_sources() + .into_iter() + .map(|source| source.name()) + .collect() } pub fn enable(source_name: &String) -> Result<()> { let sources = available_sources(); for source in sources { if &source.name() == source_name { - return source.enable() + return source.enable(); } } Err(Error::new(Other, "No such source was available.")) @@ -46,7 +49,7 @@ pub fn disable(source_name: &String) -> Result<()> { let sources = available_sources(); for source in sources { if &source.name() == source_name { - return source.disable() + return source.disable(); } } Err(Error::new(Other, "No such source was available.")) @@ -56,7 +59,7 @@ pub fn reset(source_name: &String) -> Result<()> { let sources = available_sources(); for source in sources { if &source.name() == source_name { - return source.reset() + return source.reset(); } } Err(Error::new(Other, "No such source was available.")) @@ -69,7 +72,7 @@ pub fn get_track() -> Option<Track> { return Some(track); } } - return None + return None; } pub fn available_sources() -> Vec<Box<dyn LyricsSource>> { diff --git a/src/sources/spotify.rs b/src/sources/spotify.rs index e4bf19c..bd627db 100644 --- a/src/sources/spotify.rs +++ b/src/sources/spotify.rs @@ -1,8 +1,15 @@ use std::ffi::CStr; use std::io::Result; -use cocoa::{base::{nil, id}, foundation::NSString}; -use objc::{class, msg_send, sel, sel_impl, runtime::{Class, Object}}; +use cocoa::{ + base::{id, nil}, + foundation::NSString, +}; +use objc::{ + class, msg_send, + runtime::{Class, Object}, + sel, sel_impl, +}; use objc_id::Id; use crate::Track; @@ -18,7 +25,6 @@ impl Spotify { } impl LyricsSource for Spotify { - fn name(&self) -> String { "spotify".to_string() } @@ -27,17 +33,18 @@ impl LyricsSource for Spotify { unsafe { let app: Id<Object> = { let cls = class!(SBApplication); - let bundle_identifier = NSString::alloc(nil).init_str("com.spotify.Client"); + let bundle_identifier = NSString::alloc(nil).init_str("com.spotify.Client"); let workspace_class = Class::get("NSWorkspace").unwrap(); let shared_workspace: id = msg_send![workspace_class, sharedWorkspace]; let app_url: id = msg_send![shared_workspace, URLForApplicationWithBundleIdentifier:bundle_identifier]; if app_url != nil { - let app: *mut Object = msg_send![cls, applicationWithBundleIdentifier:bundle_identifier]; + let app: *mut Object = + msg_send![cls, applicationWithBundleIdentifier:bundle_identifier]; Id::from_ptr(app) } else { - return None + return None; } }; @@ -53,11 +60,7 @@ impl LyricsSource for Spotify { let name = CStr::from_ptr(name_ptr).to_string_lossy().into_owned(); let artist = CStr::from_ptr(artist_ptr).to_string_lossy().into_owned(); - - return Some(Track { - name, - artist - }) + return Some(Track { name, artist }); } } } |