mirror of
https://github.com/tooot-app/app
synced 2024-12-21 23:24:29 +01:00
Fix #717
This commit is contained in:
parent
0db7f0c40a
commit
173d4248d8
@ -1,2 +1 @@
|
||||
Enjoy toooting! This version includes following improvements and fixes:
|
||||
- Added Belarusian language
|
@ -1,2 +1 @@
|
||||
toooting愉快!此版本包括以下改进和修复:
|
||||
- 新增白俄罗斯语
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "tooot",
|
||||
"version": "4.9.1",
|
||||
"version": "4.9.2",
|
||||
"description": "tooot for Mastodon",
|
||||
"author": "xmflsct <me@xmflsct.com>",
|
||||
"license": "GPL-3.0-or-later",
|
||||
|
@ -7,6 +7,7 @@ import ScreenAnnouncements from '@screens/Announcements'
|
||||
import ScreenCompose from '@screens/Compose'
|
||||
import ScreenImagesViewer from '@screens/ImageViewer'
|
||||
import ScreenTabs from '@screens/Tabs'
|
||||
import { useLinking } from '@utils/linking'
|
||||
import navigationRef from '@utils/navigation/navigationRef'
|
||||
import { RootStackParamList } from '@utils/navigation/navigators'
|
||||
import pushUseConnect from '@utils/push/useConnect'
|
||||
@ -78,32 +79,8 @@ const Screens: React.FC = () => {
|
||||
}
|
||||
}
|
||||
|
||||
// Deep linking for compose
|
||||
const [deeplinked, setDeeplinked] = useState(false)
|
||||
useEffect(() => {
|
||||
const getUrlAsync = async () => {
|
||||
setDeeplinked(true)
|
||||
|
||||
const initialUrl = await Linking.parseInitialURLAsync()
|
||||
|
||||
if (initialUrl.path) {
|
||||
const paths = initialUrl.path.split('/')
|
||||
|
||||
if (paths.length) {
|
||||
if (accountActive && !accounts?.includes(accountActive)) {
|
||||
setAccount(accountActive)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (initialUrl.hostname === 'compose') {
|
||||
navigationRef.navigate('Screen-Compose')
|
||||
}
|
||||
}
|
||||
if (!deeplinked) {
|
||||
getUrlAsync()
|
||||
}
|
||||
}, [accounts, accountActive, deeplinked])
|
||||
// Deep linking
|
||||
useLinking()
|
||||
|
||||
// Share Extension
|
||||
const handleShare = (
|
||||
|
41
src/utils/linking/index.ts
Normal file
41
src/utils/linking/index.ts
Normal file
@ -0,0 +1,41 @@
|
||||
import openLink from '@components/openLink'
|
||||
import navigationRef from '@utils/navigation/navigationRef'
|
||||
import { getReadableAccounts, setAccount } from '@utils/storage/actions'
|
||||
import * as Linking from 'expo-linking'
|
||||
import { useEffect } from 'react'
|
||||
|
||||
// /compose OR /compose/@username@example.com
|
||||
|
||||
export const useLinking = () => {
|
||||
const parseLink = async (link: string) => {
|
||||
const parsed = Linking.parse(link)
|
||||
|
||||
switch (parsed.scheme) {
|
||||
case 'tooot':
|
||||
if (parsed.hostname === 'compose') {
|
||||
if (parsed.path?.length) {
|
||||
const accounts = getReadableAccounts()
|
||||
const foundNotActiveAccount = accounts.find(
|
||||
account => account.acct === parsed.path && !account.active
|
||||
)
|
||||
if (foundNotActiveAccount) {
|
||||
await setAccount(foundNotActiveAccount.key)
|
||||
}
|
||||
}
|
||||
navigationRef.navigate('Screen-Compose')
|
||||
}
|
||||
break
|
||||
case 'https':
|
||||
case 'http':
|
||||
await openLink(link)
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
Linking.getInitialURL().then(parseLink)
|
||||
|
||||
const listener = Linking.addEventListener('url', ({ url }) => parseLink(url))
|
||||
return () => listener.remove()
|
||||
}, [])
|
||||
}
|
Loading…
Reference in New Issue
Block a user