From b3222b130fdc32bddae05a8b92db6cf1fb26d90a Mon Sep 17 00:00:00 2001 From: mrjvs Date: Thu, 18 Jan 2024 19:29:58 +0100 Subject: [PATCH] Fix some thumbnail scraping setting logic Co-authored-by: Jip Frijlink --- src/components/player/base/Container.tsx | 4 +--- src/components/player/hooks/useSourceSelection.ts | 7 ++++--- src/components/player/internals/ThumbnailScraper.tsx | 10 ++++++---- src/hooks/useProviderScrape.tsx | 3 ++- 4 files changed, 13 insertions(+), 11 deletions(-) diff --git a/src/components/player/base/Container.tsx b/src/components/player/base/Container.tsx index a4310ad8..9fc10bff 100644 --- a/src/components/player/base/Container.tsx +++ b/src/components/player/base/Container.tsx @@ -11,7 +11,6 @@ import { VideoClickTarget } from "@/components/player/internals/VideoClickTarget import { VideoContainer } from "@/components/player/internals/VideoContainer"; import { PlayerHoverState } from "@/stores/player/slices/interface"; import { usePlayerStore } from "@/stores/player/store"; -import { usePreferencesStore } from "@/stores/preferences"; export interface PlayerProps { children?: ReactNode; @@ -79,7 +78,6 @@ function BaseContainer(props: { children?: ReactNode }) { export function Container(props: PlayerProps) { const propRef = useRef(props.onLoad); - const enableThumbnails = usePreferencesStore((s) => s.enableThumbnails); useEffect(() => { propRef.current?.(); }, []); @@ -88,7 +86,7 @@ export function Container(props: PlayerProps) {
- {enableThumbnails ? : null} + diff --git a/src/components/player/hooks/useSourceSelection.ts b/src/components/player/hooks/useSourceSelection.ts index 3016e332..3813fa9f 100644 --- a/src/components/player/hooks/useSourceSelection.ts +++ b/src/components/player/hooks/useSourceSelection.ts @@ -5,6 +5,7 @@ import { } from "@movie-web/providers"; import { useAsyncFn } from "react-use"; +import { isExtensionActiveCached } from "@/backend/extension/messaging"; import { prepareStream } from "@/backend/extension/streams"; import { connectServerSideEvents, @@ -72,7 +73,7 @@ export function useEmbedScraping( report([ scrapeSourceOutputToProviderMetric(meta, sourceId, null, "success", null), ]); - await prepareStream(result.stream[0]); + if (isExtensionActiveCached()) await prepareStream(result.stream[0]); setSourceId(sourceId); setCaption(null); setSource( @@ -133,7 +134,7 @@ export function useSourceScraping(sourceId: string | null, routerId: string) { ]); if (result.stream) { - await prepareStream(result.stream[0]); + if (isExtensionActiveCached()) await prepareStream(result.stream[0]); setCaption(null); setSource( convertRunoutputToSource({ stream: result.stream[0] }), @@ -190,7 +191,7 @@ export function useSourceScraping(sourceId: string | null, routerId: string) { ]); setSourceId(sourceId); setCaption(null); - await prepareStream(embedResult.stream[0]); + if (isExtensionActiveCached()) await prepareStream(embedResult.stream[0]); setSource( convertRunoutputToSource({ stream: embedResult.stream[0] }), convertProviderCaption(embedResult.stream[0].captions), diff --git a/src/components/player/internals/ThumbnailScraper.tsx b/src/components/player/internals/ThumbnailScraper.tsx index b0fc8474..cede84c8 100644 --- a/src/components/player/internals/ThumbnailScraper.tsx +++ b/src/components/player/internals/ThumbnailScraper.tsx @@ -5,6 +5,7 @@ import { playerStatus } from "@/stores/player/slices/source"; import { ThumbnailImage } from "@/stores/player/slices/thumbnails"; import { usePlayerStore } from "@/stores/player/store"; import { LoadableSource, selectQuality } from "@/stores/player/utils/qualities"; +import { usePreferencesStore } from "@/stores/preferences"; import { processCdnLink } from "@/utils/cdn"; import { isSafari } from "@/utils/detectFeatures"; @@ -128,6 +129,7 @@ export function ThumbnailScraper() { const resetImages = usePlayerStore((s) => s.thumbnails.resetImages); const meta = usePlayerStore((s) => s.meta); const source = usePlayerStore((s) => s.source); + const enableThumbnails = usePreferencesStore((s) => s.enableThumbnails); const workerRef = useRef(null); // object references dont always trigger changes, so we serialize it to detect *any* change @@ -159,8 +161,8 @@ export function ThumbnailScraper() { // start worker with the stream useEffect(() => { - startRef.current(); - }, [sourceSeralized]); + if (enableThumbnails) startRef.current(); + }, [sourceSeralized, enableThumbnails]); // destroy worker on unmount useEffect(() => { @@ -183,8 +185,8 @@ export function ThumbnailScraper() { workerRef.current.destroy(); workerRef.current = null; } - startRef.current(); - }, [serializedMeta, sourceSeralized, status]); + if (enableThumbnails) startRef.current(); + }, [serializedMeta, sourceSeralized, status, enableThumbnails]); return null; } diff --git a/src/hooks/useProviderScrape.tsx b/src/hooks/useProviderScrape.tsx index fd27c06d..84aeec4e 100644 --- a/src/hooks/useProviderScrape.tsx +++ b/src/hooks/useProviderScrape.tsx @@ -171,7 +171,8 @@ export function useScrape() { conn.on("update", updateEvent); conn.on("discoverEmbeds", discoverEmbedsEvent); const sseOutput = await conn.promise(); - if (sseOutput) await prepareStream(sseOutput.stream); + if (sseOutput && isExtensionActiveCached()) + await prepareStream(sseOutput.stream); return getResult(sseOutput === "" ? null : sseOutput); }