From b4234db5016d9eba297926bda18e6da3b10be825 Mon Sep 17 00:00:00 2001 From: canisminor1990 Date: Wed, 27 Sep 2023 11:08:05 +0800 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20refactor:=20Use=20hook=20t?= =?UTF-8?q?o=20check=20PWA=20env?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 12 ++++++------ src/app/layout.tsx | 2 +- src/app/metadata.ts | 2 +- src/hooks/useIsPWA.ts | 15 +++++++++++++++ src/layout/AppLayout.tsx | 6 +++--- 5 files changed, 26 insertions(+), 11 deletions(-) create mode 100644 src/hooks/useIsPWA.ts diff --git a/package.json b/package.json index 046a108998a2..d149a97c0401 100644 --- a/package.json +++ b/package.json @@ -68,8 +68,8 @@ "@emoji-mart/data": "^1", "@emoji-mart/react": "^1", "@icons-pack/react-simple-icons": "^9", - "@lobehub/chat-plugin-sdk": "^1.17.7", - "@lobehub/chat-plugins-gateway": "^1.5.3", + "@lobehub/chat-plugin-sdk": "latest", + "@lobehub/chat-plugins-gateway": "latest", "@lobehub/ui": "latest", "@vercel/analytics": "^1", "ahooks": "^3", @@ -88,16 +88,16 @@ "lucide-react": "latest", "nanoid": "^5", "next": "^13.5.3", - "openai": "^4.10.0", + "openai": "^4", "polished": "^4", "react": "^18", "react-dom": "^18", "react-hotkeys-hook": "^4", "react-i18next": "^13", "react-intersection-observer": "^9", - "react-layout-kit": "^1.7.4", + "react-layout-kit": "^1", "swr": "^2", - "systemjs": "^6.14.2", + "systemjs": "^6", "ts-md5": "^1", "url-join": "^5", "use-merge-value": "^1", @@ -118,7 +118,7 @@ "@types/node": "^20", "@types/react": "^18", "@types/react-dom": "^18", - "@types/systemjs": "^6.13.3", + "@types/systemjs": "^6", "@types/uuid": "^9", "@umijs/lint": "^4", "@vitest/coverage-v8": "latest", diff --git a/src/app/layout.tsx b/src/app/layout.tsx index de2be3cf41d5..87bdb9684d67 100644 --- a/src/app/layout.tsx +++ b/src/app/layout.tsx @@ -19,7 +19,7 @@ const RootLayout = ({ children }: PropsWithChildren) => { const primaryColor = cookieStore.get(LOBE_THEME_PRIMARY_COLOR); return ( - + { + const [isPWA, setIsPWA] = useState(false); + + useEffect(() => { + const isInStandaloneMode = () => + 'standalone' in window.navigator && window.navigator['standalone']; + if (isInStandaloneMode()) { + setIsPWA(true); + } + }, []); + + return isPWA; +}; diff --git a/src/layout/AppLayout.tsx b/src/layout/AppLayout.tsx index 87384ea5a3c9..76b78a585199 100644 --- a/src/layout/AppLayout.tsx +++ b/src/layout/AppLayout.tsx @@ -3,15 +3,15 @@ import { PropsWithChildren, memo } from 'react'; import { Flexbox } from 'react-layout-kit'; import SideBar from '@/features/SideBar'; - -const isPwa = window.matchMedia('(display-mode: standalone)').matches; +import { useIsPWA } from '@/hooks/useIsPWA'; const AppLayout = memo(({ children }) => { + const isPWA = useIsPWA(); const theme = useTheme(); return (