import { SHOW , HIDE } from '../constants' ; import router from '../router' ; import { emit as pageEmit } from '../pageLifeCycles' ; import { emit } from '../appLifeCycles' ; declare var __weex_require__ ; function initAppLifeCycles ( ) { try { const globalEvent = __weex_require__ ( '@weex-module/globalEvent' ) ; globalEvent . addEventListener ( 'WXApplicationDidBecomeActiveEvent' , function ( ) { router . current . visibilityState = true ; emit ( SHOW ) ; pageEmit ( SHOW , router . current . pathname ) ; } ) ; globalEvent . addEventListener ( 'WXApplicationWillResignActiveEvent' , function ( ) { router . current . visibilityState = false ; pageEmit ( HIDE , router . current . pathname ) ; emit ( HIDE ) ; } ) ; } catch ( err ) { console . log ( `@weex-module/globalEvent error: ${ err }` ) ; } } export default initAppLifeCycles ;