mirror of
https://github.com/movie-web/movie-web.git
synced 2024-12-26 16:51:51 +01:00
Detect browser for extension
This commit is contained in:
parent
8abcd6c43a
commit
e1c09225ee
@ -38,6 +38,7 @@
|
|||||||
"@types/node-forge": "^1.3.10",
|
"@types/node-forge": "^1.3.10",
|
||||||
"classnames": "^2.3.2",
|
"classnames": "^2.3.2",
|
||||||
"core-js": "^3.34.0",
|
"core-js": "^3.34.0",
|
||||||
|
"detect-browser": "^5.3.0",
|
||||||
"dompurify": "^3.0.6",
|
"dompurify": "^3.0.6",
|
||||||
"flag-icons": "^7.1.0",
|
"flag-icons": "^7.1.0",
|
||||||
"focus-trap-react": "^10.2.3",
|
"focus-trap-react": "^10.2.3",
|
||||||
|
7
pnpm-lock.yaml
generated
7
pnpm-lock.yaml
generated
@ -48,6 +48,9 @@ dependencies:
|
|||||||
core-js:
|
core-js:
|
||||||
specifier: ^3.34.0
|
specifier: ^3.34.0
|
||||||
version: 3.34.0
|
version: 3.34.0
|
||||||
|
detect-browser:
|
||||||
|
specifier: ^5.3.0
|
||||||
|
version: 5.3.0
|
||||||
dompurify:
|
dompurify:
|
||||||
specifier: ^3.0.6
|
specifier: ^3.0.6
|
||||||
version: 3.0.6
|
version: 3.0.6
|
||||||
@ -3338,6 +3341,10 @@ packages:
|
|||||||
resolution: {integrity: sha512-M1Ob1zPSIvlARiJUkKqvAZ3VAqQY6Jcuth/pBKQ2b1dX/Qx0OnJ8Vux6J2H5PTMQeRzWrrbTu70VxBfv/OPDJA==}
|
resolution: {integrity: sha512-M1Ob1zPSIvlARiJUkKqvAZ3VAqQY6Jcuth/pBKQ2b1dX/Qx0OnJ8Vux6J2H5PTMQeRzWrrbTu70VxBfv/OPDJA==}
|
||||||
dev: false
|
dev: false
|
||||||
|
|
||||||
|
/detect-browser@5.3.0:
|
||||||
|
resolution: {integrity: sha512-53rsFbGdwMwlF7qvCt0ypLM5V5/Mbl0szB7GPN8y9NCcbknYOeVVXdrXEq+90IwAfrrzt6Hd+u2E2ntakICU8w==}
|
||||||
|
dev: false
|
||||||
|
|
||||||
/didyoumean@1.2.2:
|
/didyoumean@1.2.2:
|
||||||
resolution: {integrity: sha512-gxtyfqMg7GKyhQmb056K7M3xszy/myH8w+B4RT+QXBQsvAOdc3XymqDDPHx1BgPgsdAA5SIifona89YtRATDzw==}
|
resolution: {integrity: sha512-gxtyfqMg7GKyhQmb056K7M3xszy/myH8w+B4RT+QXBQsvAOdc3XymqDDPHx1BgPgsdAA5SIifona89YtRATDzw==}
|
||||||
dev: true
|
dev: true
|
||||||
|
@ -232,7 +232,7 @@
|
|||||||
"downloadSubtitle": "Download current subtitle",
|
"downloadSubtitle": "Download current subtitle",
|
||||||
"downloadPlaylist": "Download playlist",
|
"downloadPlaylist": "Download playlist",
|
||||||
"downloadVideo": "Download video",
|
"downloadVideo": "Download video",
|
||||||
"hlsDisclaimer": "Downloads are taken directly from the provider. movie-web does not have control over how the downloads are provided.<br /><br />Please note that you are downloading an HLS playlist, it is <bold>not recommended to download if you are not familiar with advanced streaming formats</bold>. Try different sources for different formats.",
|
"hlsDisclaimer": "Downloads are taken directly from the provider. movie-web does not have control over how the downloads are provided.<br /><br />Please note that you are downloading an HLS playlist, <bold>it is not recommended to download if you are not familiar with advanced streaming formats</bold>. Try different sources for different formats.",
|
||||||
"onAndroid": {
|
"onAndroid": {
|
||||||
"1": "To download on Android, click the download button then, on the new page, <bold>tap and hold</bold> on the video, then select <bold>save</bold>.",
|
"1": "To download on Android, click the download button then, on the new page, <bold>tap and hold</bold> on the video, then select <bold>save</bold>.",
|
||||||
"shortTitle": "Download / Android",
|
"shortTitle": "Download / Android",
|
||||||
@ -506,8 +506,10 @@
|
|||||||
"extension": {
|
"extension": {
|
||||||
"title": "Let's start with an extension",
|
"title": "Let's start with an extension",
|
||||||
"explainer": "Using the browser extension, you can get the best streams we have to offer. With just a simple install.",
|
"explainer": "Using the browser extension, you can get the best streams we have to offer. With just a simple install.",
|
||||||
|
"explainerIos": "Unfortunately, the browser extension is not supported on IOS, Press <bold>Go back</bold> to choose another option.",
|
||||||
"extensionHelp": "If you've installed the extension but it's not detected. <bold>Open the extension through your browsers extension menu</bold> and follow the steps on screen.",
|
"extensionHelp": "If you've installed the extension but it's not detected. <bold>Open the extension through your browsers extension menu</bold> and follow the steps on screen.",
|
||||||
"link": "Install extension",
|
"linkChrome": "Install Chrome extension",
|
||||||
|
"linkFirefox": "Install Firefox extension",
|
||||||
"back": "Go back",
|
"back": "Go back",
|
||||||
"status": {
|
"status": {
|
||||||
"loading": "Waiting for you to install the extension",
|
"loading": "Waiting for you to install the extension",
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { ReactNode } from "react";
|
import { ReactNode, useMemo } from "react";
|
||||||
import { Trans, useTranslation } from "react-i18next";
|
import { Trans, useTranslation } from "react-i18next";
|
||||||
import { useAsyncFn, useInterval } from "react-use";
|
import { useAsyncFn, useInterval } from "react-use";
|
||||||
|
|
||||||
@ -18,6 +18,10 @@ import {
|
|||||||
import { Card, Link } from "@/pages/onboarding/utils";
|
import { Card, Link } from "@/pages/onboarding/utils";
|
||||||
import { PageTitle } from "@/pages/parts/util/PageTitle";
|
import { PageTitle } from "@/pages/parts/util/PageTitle";
|
||||||
import { conf } from "@/setup/config";
|
import { conf } from "@/setup/config";
|
||||||
|
import {
|
||||||
|
ExtensionDetectionResult,
|
||||||
|
detectExtensionInstall,
|
||||||
|
} from "@/utils/detectFeatures";
|
||||||
|
|
||||||
type ExtensionStatus =
|
type ExtensionStatus =
|
||||||
| "unknown"
|
| "unknown"
|
||||||
@ -40,6 +44,7 @@ async function getExtensionState(): Promise<ExtensionStatus> {
|
|||||||
export function ExtensionStatus(props: {
|
export function ExtensionStatus(props: {
|
||||||
status: ExtensionStatus;
|
status: ExtensionStatus;
|
||||||
loading: boolean;
|
loading: boolean;
|
||||||
|
showHelp?: boolean;
|
||||||
}) {
|
}) {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
|
|
||||||
@ -88,19 +93,119 @@ export function ExtensionStatus(props: {
|
|||||||
{content}
|
{content}
|
||||||
</div>
|
</div>
|
||||||
</Card>
|
</Card>
|
||||||
<Card className="mt-4">
|
{props.showHelp ? (
|
||||||
<div className="flex items-center space-x-7">
|
<Card className="mt-4">
|
||||||
<Icon icon={Icons.WARNING} className="text-type-danger text-2xl" />
|
<div className="flex items-center space-x-7">
|
||||||
<p className="flex-1">
|
<Icon icon={Icons.WARNING} className="text-type-danger text-2xl" />
|
||||||
<Trans
|
<p className="flex-1">
|
||||||
i18nKey="onboarding.extension.extensionHelp"
|
<Trans
|
||||||
components={{
|
i18nKey="onboarding.extension.extensionHelp"
|
||||||
bold: <span className="text-white" />,
|
components={{
|
||||||
}}
|
bold: <span className="text-white" />,
|
||||||
/>
|
}}
|
||||||
</p>
|
/>
|
||||||
</div>
|
</p>
|
||||||
</Card>
|
</div>
|
||||||
|
</Card>
|
||||||
|
) : null}
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
interface ExtensionPageProps {
|
||||||
|
status: ExtensionStatus;
|
||||||
|
loading: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
function ChromeExtensionPage(props: ExtensionPageProps) {
|
||||||
|
const { t } = useTranslation();
|
||||||
|
const installLink = conf().ONBOARDING_EXTENSION_INSTALL_LINK;
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<Heading2 className="!mt-0 !text-3xl max-w-[435px]">
|
||||||
|
{t("onboarding.extension.title")}
|
||||||
|
</Heading2>
|
||||||
|
<Paragraph className="max-w-[320px] mb-4">
|
||||||
|
{t("onboarding.extension.explainer")}
|
||||||
|
</Paragraph>
|
||||||
|
{installLink ? (
|
||||||
|
<Link href={installLink} target="_blank" className="mb-12">
|
||||||
|
{t("onboarding.extension.linkChrome")}
|
||||||
|
</Link>
|
||||||
|
) : null}
|
||||||
|
|
||||||
|
<ExtensionStatus status={props.status} loading={props.loading} />
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function FirefoxExtensionPage(props: ExtensionPageProps) {
|
||||||
|
const { t } = useTranslation();
|
||||||
|
const installLink = conf().ONBOARDING_EXTENSION_INSTALL_LINK;
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<Heading2 className="!mt-0 !text-3xl max-w-[435px]">
|
||||||
|
{t("onboarding.extension.title")}
|
||||||
|
</Heading2>
|
||||||
|
<Paragraph className="max-w-[320px] mb-4">
|
||||||
|
{t("onboarding.extension.explainer")}
|
||||||
|
</Paragraph>
|
||||||
|
{installLink ? (
|
||||||
|
<Link href={installLink} target="_blank" className="mb-12">
|
||||||
|
{t("onboarding.extension.linkFirefox")}
|
||||||
|
</Link>
|
||||||
|
) : null}
|
||||||
|
|
||||||
|
<ExtensionStatus status={props.status} loading={props.loading} showHelp />
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function IosExtensionPage(_props: ExtensionPageProps) {
|
||||||
|
const { t } = useTranslation();
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<Heading2 className="!mt-0 !text-3xl max-w-[435px]">
|
||||||
|
{t("onboarding.extension.title")}
|
||||||
|
</Heading2>
|
||||||
|
<Paragraph className="max-w-[320px] mb-4">
|
||||||
|
<Trans
|
||||||
|
i18nKey="onboarding.extension.explainerIos"
|
||||||
|
components={{ bold: <span className="text-white font-bold" /> }}
|
||||||
|
/>
|
||||||
|
</Paragraph>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function UnknownExtensionPage(props: ExtensionPageProps) {
|
||||||
|
const { t } = useTranslation();
|
||||||
|
const installChromeLink = conf().ONBOARDING_EXTENSION_INSTALL_LINK;
|
||||||
|
const installFirefoxLink = conf().ONBOARDING_EXTENSION_INSTALL_LINK;
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<Heading2 className="!mt-0 !text-3xl max-w-[435px]">
|
||||||
|
{t("onboarding.extension.title")}
|
||||||
|
</Heading2>
|
||||||
|
<Paragraph className="max-w-[320px] mb-4">
|
||||||
|
{t("onboarding.extension.explainer")}
|
||||||
|
</Paragraph>
|
||||||
|
<div className="mb-4">
|
||||||
|
{installChromeLink ? (
|
||||||
|
<Link href={installChromeLink} target="_blank">
|
||||||
|
{t("onboarding.extension.linkChrome")}
|
||||||
|
</Link>
|
||||||
|
) : null}
|
||||||
|
</div>
|
||||||
|
<div className="mb-12">
|
||||||
|
{installFirefoxLink ? (
|
||||||
|
<Link href={installFirefoxLink} target="_blank">
|
||||||
|
{t("onboarding.extension.linkFirefox")}
|
||||||
|
</Link>
|
||||||
|
) : null}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<ExtensionStatus status={props.status} loading={props.loading} showHelp />
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -109,7 +214,7 @@ export function OnboardingExtensionPage() {
|
|||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const navigate = useNavigateOnboarding();
|
const navigate = useNavigateOnboarding();
|
||||||
const { completeAndRedirect } = useRedirectBack();
|
const { completeAndRedirect } = useRedirectBack();
|
||||||
const installLink = conf().ONBOARDING_EXTENSION_INSTALL_LINK;
|
const extensionSupport = useMemo(() => detectExtensionInstall(), []);
|
||||||
|
|
||||||
const [{ loading, value }, exec] = useAsyncFn(
|
const [{ loading, value }, exec] = useAsyncFn(
|
||||||
async (triggeredManually: boolean = false) => {
|
async (triggeredManually: boolean = false) => {
|
||||||
@ -121,24 +226,23 @@ export function OnboardingExtensionPage() {
|
|||||||
);
|
);
|
||||||
useInterval(exec, 1000);
|
useInterval(exec, 1000);
|
||||||
|
|
||||||
|
const componentMap: Record<
|
||||||
|
ExtensionDetectionResult,
|
||||||
|
typeof UnknownExtensionPage
|
||||||
|
> = {
|
||||||
|
chrome: ChromeExtensionPage,
|
||||||
|
firefox: FirefoxExtensionPage,
|
||||||
|
ios: IosExtensionPage,
|
||||||
|
unknown: UnknownExtensionPage,
|
||||||
|
};
|
||||||
|
const PageContent = componentMap[extensionSupport];
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<MinimalPageLayout>
|
<MinimalPageLayout>
|
||||||
<PageTitle subpage k="global.pages.onboarding" />
|
<PageTitle subpage k="global.pages.onboarding" />
|
||||||
<CenterContainer>
|
<CenterContainer>
|
||||||
<Stepper steps={2} current={2} className="mb-12" />
|
<Stepper steps={2} current={2} className="mb-12" />
|
||||||
<Heading2 className="!mt-0 !text-3xl max-w-[435px]">
|
<PageContent loading={loading} status={value ?? "unknown"} />
|
||||||
{t("onboarding.extension.title")}
|
|
||||||
</Heading2>
|
|
||||||
<Paragraph className="max-w-[320px] mb-4">
|
|
||||||
{t("onboarding.extension.explainer")}
|
|
||||||
</Paragraph>
|
|
||||||
{installLink ? (
|
|
||||||
<Link href={installLink} target="_blank" className="mb-12">
|
|
||||||
{t("onboarding.extension.link")}
|
|
||||||
</Link>
|
|
||||||
) : null}
|
|
||||||
|
|
||||||
<ExtensionStatus status={value ?? "unknown"} loading={loading} />
|
|
||||||
<div className="flex justify-between items-center mt-8">
|
<div className="flex justify-between items-center mt-8">
|
||||||
<Button onClick={() => navigate("/onboarding")} theme="secondary">
|
<Button onClick={() => navigate("/onboarding")} theme="secondary">
|
||||||
{t("onboarding.extension.back")}
|
{t("onboarding.extension.back")}
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
import { detect } from "detect-browser";
|
||||||
import fscreen from "fscreen";
|
import fscreen from "fscreen";
|
||||||
import Hls from "hls.js";
|
import Hls from "hls.js";
|
||||||
|
|
||||||
@ -52,3 +53,26 @@ export function canPlayHlsNatively(video: HTMLVideoElement): boolean {
|
|||||||
if (Hls.isSupported()) return false; // no need to play natively
|
if (Hls.isSupported()) return false; // no need to play natively
|
||||||
return !!video.canPlayType("application/vnd.apple.mpegurl");
|
return !!video.canPlayType("application/vnd.apple.mpegurl");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export type ExtensionDetectionResult =
|
||||||
|
| "unknown" // unknown detection or weird browser
|
||||||
|
| "firefox" // firefox extensions
|
||||||
|
| "chrome" // chrome extension (could be chromium, but still works with chrome extensions)
|
||||||
|
| "ios"; // ios, no extensions
|
||||||
|
|
||||||
|
export function detectExtensionInstall(): ExtensionDetectionResult {
|
||||||
|
const res = detect();
|
||||||
|
|
||||||
|
// not a browser or failed to detect
|
||||||
|
if (res?.type !== "browser") return "unknown";
|
||||||
|
|
||||||
|
if (res.name === "ios" || res.name === "ios-webview") return "ios";
|
||||||
|
if (
|
||||||
|
res.name === "chrome" ||
|
||||||
|
res.name === "chromium-webview" ||
|
||||||
|
res.name === "edge-chromium"
|
||||||
|
)
|
||||||
|
return "chrome";
|
||||||
|
if (res.name === "firefox") return "firefox";
|
||||||
|
return "unknown";
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user