From 2d2ac41c6b8ef40b3f1f1bb55a1d00e83b39957c Mon Sep 17 00:00:00 2001 From: Alexander Zinchuk Date: Sun, 19 Mar 2023 22:31:09 -0500 Subject: [PATCH] App: Disable multitab on mobile PWA (#2806) --- src/components/left/main/Chat.tsx | 4 ++-- src/components/left/main/Topic.tsx | 4 ++-- src/components/left/main/hooks/useTopicContextActions.ts | 4 ++-- src/hooks/useChatContextActions.ts | 7 ++----- src/util/environment.ts | 6 ++++-- 5 files changed, 12 insertions(+), 13 deletions(-) diff --git a/src/components/left/main/Chat.tsx b/src/components/left/main/Chat.tsx index c611fd855..116be18fd 100644 --- a/src/components/left/main/Chat.tsx +++ b/src/components/left/main/Chat.tsx @@ -17,7 +17,7 @@ import type { AnimationLevel } from '../../../types'; import type { ChatAnimationTypes } from './hooks'; import { MAIN_THREAD_ID } from '../../../api/types'; -import { IS_MULTITAB_SUPPORTED } from '../../../util/environment'; +import { IS_OPEN_IN_NEW_TAB_SUPPORTED } from '../../../util/environment'; import { isUserId, getPrivateChatUserId, @@ -223,7 +223,7 @@ const Chat: FC = ({ = ({ )} onClick={handleOpenTopic} style={style} - href={IS_MULTITAB_SUPPORTED ? `#${createLocationHash(chatId, 'thread', topic.id)}` : undefined} + href={IS_OPEN_IN_NEW_TAB_SUPPORTED ? `#${createLocationHash(chatId, 'thread', topic.id)}` : undefined} contextActions={contextActions} ref={ref} > diff --git a/src/components/left/main/hooks/useTopicContextActions.ts b/src/components/left/main/hooks/useTopicContextActions.ts index b5d3ee6c8..ac43dd175 100644 --- a/src/components/left/main/hooks/useTopicContextActions.ts +++ b/src/components/left/main/hooks/useTopicContextActions.ts @@ -6,7 +6,7 @@ import type { MenuItemContextAction } from '../../../ui/ListItem'; import { compact } from '../../../../util/iteratees'; import { getCanManageTopic, getHasAdminRight } from '../../../../global/helpers'; -import { IS_MULTITAB_SUPPORTED } from '../../../../util/environment'; +import { IS_OPEN_IN_NEW_TAB_SUPPORTED } from '../../../../util/environment'; import useLang from '../../../../hooks/useLang'; @@ -37,7 +37,7 @@ export default function useTopicContextActions( const canToggleClosed = getCanManageTopic(chat, topic); const canTogglePinned = chat.isCreator || getHasAdminRight(chat, 'manageTopics'); - const actionOpenInNewTab = IS_MULTITAB_SUPPORTED && { + const actionOpenInNewTab = IS_OPEN_IN_NEW_TAB_SUPPORTED && { title: 'Open in new tab', icon: 'open-in-new-tab', handler: () => { diff --git a/src/hooks/useChatContextActions.ts b/src/hooks/useChatContextActions.ts index 1a34cc80f..27efaba08 100644 --- a/src/hooks/useChatContextActions.ts +++ b/src/hooks/useChatContextActions.ts @@ -4,7 +4,7 @@ import { getActions } from '../global'; import type { ApiChat, ApiUser } from '../api/types'; import type { MenuItemContextAction } from '../components/ui/ListItem'; -import { IS_MULTITAB_SUPPORTED } from '../util/environment'; +import { IS_OPEN_IN_NEW_TAB_SUPPORTED } from '../util/environment'; import { SERVICE_NOTIFICATIONS_USER_ID } from '../config'; import { isChatArchived, getCanDeleteChat, isUserId, isChatChannel, isChatGroup, @@ -51,7 +51,7 @@ const useChatContextActions = ({ openChatInNewTab, } = getActions(); - const actionOpenInNewTab = IS_MULTITAB_SUPPORTED && { + const actionOpenInNewTab = IS_OPEN_IN_NEW_TAB_SUPPORTED && { title: 'Open in new tab', icon: 'open-in-new-tab', handler: () => { @@ -59,8 +59,6 @@ const useChatContextActions = ({ }, }; - const newTabActionSeparator = actionOpenInNewTab && { isSeparator: true, key: 'newTabSeparator' }; - const actionAddToFolder = canChangeFolder ? { title: lang('ChatList.Filter.AddToFolder'), icon: 'folder', @@ -122,7 +120,6 @@ const useChatContextActions = ({ return compact([ actionOpenInNewTab, - newTabActionSeparator, actionAddToFolder, actionMaskAsRead, actionMarkAsUnread, diff --git a/src/util/environment.ts b/src/util/environment.ts index 6ea41c568..bab3eba2a 100644 --- a/src/util/environment.ts +++ b/src/util/environment.ts @@ -39,6 +39,7 @@ export const PLATFORM_ENV = getPlatform(); export const IS_MAC_OS = PLATFORM_ENV === 'macOS'; export const IS_IOS = PLATFORM_ENV === 'iOS'; export const IS_ANDROID = PLATFORM_ENV === 'Android'; +export const IS_MOBILE = IS_IOS || IS_ANDROID; export const IS_SAFARI = /^((?!chrome|android).)*safari/i.test(navigator.userAgent); export const IS_YA_BROWSER = navigator.userAgent.includes('YaBrowser'); @@ -109,15 +110,16 @@ export const IS_OFFSET_PATH_SUPPORTED = CSS.supports('offset-rotate: 0deg'); export const IS_BACKDROP_BLUR_SUPPORTED = CSS.supports('backdrop-filter: blur()') || CSS.supports('-webkit-backdrop-filter: blur()'); export const IS_COMPACT_MENU = !IS_TOUCH_ENV; -export const IS_SCROLL_PATCH_NEEDED = !IS_MAC_OS && !IS_IOS && !IS_ANDROID; +export const IS_SCROLL_PATCH_NEEDED = !IS_MAC_OS && !IS_MOBILE; export const IS_INSTALL_PROMPT_SUPPORTED = 'onbeforeinstallprompt' in window; export const IS_MULTITAB_SUPPORTED = 'BroadcastChannel' in window; +export const IS_OPEN_IN_NEW_TAB_SUPPORTED = IS_MULTITAB_SUPPORTED && !(IS_PWA && IS_MOBILE); export const IS_TRANSLATION_SUPPORTED = Boolean(Intl.DisplayNames); // Smaller area reduces scroll jumps caused by `patchChromiumScroll` export const MESSAGE_LIST_SENSITIVE_AREA = IS_SCROLL_PATCH_NEEDED ? 300 : 750; -export const MAX_BUFFER_SIZE = (IS_ANDROID || IS_IOS ? 512 : 2000) * 1024 ** 2; // 512 OR 2000 MB +export const MAX_BUFFER_SIZE = (IS_MOBILE ? 512 : 2000) * 1024 ** 2; // 512 OR 2000 MB // TODO Turn on later as `!IS_IOS && !IS_ANDROID` export const VIDEO_AVATARS_DISABLED = true;