Skip to content
This repository was archived by the owner on Oct 19, 2024. It is now read-only.

Commit 173d424

Browse files
committed
Fix #717
1 parent 0db7f0c commit 173d424

File tree

5 files changed

+45
-29
lines changed

5 files changed

+45
-29
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
11
Enjoy toooting! This version includes following improvements and fixes:
2-
- Added Belarusian language
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
11
toooting愉快!此版本包括以下改进和修复:
2-
- 新增白俄罗斯语

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "tooot",
3-
"version": "4.9.1",
3+
"version": "4.9.2",
44
"description": "tooot for Mastodon",
55
"author": "xmflsct <[email protected]>",
66
"license": "GPL-3.0-or-later",

src/screens/index.tsx

+3-26
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import ScreenAnnouncements from '@screens/Announcements'
77
import ScreenCompose from '@screens/Compose'
88
import ScreenImagesViewer from '@screens/ImageViewer'
99
import ScreenTabs from '@screens/Tabs'
10+
import { useLinking } from '@utils/linking'
1011
import navigationRef from '@utils/navigation/navigationRef'
1112
import { RootStackParamList } from '@utils/navigation/navigators'
1213
import pushUseConnect from '@utils/push/useConnect'
@@ -78,32 +79,8 @@ const Screens: React.FC = () => {
7879
}
7980
}
8081

81-
// Deep linking for compose
82-
const [deeplinked, setDeeplinked] = useState(false)
83-
useEffect(() => {
84-
const getUrlAsync = async () => {
85-
setDeeplinked(true)
86-
87-
const initialUrl = await Linking.parseInitialURLAsync()
88-
89-
if (initialUrl.path) {
90-
const paths = initialUrl.path.split('/')
91-
92-
if (paths.length) {
93-
if (accountActive && !accounts?.includes(accountActive)) {
94-
setAccount(accountActive)
95-
}
96-
}
97-
}
98-
99-
if (initialUrl.hostname === 'compose') {
100-
navigationRef.navigate('Screen-Compose')
101-
}
102-
}
103-
if (!deeplinked) {
104-
getUrlAsync()
105-
}
106-
}, [accounts, accountActive, deeplinked])
82+
// Deep linking
83+
useLinking()
10784

10885
// Share Extension
10986
const handleShare = (

src/utils/linking/index.ts

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import openLink from '@components/openLink'
2+
import navigationRef from '@utils/navigation/navigationRef'
3+
import { getReadableAccounts, setAccount } from '@utils/storage/actions'
4+
import * as Linking from 'expo-linking'
5+
import { useEffect } from 'react'
6+
7+
// /compose OR /compose/@username@example.com
8+
9+
export const useLinking = () => {
10+
const parseLink = async (link: string) => {
11+
const parsed = Linking.parse(link)
12+
13+
switch (parsed.scheme) {
14+
case 'tooot':
15+
if (parsed.hostname === 'compose') {
16+
if (parsed.path?.length) {
17+
const accounts = getReadableAccounts()
18+
const foundNotActiveAccount = accounts.find(
19+
account => account.acct === parsed.path && !account.active
20+
)
21+
if (foundNotActiveAccount) {
22+
await setAccount(foundNotActiveAccount.key)
23+
}
24+
}
25+
navigationRef.navigate('Screen-Compose')
26+
}
27+
break
28+
case 'https':
29+
case 'http':
30+
await openLink(link)
31+
break
32+
}
33+
}
34+
35+
useEffect(() => {
36+
Linking.getInitialURL().then(parseLink)
37+
38+
const listener = Linking.addEventListener('url', ({ url }) => parseLink(url))
39+
return () => listener.remove()
40+
}, [])
41+
}

0 commit comments

Comments
 (0)