(&self)
| 146 | |
| 147 | #[tracing::instrument(level = "debug", skip(self))] |
| 148 | async fn create_api_client(&self) { |
| 149 | tracing::debug!("Creating spotify api client"); |
| 150 | if let Some(token) = self.tokens.lock().await.as_ref() { |
| 151 | tracing::debug!("Got tokens lock"); |
| 152 | *self.api_client.write().await = Some(ApiClient { |
| 153 | api_client: AuthCodePkceSpotify::from_token(Token { |
| 154 | access_token: token.access_token.clone(), |
| 155 | expires_in: TimeDelta::seconds(token.expires_in.try_into().unwrap()), |
| 156 | expires_at: Some(DateTime::from_timestamp_millis(token.expires_at).unwrap()), |
| 157 | refresh_token: Some(token.refresh_token.clone()), |
| 158 | scopes: HashSet::from_iter( |
| 159 | self.config |
| 160 | .lock() |
| 161 | .await |
| 162 | .scopes |
| 163 | .iter() |
| 164 | .map(|v| v.to_string()), |
| 165 | ), |
| 166 | }), |
| 167 | token_expiry: Instant::now() + Duration::from_secs(token.expires_in), |
| 168 | }); |
| 169 | |
| 170 | let res = self.fetch_user_details().await; |
| 171 | let mut is_spotify_premium = false; |
| 172 | if let Ok((res, is_premium)) = res { |
| 173 | let _ = self.status_tx.lock().await.send(res).await; |
| 174 | is_spotify_premium = is_premium; |
| 175 | } else { |
| 176 | let _ = self |
| 177 | .status_tx |
| 178 | .lock() |
| 179 | .await |
| 180 | .send(self.get_provider_status(Some("".into())).await) |
| 181 | .await; |
| 182 | } |
| 183 | |
| 184 | if is_spotify_premium { |
| 185 | tracing::debug!("Initializing librespot"); |
| 186 | if let Err(err) = initialize_librespot(self.app.clone(), token.access_token.clone()) |
| 187 | { |
| 188 | tracing::error!("Error initializing librespot {:?}", err); |
| 189 | } |
| 190 | } |
| 191 | } |
| 192 | } |
| 193 | |
| 194 | async fn get_api_client(&self) -> RwLockReadGuard<'_, Option<ApiClient>> { |
| 195 | if let Some(expired) = self |
no test coverage detected