@@ -7,17 +7,25 @@ lazy_static! {
77 static ref SPOTIFY_SESSION_CACHE : Mutex <Option <GlobalSystemMediaTransportControlsSession >> = Mutex :: new( None ) ;
88}
99
10+ pub fn is_spotify ( session : & GlobalSystemMediaTransportControlsSession ) -> Result < bool > {
11+ let app_id = session. SourceAppUserModelId ( ) ?;
12+ let app_id = app_id. to_string ( ) ;
13+
14+ Ok (
15+ app_id == "Spotify.exe" ||
16+ ( app_id. starts_with ( "SpotifyAB" ) && app_id. ends_with ( "!Spotify" ) )
17+ )
18+ }
19+
1020pub fn get_spotify_session ( ) -> Result < Option < GlobalSystemMediaTransportControlsSession > > {
1121 let mut cache = SPOTIFY_SESSION_CACHE . lock ( ) . unwrap ( ) ;
1222
1323 if let Some ( session) = cache. as_ref ( ) {
1424 // Validate cached session
15- if let Ok ( app_id) = session. SourceAppUserModelId ( ) {
16- if app_id == "Spotify.exe" {
17- // Session still valid
18- return Ok ( Some ( session. clone ( ) ) ) ;
19- }
25+ if is_spotify ( session) ? {
26+ return Ok ( Some ( session. clone ( ) ) ) ;
2027 }
28+
2129 // Session invalid: clear cache
2230 * cache = None ;
2331 }
@@ -28,8 +36,8 @@ pub fn get_spotify_session() -> Result<Option<GlobalSystemMediaTransportControls
2836 let sessions = manager. GetSessions ( ) ?;
2937
3038 for session in sessions {
31- let source_app_id = session . SourceAppUserModelId ( ) ? ;
32- if source_app_id == " Spotify.exe" {
39+ if is_spotify ( & session ) ? {
40+ // Found a valid Spotify session, cache it
3341 * cache = Some ( session. clone ( ) ) ;
3442 return Ok ( Some ( session) ) ;
3543 }
0 commit comments