From 9eacf7e203b6ebd36f7cad4c46c64190606b0b2d Mon Sep 17 00:00:00 2001 From: chrox Date: Thu, 5 Dec 2024 12:02:42 +0100 Subject: [PATCH] Don't auto hide scrollbar in platform other than macOS and iOS, closes #9 --- .../src/app/reader/components/FoliateViewer.tsx | 5 ++++- apps/readest-app/src/utils/misc.ts | 12 ++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/apps/readest-app/src/app/reader/components/FoliateViewer.tsx b/apps/readest-app/src/app/reader/components/FoliateViewer.tsx index c0a88e15..e1786ea6 100644 --- a/apps/readest-app/src/app/reader/components/FoliateViewer.tsx +++ b/apps/readest-app/src/app/reader/components/FoliateViewer.tsx @@ -4,6 +4,7 @@ import { BookDoc } from '@/libs/document'; import { BookConfig, BookNote, BookSearchConfig, BookSearchResult } from '@/types/book'; import { useReaderStore } from '@/store/readerStore'; import { useParallelViewStore } from '@/store/parallelViewStore'; +import { getOSPlatform } from '@/utils/misc'; import { getStyles } from '@/utils/style'; import { useTheme } from '@/hooks/useTheme'; import { ONE_COLUMN_MAX_INLINE_SIZE } from '@/services/constants'; @@ -78,6 +79,8 @@ const FoliateViewer: React.FC<{ const { getParallels } = useParallelViewStore(); const { themeCode } = useTheme(); + const shouldAutoHideScrollbar = ['macos', 'ios'].includes(getOSPlatform()); + const progressRelocateHandler = (event: Event) => { const detail = (event as CustomEvent).detail; // console.log('relocate:', detail); @@ -116,7 +119,7 @@ const FoliateViewer: React.FC<{ const detail = (event as CustomEvent).detail; if (detail.doc) { const viewSettings = getViewSettings(bookKey)!; - if (viewSettings.scrolled) { + if (viewSettings.scrolled && shouldAutoHideScrollbar) { handleScrollbarAutoHide(detail.doc); } if (!detail.doc.isEventListenersAdded) { diff --git a/apps/readest-app/src/utils/misc.ts b/apps/readest-app/src/utils/misc.ts index 57fab126..78afca74 100644 --- a/apps/readest-app/src/utils/misc.ts +++ b/apps/readest-app/src/utils/misc.ts @@ -22,3 +22,15 @@ export const makeSafeFilename = (filename: string, replacement = '_') => { return safeName.trim(); }; + +export const getOSPlatform = () => { + const userAgent = navigator.userAgent.toLowerCase(); + + if (userAgent.includes('macintosh') || userAgent.includes('mac os x')) return 'macos'; + if (userAgent.includes('windows nt')) return 'windows'; + if (userAgent.includes('linux')) return 'linux'; + if (/iphone|ipad|ipod/.test(userAgent)) return 'ios'; + if (userAgent.includes('android')) return 'android'; + + return ''; +};