Fix Android browser package

This commit is contained in:
xmflsct 2022-12-04 00:35:13 +01:00
parent d8bff02136
commit 9f76fa08a8
7 changed files with 49 additions and 20 deletions

View File

@ -1,5 +1,6 @@
import Button from '@components/Button' import Button from '@components/Button'
import Icon from '@components/Icon' import Icon from '@components/Icon'
import browserPackage from '@helpers/browserPackage'
import { useAppsQuery } from '@utils/queryHooks/apps' import { useAppsQuery } from '@utils/queryHooks/apps'
import { useInstanceQuery } from '@utils/queryHooks/instance' import { useInstanceQuery } from '@utils/queryHooks/instance'
import { getInstances } from '@utils/slices/instancesSlice' import { getInstances } from '@utils/slices/instancesSlice'
@ -254,13 +255,19 @@ const ComponentInstance: React.FC<Props> = ({
<CustomText <CustomText
accessible accessible
style={{ color: colors.blue }} style={{ color: colors.blue }}
onPress={() => WebBrowser.openBrowserAsync('https://tooot.app/privacy-policy')} onPress={async () =>
WebBrowser.openBrowserAsync('https://tooot.app/privacy-policy', {
browserPackage: await browserPackage()
})
}
/>, />,
<CustomText <CustomText
accessible accessible
style={{ color: colors.blue }} style={{ color: colors.blue }}
onPress={() => onPress={async () =>
WebBrowser.openBrowserAsync('https://tooot.app/terms-of-service') WebBrowser.openBrowserAsync('https://tooot.app/terms-of-service', {
browserPackage: await browserPackage()
})
} }
/> />
]} ]}

View File

@ -1,3 +1,4 @@
import browserPackage from '@helpers/browserPackage'
import { useNavigation } from '@react-navigation/native' import { useNavigation } from '@react-navigation/native'
import { useAppDispatch } from '@root/store' import { useAppDispatch } from '@root/store'
import { InstanceLatest } from '@utils/migrations/instances/migration' import { InstanceLatest } from '@utils/migrations/instances/migration'
@ -5,9 +6,7 @@ import { TabMeStackNavigationProp } from '@utils/navigation/navigators'
import addInstance from '@utils/slices/instances/add' import addInstance from '@utils/slices/instances/add'
import { checkInstanceFeature } from '@utils/slices/instancesSlice' import { checkInstanceFeature } from '@utils/slices/instancesSlice'
import * as AuthSession from 'expo-auth-session' import * as AuthSession from 'expo-auth-session'
import * as WebBrowser from 'expo-web-browser'
import React, { useEffect } from 'react' import React, { useEffect } from 'react'
import { Platform } from 'react-native'
import { useQueryClient } from 'react-query' import { useQueryClient } from 'react-query'
import { useSelector } from 'react-redux' import { useSelector } from 'react-redux'
@ -47,15 +46,7 @@ const InstanceAuth = React.memo(
useEffect(() => { useEffect(() => {
;(async () => { ;(async () => {
if (request?.clientId) { if (request?.clientId) {
let browserPackage: string | undefined await promptAsync({ browserPackage: await browserPackage() }).catch(e => console.log(e))
if (Platform.OS === 'android') {
const tabsSupportingBrowsers = await WebBrowser.getCustomTabsSupportingBrowsersAsync()
browserPackage =
tabsSupportingBrowsers?.preferredBrowserPackage ||
tabsSupportingBrowsers.browserPackages[0] ||
tabsSupportingBrowsers.servicePackages[0]
}
await promptAsync({ browserPackage }).catch(e => console.log(e))
} }
})() })()
}, [request]) }, [request])

View File

@ -1,4 +1,5 @@
import apiInstance from '@api/instance' import apiInstance from '@api/instance'
import browserPackage from '@helpers/browserPackage'
import navigationRef from '@helpers/navigationRef' import navigationRef from '@helpers/navigationRef'
import { matchAccount, matchStatus } from '@helpers/urlMatcher' import { matchAccount, matchStatus } from '@helpers/urlMatcher'
import { store } from '@root/store' import { store } from '@root/store'
@ -91,7 +92,8 @@ const openLink = async (url: string, navigation?: any) => {
case 'internal': case 'internal':
await WebBrowser.openBrowserAsync(encodeURI(url), { await WebBrowser.openBrowserAsync(encodeURI(url), {
dismissButtonStyle: 'close', dismissButtonStyle: 'close',
enableBarCollapsing: true enableBarCollapsing: true,
browserPackage: await browserPackage()
}) })
break break
case 'external': case 'external':

View File

@ -0,0 +1,16 @@
import * as WebBrowser from 'expo-web-browser'
import { Platform } from 'react-native'
const browserPackage = async () => {
let browserPackage: string | undefined
if (Platform.OS === 'android') {
const tabsSupportingBrowsers = await WebBrowser.getCustomTabsSupportingBrowsersAsync()
browserPackage =
tabsSupportingBrowsers?.preferredBrowserPackage ||
tabsSupportingBrowsers.browserPackages[0] ||
tabsSupportingBrowsers.servicePackages[0]
}
return browserPackage
}
export default browserPackage

View File

@ -2,6 +2,7 @@ import Button from '@components/Button'
import Icon from '@components/Icon' import Icon from '@components/Icon'
import { MenuContainer, MenuRow } from '@components/Menu' import { MenuContainer, MenuRow } from '@components/Menu'
import CustomText from '@components/Text' import CustomText from '@components/Text'
import browserPackage from '@helpers/browserPackage'
import { useAppDispatch } from '@root/store' import { useAppDispatch } from '@root/store'
import { isDevelopment } from '@utils/checkEnvironment' import { isDevelopment } from '@utils/checkEnvironment'
import { getExpoToken } from '@utils/slices/appSlice' import { getExpoToken } from '@utils/slices/appSlice'
@ -153,7 +154,11 @@ const TabMePush: React.FC = () => {
<MenuRow <MenuRow
title={t('me.push.howitworks')} title={t('me.push.howitworks')}
iconBack='ExternalLink' iconBack='ExternalLink'
onPress={() => WebBrowser.openBrowserAsync('https://tooot.app/how-push-works')} onPress={async () =>
WebBrowser.openBrowserAsync('https://tooot.app/how-push-works', {
browserPackage: await browserPackage()
})
}
/> />
</MenuContainer> </MenuContainer>
<MenuContainer>{alerts}</MenuContainer> <MenuContainer>{alerts}</MenuContainer>

View File

@ -1,4 +1,5 @@
import { MenuContainer, MenuRow } from '@components/Menu' import { MenuContainer, MenuRow } from '@components/Menu'
import browserPackage from '@helpers/browserPackage'
import { useNavigation } from '@react-navigation/native' import { useNavigation } from '@react-navigation/native'
import { getInstanceActive, getInstanceUrl } from '@utils/slices/instancesSlice' import { getInstanceActive, getInstanceUrl } from '@utils/slices/instancesSlice'
import * as WebBrowser from 'expo-web-browser' import * as WebBrowser from 'expo-web-browser'
@ -25,11 +26,15 @@ const Settings: React.FC = () => {
iconFront='Sliders' iconFront='Sliders'
iconBack='ExternalLink' iconBack='ExternalLink'
title={t('me.stacks.webSettings.name')} title={t('me.stacks.webSettings.name')}
onPress={() => onPress={async () =>
WebBrowser.openAuthSessionAsync( WebBrowser.openAuthSessionAsync(
`https://${url}/settings/preferences`, `https://${url}/settings/preferences`,
'tooot://tooot', 'tooot://tooot',
{ dismissButtonStyle: 'done', readerMode: false } {
browserPackage: await browserPackage(),
dismissButtonStyle: 'done',
readerMode: false
}
) )
} }
/> />

View File

@ -14,6 +14,7 @@ import { isDevelopment, isRelease } from '@utils/checkEnvironment'
import { Platform } from 'react-native' import { Platform } from 'react-native'
import Constants from 'expo-constants' import Constants from 'expo-constants'
import { getExpoToken } from '@utils/slices/appSlice' import { getExpoToken } from '@utils/slices/appSlice'
import browserPackage from '@helpers/browserPackage'
const SettingsTooot: React.FC = () => { const SettingsTooot: React.FC = () => {
const instanceActive = useSelector(getInstanceActive) const instanceActive = useSelector(getInstanceActive)
@ -52,7 +53,7 @@ const SettingsTooot: React.FC = () => {
title={t('me.settings.contact.heading')} title={t('me.settings.contact.heading')}
content={<Icon name='Mail' size={StyleConstants.Font.Size.M} color={colors.secondary} />} content={<Icon name='Mail' size={StyleConstants.Font.Size.M} color={colors.secondary} />}
iconBack='ChevronRight' iconBack='ChevronRight'
onPress={() => { onPress={async () => {
if (instanceActive !== -1) { if (instanceActive !== -1) {
navigation.navigate('Screen-Compose', { navigation.navigate('Screen-Compose', {
type: 'conversation', type: 'conversation',
@ -71,7 +72,9 @@ const SettingsTooot: React.FC = () => {
']' ']'
}) })
} else { } else {
WebBrowser.openBrowserAsync('https://social.xmflsct.com/@tooot') WebBrowser.openBrowserAsync('https://social.xmflsct.com/@tooot', {
browserPackage: await browserPackage()
})
} }
}} }}
/> />