Skip to content

Commit 1196c75

Browse files
committed
check for Spotify Windows app
1 parent 9d38b79 commit 1196c75

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

rust/src/session.rs

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
1020
pub 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
}

src/main/java/de/labystudio/spotifyapi/platform/windows/WinSpotifyAPI.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ public int getPosition() {
139139

140140
@Override
141141
public boolean hasPosition() {
142-
if (this.process == null) {
142+
if (!this.isConnected()) {
143143
return false;
144144
}
145145

0 commit comments

Comments
 (0)