From 797b59a38aceaac686f39ae9f582c95a6a0f468c Mon Sep 17 00:00:00 2001 From: Sped0n Date: Sun, 22 Mar 2026 17:29:11 +0800 Subject: [PATCH] fix: improve mobile device detection reliability Signed-off-by: Sped0n --- assets/ts/main.tsx | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/assets/ts/main.tsx b/assets/ts/main.tsx index cf49e01..207bc4e 100644 --- a/assets/ts/main.tsx +++ b/assets/ts/main.tsx @@ -38,9 +38,14 @@ const Mobile = lazy(async () => await import('./mobile/layout')) function Main(): JSX.Element { // variables const [ijs] = createResource(getImageJSON) - const isMobile = - window.matchMedia('(hover: none)').matches && - !window.navigator.userAgent.includes('Win') + const ua = window.navigator.userAgent.toLowerCase() + const hasTouchInput = 'ontouchstart' in window || window.navigator.maxTouchPoints > 0 + const hasTouchLayout = + window.matchMedia('(pointer: coarse)').matches || + window.matchMedia('(hover: none)').matches + const isMobileUA = /android|iphone|ipad|ipod|mobile/.test(ua) + const isWindowsDesktop = /windows nt/.test(ua) + const isMobile = isMobileUA || (hasTouchInput && hasTouchLayout && !isWindowsDesktop) // states const [scrollable, setScollable] = createSignal(true)