Prompt regular browser
All checks were successful
Publish Docker Image / Publish Docker Image (push) Successful in 5s

This commit is contained in:
2025-07-28 18:29:17 -04:00
parent 44cbc48860
commit 94a35b1ea6
2 changed files with 52 additions and 1 deletions

View File

@@ -0,0 +1,34 @@
// https://github.com/f2etw/detect-inapp/blob/master/src/inapp.js
import { findKey } from "lodash";
const BROWSER = {
messenger: /\bFB[\w_]+\/(Messenger|MESSENGER)/,
facebook: /\bFB[\w_]+\//,
twitter: /\bTwitter/i,
line: /\bLine\//i,
wechat: /\bMicroMessenger\//i,
puffin: /\bPuffin/i,
miui: /\bMiuiBrowser\//i,
instagram: /\bInstagram/i,
chrome: /\bCrMo\b|CriOS|Android.*Chrome\/[.0-9]* (Mobile)?/,
safari: /Version.*Mobile.*Safari|Safari.*Mobile|MobileSafari/,
ie: /IEMobile|MSIEMobile/,
firefox:
/fennec|firefox.*maemo|(Mobile|Tablet).*Firefox|Firefox.*Mobile|FxiOS/,
};
export const useInAppBrowser = (): boolean => {
const userAgent =
navigator.userAgent ||
navigator.vendor ||
(window as unknown as { opera: string }).opera;
const rules = ["WebView", "(iPhone|iPod|iPad)(?!.*Safari/)", "Android.*(wv)"];
const regex = new RegExp(`(${rules.join("|")})`, "ig");
return (
Boolean(userAgent.match(regex)) &&
findKey(BROWSER, (regex) => regex.test(userAgent)) !== undefined
);
};

View File

@@ -32,7 +32,7 @@ import round from "lodash/round";
import Stack from "@/util/stack";
import isMobile from "@/util/isMobile";
import { Canvas } from "@react-three/fiber";
import { mdiArrowLeftBold, mdiOpenInNew } from "@mdi/js";
import { mdiArrowLeftBold, mdiClose, mdiOpenInNew } from "@mdi/js";
import { Icon } from "@mdi/react";
import { PDF } from "../util/PDF";
import { CellphoneUI } from "../ui/CellphoneUI";
@@ -48,6 +48,7 @@ import { useWindowSize } from "../hooks/useWindowSize";
import { Info } from "../util/Info";
import { Loader } from "../ui/Loader";
import { MobileMenu } from "../ui/MobileMenu";
import { useInAppBrowser } from "../hooks/useInAppBrowser";
const AnimatedText = threeAnimated(Text);
const AnimatedCam = threeAnimated(PerspectiveCamera);
@@ -60,10 +61,12 @@ export function Scene(props: JSX.IntrinsicElements["group"]) {
const { width, height } = useWindowSize();
const config = useConfig();
const mobile = isMobile();
const isInAppBrowser = useInAppBrowser();
// States
const [fps, setFps] = useState(0);
const [dpr, setDpr] = useState(2);
const [warningDismissed, setWarningDismissed] = useState(false);
const [pendingView, setPendingView] = useState<View | null>(null);
const [backHovered, setBackHovered] = useState(false);
const [backClicked, setBackClicked] = useState(false);
@@ -174,6 +177,20 @@ export function Scene(props: JSX.IntrinsicElements["group"]) {
/>
</AnimatedButton>
)}
{!warningDismissed && isInAppBrowser ? (
<div className="absolute top-0 right-0 bg-amber-500 m-3 p-2 rounded-xl flex gap-2 items-center justify-between">
<p className="text-black text-md">
For the best experience, please open this page in a regular
browser
</p>
<button
className="transition-all duration-300 pointer-events-auto hover:scale-110 hover:bg-amber-600 rounded-lg"
onClick={() => setWarningDismissed(true)}
>
<Icon path={mdiClose} color="black" className="size-6" />
</button>
</div>
) : null}
<div className="min-w-12 text-white bottom-0 right-0 absolute m-3 p-1 text-xs text-right text-stroke-2 text-stroke-black paint-sfm">
<Info />
{fps > 0 && (