Refactoring intent receivers for web links
This commit is contained in:
parent
c3c93139ed
commit
f9517b07b4
|
@ -95,14 +95,7 @@ const Map: Component = () => {
|
|||
if (receiveIntent(intent, navigate)) {
|
||||
return;
|
||||
}
|
||||
if (intent.action === 'android.intent.action.VIEW') {
|
||||
const url = new URL(intent.data);
|
||||
console.log({ caller: 'Intent receiver', intent, url });
|
||||
if (url.protocol === 'https:' && url.hostname === 'web.dyomedea.app') {
|
||||
location.hash = url.hash;
|
||||
location.pathname = url.pathname;
|
||||
}
|
||||
} else if (
|
||||
if (
|
||||
intent.action === 'android.intent.action.SEND' &&
|
||||
!!intent.extras['android.intent.extra.TEXT']
|
||||
) {
|
||||
|
|
|
@ -1,11 +1,13 @@
|
|||
import { geoLocationReceiver } from './geo-location';
|
||||
import { gpxReceiver } from './gpx-receiver';
|
||||
import { invitationReceiver } from './invitation-receiver';
|
||||
import { webLinksReceiver } from './web-links';
|
||||
|
||||
const receivers = {
|
||||
invitationReceiver,
|
||||
gpxReceiver,
|
||||
geoLocationReceiver,
|
||||
webLinksReceiver,
|
||||
};
|
||||
|
||||
export const receiveIntent = (intent: any, navigate: any) => {
|
||||
|
|
|
@ -0,0 +1,32 @@
|
|||
const ACCEPTED_ACTIONS = ['android.intent.action.VIEW'];
|
||||
|
||||
const ACCEPTED_PROTOCOLS = ['https:'];
|
||||
|
||||
const ACCEPTED_HOSTNAMES = ['web.dyomedea.app'];
|
||||
|
||||
export const webLinksReceiver = (
|
||||
intent: any,
|
||||
url: URL | undefined,
|
||||
navigate: any
|
||||
) => {
|
||||
if (!ACCEPTED_ACTIONS.includes(intent.action)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!url) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!ACCEPTED_PROTOCOLS.includes(url.protocol)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!ACCEPTED_HOSTNAMES.includes(url.hostname)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
location.hash = url.hash;
|
||||
location.pathname = url.pathname;
|
||||
|
||||
return true;
|
||||
};
|
Loading…
Reference in New Issue