diff --git a/src/album.rs b/src/album.rs index 947a3fa..51c7ed3 100644 --- a/src/album.rs +++ b/src/album.rs @@ -27,7 +27,7 @@ pub struct Album { } impl Album { - pub fn load_tracks(&mut self, spotify: Arc) { + pub fn load_tracks(&mut self, spotify: Spotify) { if self.tracks.is_some() { return; } diff --git a/src/artist.rs b/src/artist.rs index 001efd1..a236c2b 100644 --- a/src/artist.rs +++ b/src/artist.rs @@ -34,7 +34,7 @@ impl Artist { } } - pub fn load_albums(&mut self, spotify: Arc) { + pub fn load_albums(&mut self, spotify: Spotify) { if let Some(albums) = self.albums.as_mut() { for album in albums { album.load_tracks(spotify.clone()); diff --git a/src/commands.rs b/src/commands.rs index daa5a9f..30c9b39 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -37,7 +37,7 @@ pub enum CommandResult { pub struct CommandManager { aliases: HashMap, bindings: RefCell>, - spotify: Arc, + spotify: Spotify, queue: Arc, library: Arc, config: Arc, @@ -46,7 +46,7 @@ pub struct CommandManager { impl CommandManager { pub fn new( - spotify: Arc, + spotify: Spotify, queue: Arc, library: Arc, config: Arc, diff --git a/src/library.rs b/src/library.rs index 92d4775..a6039ef 100644 --- a/src/library.rs +++ b/src/library.rs @@ -36,12 +36,12 @@ pub struct Library { pub user_id: Option, pub display_name: Option, ev: EventManager, - spotify: Arc, + spotify: Spotify, pub cfg: Arc, } impl Library { - pub fn new(ev: &EventManager, spotify: Arc, cfg: Arc) -> Self { + pub fn new(ev: &EventManager, spotify: Spotify, cfg: Arc) -> Self { let current_user = spotify.current_user(); let user_id = current_user.as_ref().map(|u| u.id.clone()); let display_name = current_user.as_ref().and_then(|u| u.display_name.clone()); diff --git a/src/main.rs b/src/main.rs index 7868dbd..4260b65 100644 --- a/src/main.rs +++ b/src/main.rs @@ -197,11 +197,7 @@ fn main() { let event_manager = EventManager::new(cursive.cb_sink().clone()); - let spotify = Arc::new(spotify::Spotify::new( - event_manager.clone(), - credentials, - cfg.clone(), - )); + let spotify = spotify::Spotify::new(event_manager.clone(), credentials, cfg.clone()); let queue = Arc::new(queue::Queue::new(spotify.clone(), cfg.clone())); diff --git a/src/mpris.rs b/src/mpris.rs index be0650a..56e90a2 100644 --- a/src/mpris.rs +++ b/src/mpris.rs @@ -28,7 +28,7 @@ type Metadata = HashMap>>; struct MprisState(String, Option); -fn get_playbackstatus(spotify: Arc) -> String { +fn get_playbackstatus(spotify: Spotify) -> String { match spotify.get_current_status() { PlayerEvent::Playing | PlayerEvent::FinishedTrack => "Playing", PlayerEvent::Paused => "Paused", @@ -136,7 +136,7 @@ fn get_metadata(playable: Option) -> Metadata { fn run_dbus_server( ev: EventManager, - spotify: Arc, + spotify: Spotify, queue: Arc, rx: mpsc::Receiver, ) { @@ -691,11 +691,11 @@ fn run_dbus_server( pub struct MprisManager { tx: mpsc::Sender, queue: Arc, - spotify: Arc, + spotify: Spotify, } impl MprisManager { - pub fn new(ev: EventManager, spotify: Arc, queue: Arc) -> Self { + pub fn new(ev: EventManager, spotify: Spotify, queue: Arc) -> Self { let (tx, rx) = mpsc::channel::(); { diff --git a/src/playlist.rs b/src/playlist.rs index 9eb1143..3b458b5 100644 --- a/src/playlist.rs +++ b/src/playlist.rs @@ -23,7 +23,7 @@ pub struct Playlist { } impl Playlist { - pub fn load_tracks(&mut self, spotify: Arc) { + pub fn load_tracks(&mut self, spotify: Spotify) { if self.tracks.is_some() { return; } @@ -31,7 +31,7 @@ impl Playlist { self.tracks = Some(self.get_all_tracks(spotify)); } - fn get_all_tracks(&self, spotify: Arc) -> Vec { + fn get_all_tracks(&self, spotify: Spotify) -> Vec { let mut collected_tracks = Vec::new(); let mut tracks_result = spotify.user_playlist_tracks(&self.id, 100, 0); @@ -71,12 +71,7 @@ impl Playlist { }) } - pub fn delete_track( - &mut self, - index: usize, - spotify: Arc, - library: Arc, - ) -> bool { + pub fn delete_track(&mut self, index: usize, spotify: Spotify, library: Arc) -> bool { let track = self.tracks.as_ref().unwrap()[index].clone(); debug!("deleting track: {} {:?}", index, track); match spotify.delete_tracks(&self.id, &self.snapshot_id, &[(&track, track.list_index)]) { @@ -92,12 +87,7 @@ impl Playlist { } } - pub fn append_tracks( - &mut self, - new_tracks: &[Track], - spotify: Arc, - library: Arc, - ) { + pub fn append_tracks(&mut self, new_tracks: &[Track], spotify: Spotify, library: Arc) { let track_ids: Vec = new_tracks .to_vec() .iter() diff --git a/src/queue.rs b/src/queue.rs index 13a5065..436daba 100644 --- a/src/queue.rs +++ b/src/queue.rs @@ -25,12 +25,12 @@ pub struct Queue { pub queue: Arc>>, random_order: RwLock>>, current_track: RwLock>, - spotify: Arc, + spotify: Spotify, cfg: Arc, } impl Queue { - pub fn new(spotify: Arc, cfg: Arc) -> Queue { + pub fn new(spotify: Spotify, cfg: Arc) -> Queue { let queue = cfg.state().queue.clone(); Queue { queue: Arc::new(RwLock::new(queue)), @@ -370,7 +370,7 @@ impl Queue { } } - pub fn get_spotify(&self) -> Arc { + pub fn get_spotify(&self) -> Spotify { self.spotify.clone() } } diff --git a/src/show.rs b/src/show.rs index 227403a..c47201c 100644 --- a/src/show.rs +++ b/src/show.rs @@ -21,7 +21,7 @@ pub struct Show { } impl Show { - pub fn load_episodes(&mut self, spotify: Arc) { + pub fn load_episodes(&mut self, spotify: Spotify) { if self.episodes.is_some() { return; } diff --git a/src/spotify.rs b/src/spotify.rs index c679871..77a04b3 100644 --- a/src/spotify.rs +++ b/src/spotify.rs @@ -62,16 +62,17 @@ pub enum PlayerEvent { FinishedTrack, } +#[derive(Clone)] pub struct Spotify { events: EventManager, credentials: Credentials, cfg: Arc, - status: RwLock, - api: RwLock, - elapsed: RwLock>, - since: RwLock>, - token_issued: RwLock>, - channel: RwLock>>, + status: Arc>, + api: Arc>, + elapsed: Arc>>, + since: Arc>>, + token_issued: Arc>>, + channel: Arc>>>, user: Option, country: Option, } @@ -86,12 +87,12 @@ impl Spotify { events, credentials, cfg: cfg.clone(), - status: RwLock::new(PlayerEvent::Stopped), - api: RwLock::new(SpotifyAPI::default()), - elapsed: RwLock::new(None), - since: RwLock::new(None), - token_issued: RwLock::new(None), - channel: RwLock::new(None), + status: Arc::new(RwLock::new(PlayerEvent::Stopped)), + api: Arc::new(RwLock::new(SpotifyAPI::default())), + elapsed: Arc::new(RwLock::new(None)), + since: Arc::new(RwLock::new(None)), + token_issued: Arc::new(RwLock::new(None)), + channel: Arc::new(RwLock::new(None)), user: None, country: None, }; diff --git a/src/ui/contextmenu.rs b/src/ui/contextmenu.rs index 13281db..85b98a7 100644 --- a/src/ui/contextmenu.rs +++ b/src/ui/contextmenu.rs @@ -45,7 +45,7 @@ enum ContextMenuAction { impl ContextMenu { pub fn add_track_dialog( library: Arc, - spotify: Arc, + spotify: Spotify, track: Track, ) -> NamedView { let mut list_select: SelectView = SelectView::new(); diff --git a/src/ui/playlist.rs b/src/ui/playlist.rs index 9ff8e1c..c213b9b 100644 --- a/src/ui/playlist.rs +++ b/src/ui/playlist.rs @@ -16,7 +16,7 @@ use crate::ui::listview::ListView; pub struct PlaylistView { playlist: Playlist, list: ListView, - spotify: Arc, + spotify: Spotify, library: Arc, queue: Arc, } diff --git a/src/ui/search_results.rs b/src/ui/search_results.rs index 9bbf5a8..35d52a6 100644 --- a/src/ui/search_results.rs +++ b/src/ui/search_results.rs @@ -36,12 +36,12 @@ pub struct SearchResultsView { results_episodes: Arc>>, pagination_episodes: Pagination, tabs: TabView, - spotify: Arc, + spotify: Spotify, events: EventManager, } type SearchHandler = - Box, &Arc>>, &str, usize, bool) -> u32 + Send + Sync>; + Box>>, &str, usize, bool) -> u32 + Send + Sync>; impl SearchResultsView { pub fn new( @@ -103,7 +103,7 @@ impl SearchResultsView { } fn get_track( - spotify: &Arc, + spotify: &Spotify, tracks: &Arc>>, query: &str, _offset: usize, @@ -119,7 +119,7 @@ impl SearchResultsView { } fn search_track( - spotify: &Arc, + spotify: &Spotify, tracks: &Arc>>, query: &str, offset: usize, @@ -142,7 +142,7 @@ impl SearchResultsView { } fn get_album( - spotify: &Arc, + spotify: &Spotify, albums: &Arc>>, query: &str, _offset: usize, @@ -158,7 +158,7 @@ impl SearchResultsView { } fn search_album( - spotify: &Arc, + spotify: &Spotify, albums: &Arc>>, query: &str, offset: usize, @@ -181,7 +181,7 @@ impl SearchResultsView { } fn get_artist( - spotify: &Arc, + spotify: &Spotify, artists: &Arc>>, query: &str, _offset: usize, @@ -197,7 +197,7 @@ impl SearchResultsView { } fn search_artist( - spotify: &Arc, + spotify: &Spotify, artists: &Arc>>, query: &str, offset: usize, @@ -220,7 +220,7 @@ impl SearchResultsView { } fn get_playlist( - spotify: &Arc, + spotify: &Spotify, playlists: &Arc>>, query: &str, _offset: usize, @@ -236,7 +236,7 @@ impl SearchResultsView { } fn search_playlist( - spotify: &Arc, + spotify: &Spotify, playlists: &Arc>>, query: &str, offset: usize, @@ -259,7 +259,7 @@ impl SearchResultsView { } fn get_show( - spotify: &Arc, + spotify: &Spotify, shows: &Arc>>, query: &str, _offset: usize, @@ -275,7 +275,7 @@ impl SearchResultsView { } fn search_show( - spotify: &Arc, + spotify: &Spotify, shows: &Arc>>, query: &str, offset: usize, @@ -298,7 +298,7 @@ impl SearchResultsView { } fn get_episode( - spotify: &Arc, + spotify: &Spotify, episodes: &Arc>>, query: &str, _offset: usize, @@ -314,7 +314,7 @@ impl SearchResultsView { } fn search_episode( - spotify: &Arc, + spotify: &Spotify, episodes: &Arc>>, query: &str, offset: usize, diff --git a/src/ui/statusbar.rs b/src/ui/statusbar.rs index 9082c46..1f31fa8 100644 --- a/src/ui/statusbar.rs +++ b/src/ui/statusbar.rs @@ -14,7 +14,7 @@ use crate::spotify::{PlayerEvent, Spotify}; pub struct StatusBar { queue: Arc, - spotify: Arc, + spotify: Spotify, library: Arc, last_size: Vec2, use_nerdfont: bool,