chore: fix android
This commit is contained in:
@@ -80,13 +80,13 @@ export class ReceivedSharedItemsHandler {
|
|||||||
Linking.getInitialURL()
|
Linking.getInitialURL()
|
||||||
.then((url) => {
|
.then((url) => {
|
||||||
if (url && url.startsWith(IosUrlToCheckFor)) {
|
if (url && url.startsWith(IosUrlToCheckFor)) {
|
||||||
this.addSharedItemsToQueue(url)
|
this.addSharedItemsToQueue(url).catch(console.error)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch(console.error)
|
.catch(console.error)
|
||||||
this.eventSub = Linking.addEventListener('url', ({ url }) => {
|
this.eventSub = Linking.addEventListener('url', ({ url }) => {
|
||||||
if (url && url.startsWith(IosUrlToCheckFor)) {
|
if (url && url.startsWith(IosUrlToCheckFor)) {
|
||||||
this.addSharedItemsToQueue(url)
|
this.addSharedItemsToQueue(url).catch(console.error)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
return
|
return
|
||||||
@@ -94,7 +94,7 @@ export class ReceivedSharedItemsHandler {
|
|||||||
|
|
||||||
this.eventSub = AppState.addEventListener('change', (state) => {
|
this.eventSub = AppState.addEventListener('change', (state) => {
|
||||||
if (state === 'active') {
|
if (state === 'active') {
|
||||||
this.addSharedItemsToQueue()
|
this.addSharedItemsToQueue().catch(console.error)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -163,48 +163,47 @@ export class ReceivedSharedItemsHandler {
|
|||||||
this.handleItemsQueue().catch(console.error)
|
this.handleItemsQueue().catch(console.error)
|
||||||
}
|
}
|
||||||
|
|
||||||
private addSharedItemsToQueue = (url?: string) => {
|
private addSharedItemsToQueue = async (url?: string) => {
|
||||||
ReceiveSharingIntent.getFileNames(url)
|
const received =
|
||||||
.then(async (received: unknown) => {
|
Platform.OS === 'ios' ? await ReceiveSharingIntent.getFileNames(url) : await ReceiveSharingIntent.getFileNames()
|
||||||
if (!received) {
|
ReceiveSharingIntent.clearFileNames()
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Platform.OS === 'android') {
|
if (!received) {
|
||||||
const items = Object.values(received as Record<string, ReceivedItem>)
|
return
|
||||||
this.receivedItemsQueue.push(...items)
|
}
|
||||||
} else if (typeof received === 'string') {
|
|
||||||
const parsed: unknown = JSON.parse(received)
|
|
||||||
if (typeof parsed !== 'object') {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if (!parsed) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if ('media' in parsed && Array.isArray(parsed.media)) {
|
|
||||||
this.receivedItemsQueue.push(...parsed.media)
|
|
||||||
}
|
|
||||||
if ('text' in parsed && Array.isArray(parsed.text)) {
|
|
||||||
this.receivedItemsQueue.push(
|
|
||||||
...parsed.text.map((text: string) => ({
|
|
||||||
text: text,
|
|
||||||
})),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
if ('urls' in parsed && Array.isArray(parsed.urls)) {
|
|
||||||
this.receivedItemsQueue.push(
|
|
||||||
...parsed.urls.map((url: string) => ({
|
|
||||||
weblink: url,
|
|
||||||
})),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.isApplicationLaunched) {
|
if (Platform.OS === 'android') {
|
||||||
this.handleItemsQueue().catch(console.error)
|
const items = Object.values(received as Record<string, ReceivedItem>)
|
||||||
}
|
this.receivedItemsQueue.push(...items)
|
||||||
})
|
} else if (typeof received === 'string') {
|
||||||
.then(() => ReceiveSharingIntent.clearFileNames())
|
const parsed: unknown = JSON.parse(received)
|
||||||
.catch(console.error)
|
if (typeof parsed !== 'object') {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if (!parsed) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if ('media' in parsed && Array.isArray(parsed.media)) {
|
||||||
|
this.receivedItemsQueue.push(...parsed.media)
|
||||||
|
}
|
||||||
|
if ('text' in parsed && Array.isArray(parsed.text)) {
|
||||||
|
this.receivedItemsQueue.push(
|
||||||
|
...parsed.text.map((text: string) => ({
|
||||||
|
text: text,
|
||||||
|
})),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
if ('urls' in parsed && Array.isArray(parsed.urls)) {
|
||||||
|
this.receivedItemsQueue.push(
|
||||||
|
...parsed.urls.map((url: string) => ({
|
||||||
|
weblink: url,
|
||||||
|
})),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.isApplicationLaunched) {
|
||||||
|
this.handleItemsQueue().catch(console.error)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user