From 8f69bbb7b1782ed54d0f5b7984e3588f7722637b Mon Sep 17 00:00:00 2001 From: Cooper Ransom Date: Sat, 9 Mar 2024 21:23:06 -0500 Subject: [PATCH] Add a check for extension before asking if its enabled --- src/assets/locales/en.json | 1 + src/pages/parts/player/ScrapeErrorPart.tsx | 53 +++++++++++++++++++--- 2 files changed, 47 insertions(+), 7 deletions(-) diff --git a/src/assets/locales/en.json b/src/assets/locales/en.json index 114bd426..069acaf3 100644 --- a/src/assets/locales/en.json +++ b/src/assets/locales/en.json @@ -416,6 +416,7 @@ "reloadButton": "Try again", "homeButton": "Go home", "text": "We can not find the media you are looking for or no one provides it... Did you enable the extension for this site?", + "text2": "We can not find the media you are looking for or no one provides it...", "title": "We couldn't find that" } }, diff --git a/src/pages/parts/player/ScrapeErrorPart.tsx b/src/pages/parts/player/ScrapeErrorPart.tsx index 4824fef3..532dc630 100644 --- a/src/pages/parts/player/ScrapeErrorPart.tsx +++ b/src/pages/parts/player/ScrapeErrorPart.tsx @@ -1,7 +1,9 @@ -import { useMemo } from "react"; +import { useEffect, useMemo, useState } from "react"; import { Trans, useTranslation } from "react-i18next"; import { useLocation } from "react-router-dom"; +import { isAllowedExtensionVersion } from "@/backend/extension/compatibility"; +import { extensionInfo } from "@/backend/extension/messaging"; import { Button } from "@/components/buttons/Button"; import { Icons } from "@/components/Icon"; import { IconPill } from "@/components/layout/IconPill"; @@ -14,6 +16,14 @@ import { getProviderApiUrls } from "@/utils/proxyUrls"; import { ErrorCardInModal } from "../errors/ErrorCard"; +type ExtensionStatus = + | "unknown" + | "failed" + | "disallowed" + | "noperms" + | "outdated" + | "success"; + export interface ScrapeErrorPartProps { data: { sources: Record; @@ -21,10 +31,22 @@ export interface ScrapeErrorPartProps { }; } +async function getExtensionState(): Promise { + const info = await extensionInfo(); + if (!info) return "unknown"; // cant talk to extension + if (!info.success) return "failed"; // extension failed to respond + if (!info.allowed) return "disallowed"; // extension is not enabled on this page + if (!info.hasPermission) return "noperms"; // extension has no perms to do it's tasks + if (!isAllowedExtensionVersion(info.version)) return "outdated"; // extension is too old + return "success"; // no problems +} + export function ScrapeErrorPart(props: ScrapeErrorPartProps) { const { t } = useTranslation(); const modal = useModal("error"); const location = useLocation(); + const [extensionState, setExtensionState] = + useState("unknown"); const error = useMemo(() => { const data = props.data; @@ -42,6 +64,10 @@ export function ScrapeErrorPart(props: ScrapeErrorPartProps) { return str; }, [props, location]); + useEffect(() => { + getExtensionState().then(setExtensionState); + }, []); + return ( @@ -50,12 +76,25 @@ export function ScrapeErrorPart(props: ScrapeErrorPartProps) { {t("player.scraping.notFound.title")} - , - }} - /> + {extensionState === "disallowed" ? ( + + ), + }} + /> + ) : ( + + ), + }} + /> + )}