import { LinkingCrossPlatform } from './index' ; import { Linking as LinkingNative } from './index-native' ; const eventHandlers = new Map ( ) ; export const Linking = { addEventListener : ( type , handler ) => { if ( ! ( type === 'url' && typeof handler === 'function' ) ) return ; const wrapHandler = ( _e , url ) => { if ( typeof ( url || '' ) !== 'string' ) { if ( __DEV__ ) console . error ( '[Linking] URL not a string' , url ) ; return ; } handler ( { type , url : url || '' } ) ; } ; eventHandlers . set ( handler , wrapHandler ) ; window . ipc . addListener ( 'open-url' , wrapHandler ) ; } , async canOpenURL ( url ) { return await window . ipc . sendSync ( 'can-open-url' , url ) ; } , clearCurrentURL ( ) { } , getCurrentURL ( ) { return typeof window . location . href === 'string' ? window . location . href || '' : '' ; } , getInitialURL ( ) { return LinkingNative . getInitialURL ( ) ; } , openURL : ( url ) : Promise < void > => { return LinkingNative . openURL ( url ) ; } , removeEventListener : ( type , handler ) => { if ( ! ( type === 'url' && typeof handler === 'function' ) ) return ; const wrapHandler = eventHandlers . get ( handler ) ; if ( wrapHandler ) { window . ipc . removeListener ( 'open-url' , wrapHandler ) ; } eventHandlers . delete ( handler ) ; } , } ;