MCPcopy Index your code
hub / github.com/LabyStudio/java-spotify-api / get_spotify_session

Function get_spotify_session

rust/src/session.rs:28–59  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

26}
27
28pub fn get_spotify_session() -> Result<Option<GlobalSystemMediaTransportControlsSession>> {
29 let mut cache = SPOTIFY_SESSION_CACHE.lock().unwrap();
30
31 // Check cache expiration and validity
32 if let Some(cached) = cache.as_ref() {
33 if cached.timestamp.elapsed() < CACHE_TTL && is_spotify(&cached.session)? {
34 return Ok(Some(cached.session.clone()));
35 }
36 // Cache expired or invalid, drop it
37 *cache = None;
38 }
39
40 // Refresh the session cache
41 let manager_operation = GlobalSystemMediaTransportControlsSessionManager::RequestAsync()?;
42 let manager = manager_operation.get()?;
43 let sessions = manager.GetSessions()?;
44
45 for session in sessions {
46 if is_spotify(&session)? {
47 // Cache new session with current timestamp
48 *cache = Some(CachedSession {
49 session: session.clone(),
50 timestamp: Instant::now(),
51 });
52 return Ok(Some(session));
53 }
54 }
55
56 // No valid session found
57 *cache = None;
58 Ok(None)
59}

Callers 8

mainFunction · 0.85
isSpotifyAvailableFunction · 0.85
getPlaybackPositionFunction · 0.85
getTrackDurationFunction · 0.85
getTrackTitleFunction · 0.85
getArtistNameFunction · 0.85
isPlayingFunction · 0.85
getCoverArtFunction · 0.85

Calls 2

is_spotifyFunction · 0.85
getMethod · 0.45

Tested by

no test coverage detected