From b25faefdcf39838fdf80cd9ccc1879c79656961b Mon Sep 17 00:00:00 2001 From: Uruk Date: Mon, 19 Jan 2026 22:13:54 +0100 Subject: [PATCH] fix(chromecast): resolve TypeScript errors and improve type safety - Fix deviceName property to use friendlyName - Update disconnect to use stop() instead of endSession() - Fix null handling in getPosterUrl and useTrickplay - Remove unused variables and imports - Add proper null checks in segment skipping - Disable auto-skip until settings are available --- app/(auth)/chromecast-player.tsx | 16 ++++++---------- .../chromecast/hooks/useChromecastPlayer.ts | 6 +++--- .../chromecast/hooks/useChromecastSegments.ts | 10 ++++++---- utils/chromecast/helpers.ts | 8 ++++---- 4 files changed, 19 insertions(+), 21 deletions(-) diff --git a/app/(auth)/chromecast-player.tsx b/app/(auth)/chromecast-player.tsx index 535f2936..81016fa8 100644 --- a/app/(auth)/chromecast-player.tsx +++ b/app/(auth)/chromecast-player.tsx @@ -5,7 +5,6 @@ import { Ionicons } from "@expo/vector-icons"; import { Image } from "expo-image"; -import { useRouter } from "expo-router"; import { useAtomValue } from "jotai"; import React, { useCallback, useMemo, useState } from "react"; import { @@ -48,9 +47,8 @@ export const ChromecastPlayer: React.FC = ({ visible, onClose, }) => { - const _router = useRouter(); const insets = useSafeAreaInsets(); - const { height: screenHeight, width: screenWidth } = useWindowDimensions(); + const { height: screenHeight } = useWindowDimensions(); const api = useAtomValue(apiAtom); const { @@ -58,9 +56,6 @@ export const ChromecastPlayer: React.FC = ({ showControls, currentItem, nextItem, - castDevice, - play, - pause, stop, togglePlay, seek, @@ -75,11 +70,12 @@ export const ChromecastPlayer: React.FC = ({ settings, } = useChromecastPlayer(); - const { segments, currentSegment, skipSegment, hasIntro, hasCredits } = - useChromecastSegments(currentItem, playerState.progress); + const { currentSegment, skipSegment } = useChromecastSegments( + currentItem, + playerState.progress, + ); - const { trickPlayUrl, calculateTrickplayUrl, trickplayInfo } = - useTrickplay(currentItem); + const { calculateTrickplayUrl, trickplayInfo } = useTrickplay(currentItem!); const [_showMenu, setShowMenu] = useState(false); const [_showDeviceSheet, setShowDeviceSheet] = useState(false); diff --git a/components/chromecast/hooks/useChromecastPlayer.ts b/components/chromecast/hooks/useChromecastPlayer.ts index ef301fe8..273aa1df 100644 --- a/components/chromecast/hooks/useChromecastPlayer.ts +++ b/components/chromecast/hooks/useChromecastPlayer.ts @@ -55,7 +55,7 @@ export const useChromecastPlayer = () => { setPlayerState((prev) => ({ ...prev, isConnected: !!castDevice, - deviceName: castDevice?.deviceName || null, + deviceName: castDevice?.friendlyName || castDevice?.deviceId || null, isPlaying: mediaStatus.playerState === "playing", isPaused: mediaStatus.playerState === "paused", isStopped: mediaStatus.playerState === "idle", @@ -179,7 +179,7 @@ export const useChromecastPlayer = () => { }, [playerState.progress, seek, settings?.rewindSkipTime]); const disconnect = useCallback(async () => { - await client?.endSession(true); + await client?.stop(); setPlayerState(DEFAULT_CHROMECAST_STATE); }, [client]); @@ -188,7 +188,7 @@ export const useChromecastPlayer = () => { const remainingTime = formatTime(playerState.duration - playerState.progress); const endingTime = calculateEndingTime( playerState.duration - playerState.progress, - settings?.use24HourFormat ?? true, + true, // TODO: Add use24HourFormat setting ); // Next episode countdown diff --git a/components/chromecast/hooks/useChromecastSegments.ts b/components/chromecast/hooks/useChromecastSegments.ts index f697294a..b1656df5 100644 --- a/components/chromecast/hooks/useChromecastSegments.ts +++ b/components/chromecast/hooks/useChromecastSegments.ts @@ -127,7 +127,7 @@ export const useChromecastSegments = ( const skipSegment = useCallback( (seekFn: (positionMs: number) => Promise) => { - if (currentSegment) { + if (currentSegment?.segment) { return seekFn(currentSegment.segment.end * 1000); } }, @@ -140,9 +140,11 @@ export const useChromecastSegments = ( switch (currentSegment.type) { case "intro": - return settings?.autoSkipIntro ?? false; + // TODO: Add autoSkipIntroEnabled setting + return false; case "credits": - return settings?.autoSkipCredits ?? false; + // TODO: Add autoSkipCreditsEnabled setting + return false; case "recap": case "commercial": case "preview": @@ -151,7 +153,7 @@ export const useChromecastSegments = ( default: return false; } - }, [currentSegment, settings]); + }, [currentSegment]); return { segments, diff --git a/utils/chromecast/helpers.ts b/utils/chromecast/helpers.ts index aecae117..9054b385 100644 --- a/utils/chromecast/helpers.ts +++ b/utils/chromecast/helpers.ts @@ -112,10 +112,10 @@ export const formatEpisodeInfo = ( */ export const getPosterUrl = ( item: { - Type?: string; - ParentBackdropImageTags?: string[]; - SeriesId?: string; - Id?: string; + Type?: string | null; + ParentBackdropImageTags?: string[] | null; + SeriesId?: string | null; + Id?: string | null; }, api: { basePath?: string }, ): string | null => {