Begining to refactor intent receivers to support GPX imports from more sources

This commit is contained in:
vdv committed 2023-04-17 10:41:30 +02:00
1 parent 8242680137
commit f82181347c
4 files changed
+90 -9

No files matched your search

+34
View File
@@ -0,0 +1,34 @@
import { importUrls } from '../../components/import';
const ACCEPTED_ACTIONS = [
'android.intent.action.VIEW',
'android.intent.action.SEND',
];
const ACCEPTED_PROTOCOLS = ['content:'];
const ACCEPTED_TYPES = [
'application/xml',
'application/gpx+xml',
'text/xml',
'text/plain',
'image/*',
'image/jpeg',
];
export const gpxReceiver = (intent: any, url: URL | undefined) => {
if (!ACCEPTED_ACTIONS.includes(intent.action)) {
return false;
}
if (!url) {
return false;
}
if (!ACCEPTED_PROTOCOLS.includes(url.protocol)) {
return false;
}
importUrls([url.toString()]);
return true;
};
+24
View File
@@ -0,0 +1,24 @@
import { gpxReceiver } from './gpx-receiver';
const receivers = {
gpxReceiver,
};
export const receiveIntent = (intent: any) => {
let url: URL | undefined;
try {
url = new URL(
intent.extras && intent.extras['android.intent.extra.STREAM']
? intent.extras['android.intent.extra.STREAM']
: intent.data
);
} catch (error) {
console.error({ caller: 'receiveIntent / URL', error });
}
const found = Object.values(receivers).some((receiver) =>
receiver(intent, url)
);
return found;
};