MCPcopy Create free account
hub / github.com/Moosync/Moosync / initialize

Method initialize

src-tauri/src/providers/spotify.rs:373–423  ·  view source on GitHub ↗
(&self)

Source from the content-addressed store, hash-verified

371impl GenericProvider for SpotifyProvider {
372 #[tracing::instrument(level = "debug", skip(self))]
373 async fn initialize(&self) -> Result<()> {
374 let _ = self
375 .status_tx
376 .lock()
377 .await
378 .send(self.get_provider_status(None).await)
379 .await;
380
381 let preferences: State<PreferenceConfig> = self.app.state();
382 let spotify_config: Value = preferences
383 .load_selective("spotify".into())
384 .unwrap_or_default();
385 let client_id = spotify_config.get("client_id");
386 let client_secret = spotify_config.get("client_secret");
387
388 {
389 let mut config = self.config.lock().await;
390 *config = SpotifyConfig {
391 client_id: client_id.map(|v| v.as_str().unwrap().to_string()),
392 client_secret: client_secret.map(|v| v.as_str().unwrap().to_string()),
393 ..Default::default()
394 };
395
396 if config.client_id.as_ref().map_or(true, |id| id.is_empty())
397 || config
398 .client_secret
399 .as_ref()
400 .map_or(true, |secret| secret.is_empty())
401 {
402 config.redirect_uri = "http://127.0.0.1:8898/login";
403 config.client_id = Some("65b708073fc0480ea92a077233ca87bd".into())
404 } else {
405 config.redirect_uri = "https://moosync.app/spotify";
406 }
407 config.scopes = vec![
408 "playlist-read-private",
409 "user-top-read",
410 "user-library-read",
411 "user-read-private",
412 "streaming",
413 "app-remote-control",
414 ];
415 }
416
417 let res = self.refresh_login().await;
418 if let Err(err) = res {
419 tracing::error!("spotify refresh login err: {:?}", err);
420 }
421
422 Ok(())
423 }
424
425 #[tracing::instrument(level = "debug", skip(self))]
426 async fn get_provider_scopes(&self) -> Result<Vec<ExtensionProviderScope>> {

Callers

nothing calls this directly

Calls 5

sendMethod · 0.80
load_selectiveMethod · 0.80
getMethod · 0.80
get_provider_statusMethod · 0.45
refresh_loginMethod · 0.45

Tested by

no test coverage detected