Refactoring intent receivers for web links
This commit is contained in:
1 parent
c3c93139ed
commit
f9517b07b4
3 files changed
+35
-8
No files matched your search
@@ -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;
|
||||
};
|
||||
Reference in new issue
Block a user