From f6d1b04e7b3ff75f084132b758f2192e2cbd0346 Mon Sep 17 00:00:00 2001 From: Lars Berger Date: Fri, 22 Nov 2024 14:39:15 +0800 Subject: [PATCH] feat: change title to nullable --- .../providers/media/media-provider-types.ts | 2 +- .../src/providers/media/media_provider.rs | 21 +++++++------------ 2 files changed, 8 insertions(+), 15 deletions(-) diff --git a/packages/client-api/src/providers/media/media-provider-types.ts b/packages/client-api/src/providers/media/media-provider-types.ts index 05362cb9..3ac946e3 100644 --- a/packages/client-api/src/providers/media/media-provider-types.ts +++ b/packages/client-api/src/providers/media/media-provider-types.ts @@ -22,7 +22,7 @@ export interface MediaControlArgs { export interface MediaSession { sessionId: string; - title: string; + title: string | null; artist: string | null; albumTitle: string | null; albumArtist: string | null; diff --git a/packages/desktop/src/providers/media/media_provider.rs b/packages/desktop/src/providers/media/media_provider.rs index 1496d019..707dbfea 100644 --- a/packages/desktop/src/providers/media/media_provider.rs +++ b/packages/desktop/src/providers/media/media_provider.rs @@ -33,7 +33,7 @@ pub struct MediaOutput { #[serde(rename_all = "camelCase")] pub struct MediaSession { pub session_id: String, - pub title: String, + pub title: Option, pub artist: Option, pub album_title: Option, pub album_artist: Option, @@ -49,7 +49,7 @@ impl Default for MediaSession { fn default() -> Self { Self { session_id: "".to_string(), - title: "".to_string(), + title: None, artist: None, album_title: None, album_artist: None, @@ -421,26 +421,19 @@ impl MediaProvider { } /// Emits a `MediaOutput` update through the provider's emitter. + /// + /// Note that at times, GSMTC can have a valid session, but return empty + /// string for all media properties. fn emit_output(&self) { - println!("Emitting output {:?}", self.session_states); - // At times, GSMTC can have a valid session, but return empty string - // for all media properties. Check that we at least have a valid - // title, otherwise, return `None`. let current_session = self .current_session_id .as_ref() - .and_then(|id| { - self - .session_states - .get(id) - .filter(|state| !state.output.title.is_empty()) - }) + .and_then(|id| self.session_states.get(id)) .map(|state| state.output.clone()); let all_sessions = self .session_states .values() - .filter(|state| !state.output.title.is_empty()) .map(|state| state.output.clone()) .collect(); @@ -477,7 +470,7 @@ impl MediaProvider { let album_title = properties.AlbumTitle()?.to_string(); let album_artist = properties.AlbumArtist()?.to_string(); - session_output.title = title; + session_output.title = (!title.is_empty()).then_some(title); session_output.artist = (!artist.is_empty()).then_some(artist); session_output.album_title = (!album_title.is_empty()).then_some(album_title);