diff --git a/src/backend/extension/messaging.ts b/src/backend/extension/messaging.ts index 6d1f32fd..2e2747c1 100644 --- a/src/backend/extension/messaging.ts +++ b/src/backend/extension/messaging.ts @@ -34,17 +34,23 @@ function sendMessage( } export async function sendExtensionRequest( - ops: Omit, + ops: MessagesMetadata["makeRequest"]["req"], ): Promise | null> { return sendMessage("makeRequest", ops); } export async function setDomainRule( - ops: Omit, + ops: MessagesMetadata["prepareStream"]["req"], ): Promise { return sendMessage("prepareStream", ops); } +export async function sendPage( + ops: MessagesMetadata["openPage"]["req"], +): Promise { + return sendMessage("openPage", ops); +} + export async function extensionInfo(): Promise< MessagesMetadata["hello"]["res"] | null > { diff --git a/src/backend/extension/plasmo.ts b/src/backend/extension/plasmo.ts index 12222b22..c13898be 100644 --- a/src/backend/extension/plasmo.ts +++ b/src/backend/extension/plasmo.ts @@ -12,6 +12,7 @@ export type ExtensionBaseResponse = export type ExtensionHelloResponse = ExtensionBaseResponse<{ version: string; allowed: boolean; + hasPermission: boolean; }>; export interface ExtensionMakeRequest extends ExtensionBaseRequest { @@ -50,6 +51,13 @@ export interface MmMetadata { req: ExtensionPrepareStreamRequest; res: ExtensionBaseResponse; }; + openPage: { + req: ExtensionBaseRequest & { + page: string; + redirectUrl: string; + }; + res: ExtensionBaseResponse; + }; } interface MpMetadata {} diff --git a/src/pages/parts/player/MetaPart.tsx b/src/pages/parts/player/MetaPart.tsx index 6d5b64ef..fb40379a 100644 --- a/src/pages/parts/player/MetaPart.tsx +++ b/src/pages/parts/player/MetaPart.tsx @@ -3,7 +3,8 @@ import { useNavigate, useParams } from "react-router-dom"; import { useAsync } from "react-use"; import type { AsyncReturnType } from "type-fest"; -import { isExtensionActive } from "@/backend/extension/messaging"; +import { isAllowedExtensionVersion } from "@/backend/extension/compatibility"; +import { extensionInfo, sendPage } from "@/backend/extension/messaging"; import { fetchMetadata, setCachedMetadata, @@ -43,12 +44,16 @@ export function MetaPart(props: MetaPartProps) { const navigate = useNavigate(); const { error, value, loading } = useAsync(async () => { - // check extension - const isActive = await isExtensionActive(); + const info = await extensionInfo(); + const isAllowed = info?.success && isAllowedExtensionVersion(info.version); + + if (isAllowed) { + if (!info.hasPermission) throw new Error("extension-no-permission"); + } // use api metadata or providers metadata const providerApiUrl = getLoadbalancedProviderApiUrl(); - if (providerApiUrl && !isActive) { + if (providerApiUrl && !isAllowed) { try { await fetchMetadata(providerApiUrl); } catch (err) { @@ -105,6 +110,36 @@ export function MetaPart(props: MetaPartProps) { props.onGetMeta?.(meta, epId); }, []); + if (error && error.message === "extension-no-permission") { + return ( + + + + {t("player.metadata.failed.badge")} + + Configure the extension + + You have the browser extension, but we need your permission to get + started using the extension. + + + + + ); + } + if (error && error.message === "dmca") { return (