From 1ef045aa42dc499bd207506eabb65fcd9ca62edf Mon Sep 17 00:00:00 2001 From: Violet Caulfield <42452695+anultravioletaurora@users.noreply.github.com> Date: Fri, 5 Sep 2025 06:57:51 -0500 Subject: [PATCH] CarPlay hotfix (#507) Fix CarPlay not loading any data on the home screen --- src/components/CarPlay/Home.tsx | 38 ++++++++++++++++----------- src/components/CarPlay/Navigation.tsx | 4 ++- src/providers/CarPlay/index.tsx | 11 ++++++-- 3 files changed, 34 insertions(+), 19 deletions(-) diff --git a/src/components/CarPlay/Home.tsx b/src/components/CarPlay/Home.tsx index 583ba35e..37cb2790 100644 --- a/src/components/CarPlay/Home.tsx +++ b/src/components/CarPlay/Home.tsx @@ -10,11 +10,21 @@ import { QueueMutation } from '../../providers/Player/interfaces' import { JellifyLibrary } from '../../types/JellifyLibrary' import { Api } from '@jellyfin/sdk' import { networkStatusTypes } from '../Network/internetConnectionWatcher' +import { + RecentlyPlayedArtistsQueryKey, + RecentlyPlayedTracksQueryKey, +} from '../../api/queries/recents/keys' +import { JellifyUser } from '@/src/types/JellifyUser' +import { + FrequentlyPlayedArtistsQueryKey, + FrequentlyPlayedTracksQueryKey, +} from '../../api/queries/frequents/keys' const CarPlayHome = ( library: JellifyLibrary, loadQueue: (mutation: QueueMutation) => void, api: Api | undefined, + user: JellifyUser | undefined, networkStatus: networkStatusTypes | null, deviceProfile: DeviceProfile | undefined, ) => @@ -45,20 +55,18 @@ const CarPlayHome = ( switch (index) { case 0: { // Recent Artists - const artists = queryClient.getQueryData>([ - QueryKeys.RecentlyPlayedArtists, - library?.musicLibraryId, - ]) ?? { pages: [], pageParams: [] } + const artists = queryClient.getQueryData>( + RecentlyPlayedArtistsQueryKey(user, library), + ) ?? { pages: [], pageParams: [] } CarPlay.pushTemplate(ArtistsTemplate(artists.pages.flat())) break } case 1: { // Recent Tracks - const items = queryClient.getQueryData>([ - QueryKeys.RecentlyPlayed, - library?.musicLibraryId, - ]) ?? { pages: [], pageParams: [] } + const items = queryClient.getQueryData>( + RecentlyPlayedTracksQueryKey(user, library), + ) ?? { pages: [], pageParams: [] } CarPlay.pushTemplate( TracksTemplate( items.pages.flat(), @@ -74,20 +82,18 @@ const CarPlayHome = ( case 2: { // Most Played Artists - const artists = queryClient.getQueryData>([ - QueryKeys.FrequentArtists, - library?.musicLibraryId, - ]) ?? { pages: [], pageParams: [] } + const artists = queryClient.getQueryData>( + FrequentlyPlayedArtistsQueryKey(user, library), + ) ?? { pages: [], pageParams: [] } CarPlay.pushTemplate(ArtistsTemplate(artists.pages.flat())) break } case 3: { // On Repeat - const items = queryClient.getQueryData>([ - QueryKeys.FrequentlyPlayed, - library?.musicLibraryId, - ]) ?? { pages: [], pageParams: [] } + const items = queryClient.getQueryData>( + FrequentlyPlayedTracksQueryKey(user, library), + ) ?? { pages: [], pageParams: [] } CarPlay.pushTemplate( TracksTemplate( items.pages.flat(), diff --git a/src/components/CarPlay/Navigation.tsx b/src/components/CarPlay/Navigation.tsx index ff0e46ff..30b38e26 100644 --- a/src/components/CarPlay/Navigation.tsx +++ b/src/components/CarPlay/Navigation.tsx @@ -7,11 +7,13 @@ import { JellifyLibrary } from '../../types/JellifyLibrary' import { Api } from '@jellyfin/sdk' import { networkStatusTypes } from '../Network/internetConnectionWatcher' import { DeviceProfile } from '@jellyfin/sdk/lib/generated-client' +import { JellifyUser } from '@/src/types/JellifyUser' const CarPlayNavigation = ( library: JellifyLibrary, loadQueue: (mutation: QueueMutation) => void, api: Api | undefined, + user: JellifyUser | undefined, networkStatus: networkStatusTypes | null, deviceProfile: DeviceProfile | undefined, ) => @@ -19,7 +21,7 @@ const CarPlayNavigation = ( id: uuid.v4(), title: 'Tabs', templates: [ - CarPlayHome(library, loadQueue, api, networkStatus, deviceProfile), + CarPlayHome(library, loadQueue, api, user, networkStatus, deviceProfile), CarPlayDiscover, ], onTemplateSelect(template, e) {}, diff --git a/src/providers/CarPlay/index.tsx b/src/providers/CarPlay/index.tsx index e21f8405..76b430af 100644 --- a/src/providers/CarPlay/index.tsx +++ b/src/providers/CarPlay/index.tsx @@ -12,7 +12,7 @@ interface CarPlayContext { } const CarPlayContextInitializer = () => { - const { api, library } = useJellifyContext() + const { api, user, library } = useJellifyContext() const [carplayConnected, setCarPlayConnected] = useState(CarPlay ? CarPlay.connected : false) const [networkStatus] = useNetworkStatus() @@ -27,7 +27,14 @@ const CarPlayContextInitializer = () => { if (api && library) { CarPlay.setRootTemplate( - CarPlayNavigation(library, loadNewQueue, api, networkStatus, deviceProfile), + CarPlayNavigation( + library, + loadNewQueue, + api, + user, + networkStatus, + deviceProfile, + ), ) if (Platform.OS === 'ios') {