cargo fmt

This commit is contained in:
KoffeinFlummi
2019-04-20 00:11:43 +02:00
parent f320b953d6
commit 1a17860957
8 changed files with 109 additions and 55 deletions

View File

@@ -20,7 +20,7 @@ pub struct Album {
pub cover_url: Option<String>,
pub url: String,
pub tracks: Option<Vec<Track>>,
pub added_at: Option<DateTime<Utc>>
pub added_at: Option<DateTime<Utc>>,
}
impl Album {

View File

@@ -53,25 +53,30 @@ impl Library {
let t_tracks = {
let library = library.clone();
thread::spawn(move || {
library.load_cache(config::cache_path(CACHE_TRACKS), library.tracks.clone());
library
.load_cache(config::cache_path(CACHE_TRACKS), library.tracks.clone());
library.fetch_tracks();
library.save_cache(config::cache_path(CACHE_TRACKS), library.tracks.clone());
library
.save_cache(config::cache_path(CACHE_TRACKS), library.tracks.clone());
})
};
let t_albums = {
let library = library.clone();
thread::spawn(move || {
library.load_cache(config::cache_path(CACHE_ALBUMS), library.albums.clone());
library
.load_cache(config::cache_path(CACHE_ALBUMS), library.albums.clone());
library.fetch_albums();
library.save_cache(config::cache_path(CACHE_ALBUMS), library.albums.clone());
library
.save_cache(config::cache_path(CACHE_ALBUMS), library.albums.clone());
})
};
let t_artists = {
let library = library.clone();
thread::spawn(move || {
library.load_cache(config::cache_path(CACHE_ARTISTS), library.artists.clone());
library
.load_cache(config::cache_path(CACHE_ARTISTS), library.artists.clone());
library.fetch_artists();
})
};
@@ -79,9 +84,15 @@ impl Library {
let t_playlists = {
let library = library.clone();
thread::spawn(move || {
library.load_cache(config::cache_path(CACHE_PLAYLISTS), library.playlists.clone());
library.load_cache(
config::cache_path(CACHE_PLAYLISTS),
library.playlists.clone(),
);
library.fetch_playlists();
library.save_cache(config::cache_path(CACHE_PLAYLISTS), library.playlists.clone());
library.save_cache(
config::cache_path(CACHE_PLAYLISTS),
library.playlists.clone(),
);
})
};
@@ -114,7 +125,11 @@ impl Library {
let parsed: Result<Vec<T>, _> = serde_json::from_str(&contents);
match parsed {
Ok(cache) => {
debug!("cache from {} loaded ({} lists)", cache_path.display(), cache.len());
debug!(
"cache from {} loaded ({} lists)",
cache_path.display(),
cache.len()
);
let mut store = store.write().expect("can't writelock store");
store.clear();
store.extend(cache);
@@ -196,7 +211,12 @@ impl Library {
}
fn needs_download(&self, remote: &SimplifiedPlaylist) -> bool {
for local in self.playlists.read().expect("can't readlock playlists").iter() {
for local in self
.playlists
.read()
.expect("can't readlock playlists")
.iter()
{
if local.id == remote.id {
return local.snapshot_id != remote.snapshot_id;
}
@@ -382,8 +402,9 @@ impl Library {
let store = self.albums.read().unwrap();
if page.total as usize == store.len() &&
!page.items
if page.total as usize == store.len()
&& !page
.items
.iter()
.enumerate()
.any(|(i, a)| &a.album.id != &store[i].id)
@@ -425,8 +446,9 @@ impl Library {
let store = self.tracks.read().unwrap();
if page.total as usize == store.len() &&
!page.items
if page.total as usize == store.len()
&& !page
.items
.iter()
.enumerate()
.any(|(i, t)| &t.track.id != &store[i].id)
@@ -449,11 +471,7 @@ impl Library {
// Remove old unfollowed artists
{
let mut artists = self.artists.write().unwrap();
*artists = artists
.iter()
.filter(|a| a.is_followed)
.cloned()
.collect();
*artists = artists.iter().filter(|a| a.is_followed).cloned().collect();
}
// Add artists that aren't followed but have saved tracks
@@ -527,12 +545,11 @@ impl Library {
}
if api {
if self.spotify.current_user_saved_tracks_add(
tracks
.iter()
.map(|t| t.id.clone())
.collect()
).is_none() {
if self
.spotify
.current_user_saved_tracks_add(tracks.iter().map(|t| t.id.clone()).collect())
.is_none()
{
return;
}
}
@@ -562,12 +579,11 @@ impl Library {
}
if api {
if self.spotify.current_user_saved_tracks_delete(
tracks
.iter()
.map(|t| t.id.clone())
.collect()
).is_none() {
if self
.spotify
.current_user_saved_tracks_delete(tracks.iter().map(|t| t.id.clone()).collect())
.is_none()
{
return;
}
}
@@ -601,7 +617,11 @@ impl Library {
return;
}
if self.spotify.current_user_saved_albums_add(vec![album.id.clone()]).is_none() {
if self
.spotify
.current_user_saved_albums_add(vec![album.id.clone()])
.is_none()
{
return;
}
@@ -626,7 +646,11 @@ impl Library {
return;
}
if self.spotify.current_user_saved_albums_delete(vec![album.id.clone()]).is_none() {
if self
.spotify
.current_user_saved_albums_delete(vec![album.id.clone()])
.is_none()
{
return;
}
@@ -634,11 +658,7 @@ impl Library {
{
let mut store = self.albums.write().unwrap();
*store = store
.iter()
.filter(|a| a.id != album.id)
.cloned()
.collect();
*store = store.iter().filter(|a| a.id != album.id).cloned().collect();
}
if let Some(tracks) = album.tracks.as_ref() {
@@ -662,7 +682,11 @@ impl Library {
return;
}
if self.spotify.user_follow_artists(vec![artist.id.clone()]).is_none() {
if self
.spotify
.user_follow_artists(vec![artist.id.clone()])
.is_none()
{
return;
}
@@ -687,7 +711,11 @@ impl Library {
return;
}
if self.spotify.user_unfollow_artists(vec![artist.id.clone()]).is_none() {
if self
.spotify
.user_unfollow_artists(vec![artist.id.clone()])
.is_none()
{
return;
}
@@ -717,7 +745,11 @@ impl Library {
return;
}
if self.spotify.user_playlist_follow_playlist(playlist.owner_id.clone(), playlist.id.clone()).is_none() {
if self
.spotify
.user_playlist_follow_playlist(playlist.owner_id.clone(), playlist.id.clone())
.is_none()
{
return;
}

View File

@@ -156,7 +156,11 @@ fn main() {
#[cfg(feature = "mpris")]
let mpris_manager = Arc::new(mpris::MprisManager::new(spotify.clone(), queue.clone()));
let library = Arc::new(Library::new(&event_manager, spotify.clone(), cfg.use_nerdfont.unwrap_or(false)));
let library = Arc::new(Library::new(
&event_manager,
spotify.clone(),
cfg.use_nerdfont.unwrap_or(false),
));
let mut cmd_manager = CommandManager::new();
cmd_manager.register_all(spotify.clone(), queue.clone(), library.clone());
@@ -172,7 +176,7 @@ fn main() {
event_manager.clone(),
spotify.clone(),
queue.clone(),
library.clone()
library.clone(),
);
let libraryview = ui::library::LibraryView::new(queue.clone(), library.clone());

View File

@@ -1,8 +1,8 @@
use std::iter::Iterator;
use std::sync::Arc;
use queue::Queue;
use library::Library;
use queue::Queue;
use track::Track;
use traits::ListItem;

View File

@@ -527,7 +527,10 @@ impl Spotify {
})
}
pub fn current_user_followed_artists(&self, last: Option<String>) -> Option<CursorBasedPage<FullArtist>> {
pub fn current_user_followed_artists(
&self,
last: Option<String>,
) -> Option<CursorBasedPage<FullArtist>> {
self.api_with_retry(|api| api.current_user_followed_artists(50, last.clone()))
.map(|cp| cp.artists)
}

View File

@@ -22,7 +22,7 @@ pub struct Track {
pub album_artists: Vec<String>,
pub cover_url: String,
pub url: String,
pub added_at: Option<DateTime<Utc>>
pub added_at: Option<DateTime<Utc>>,
}
impl Track {

View File

@@ -18,14 +18,28 @@ pub struct LibraryView {
impl LibraryView {
pub fn new(queue: Arc<Queue>, library: Arc<Library>) -> Self {
let tabs = TabView::new()
.tab("tracks", "Tracks", ListView::new(library.tracks.clone(), queue.clone(), library.clone()))
.tab("albums", "Albums", ListView::new(library.albums.clone(), queue.clone(), library.clone()))
.tab("artists", "Artists", ListView::new(library.artists.clone(), queue.clone(), library.clone()))
.tab("playlists", "Playlists", PlaylistsView::new(queue.clone(), library.clone()));
.tab(
"tracks",
"Tracks",
ListView::new(library.tracks.clone(), queue.clone(), library.clone()),
)
.tab(
"albums",
"Albums",
ListView::new(library.albums.clone(), queue.clone(), library.clone()),
)
.tab(
"artists",
"Artists",
ListView::new(library.artists.clone(), queue.clone(), library.clone()),
)
.tab(
"playlists",
"Playlists",
PlaylistsView::new(queue.clone(), library.clone()),
);
Self {
tabs
}
Self { tabs }
}
}

View File

@@ -48,7 +48,7 @@ impl SearchView {
events: EventManager,
spotify: Arc<Spotify>,
queue: Arc<Queue>,
library: Arc<Library>
library: Arc<Library>,
) -> SearchView {
let results_tracks = Arc::new(RwLock::new(Vec::new()));
let results_albums = Arc::new(RwLock::new(Vec::new()));
@@ -72,7 +72,8 @@ impl SearchView {
let pagination_albums = list_albums.get_pagination().clone();
let list_artists = ListView::new(results_artists.clone(), queue.clone(), library.clone());
let pagination_artists = list_artists.get_pagination().clone();
let list_playlists = ListView::new(results_playlists.clone(), queue.clone(), library.clone());
let list_playlists =
ListView::new(results_playlists.clone(), queue.clone(), library.clone());
let pagination_playlists = list_playlists.get_pagination().clone();
let tabs = TabView::new()