diff --git a/AndroidManifest.xml b/AndroidManifest.xml index e911bcc..b203e8b 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -34,7 +34,9 @@ + + diff --git a/src/components/invitation/Invitation.tsx b/src/components/invitation/Invitation.tsx index 955c669..cf0e40f 100644 --- a/src/components/invitation/Invitation.tsx +++ b/src/components/invitation/Invitation.tsx @@ -36,6 +36,42 @@ const fetchInvitation = () => { }); }; +export const searchInvitationInIntent = (intent: any) => { + if (intent.action !== 'android.intent.action.VIEW') { + return false; + } + let url; + try { + url = new URL(intent.data); + } catch (error) { + console.error({ caller: 'searchInvitationInIntent', intent, error }); + return false; + } + if (url.protocol !== 'geo:') { + return false; + } + const q = url.search; + const matches = q.match(/invitation=(.+)/); + if (!matches) { + return false; + } + try { + const payload = matches[1]; + const decoded = atob(payload); + const url = new URL(decoded); + setInvitation({ url }); + fetchInvitation(); + } catch { + console.warn({ + caller: 'Invitation / searchInvitationInIntent', + intent, + matches, + message: 'Query is not a base64 encoded URL', + }); + } + return true; +}; + export const searchInvitation = () => { const hash = location.hash; console.log({ caller: 'Invitation / searchInvitation', hash }); diff --git a/src/components/invitation/index.ts b/src/components/invitation/index.ts index b7dbbb2..2be74d0 100644 --- a/src/components/invitation/index.ts +++ b/src/components/invitation/index.ts @@ -1 +1 @@ -export { default, searchInvitation } from './Invitation'; +export { default, searchInvitation, searchInvitationInIntent } from './Invitation'; diff --git a/src/components/map/Map.tsx b/src/components/map/Map.tsx index feae88d..693bdda 100644 --- a/src/components/map/Map.tsx +++ b/src/components/map/Map.tsx @@ -46,7 +46,11 @@ import { Overlays } from '../overlays/Overlays'; import Finder, { findLocation } from '../finder'; import { ZoomIn } from '@suid/icons-material'; import Note from '../note'; -import Invitation, { searchInvitation } from '../invitation'; +import Invitation, { + searchInvitation, + searchInvitationInIntent, +} from '../invitation'; +import { returnOrUpdate } from 'ol/extent'; const [getState, setState] = createSignal({ lon: 0, @@ -92,6 +96,9 @@ const Map: Component = () => { ); window.plugins.intentShim.onIntent(function (intent: any) { console.log({ caller: 'Intent receiver', intent }); + if (searchInvitationInIntent(intent)) { + return; + } if (intent.action === 'android.intent.action.VIEW') { const url = new URL(intent.data); console.log({ caller: 'Intent receiver', intent, url });