import { Injectable } from '@angular/core' ; import { Platform , ToastController } from 'ionic-angular' ; import { Config } from '../config' ; @ Injectable ( ) export class LastToastProvider { private paused = false ; private lastToastMessage : string ; constructor ( public platform , public toastCtrl ) { platform . pause . subscribe ( ( ) => { this . paused = true ; } ) ; platform . resume . subscribe ( ( ) => { this . paused = false ; if ( this . lastToastMessage && this . lastToastMessage . length ) { this . present ( this . lastToastMessage ) ; } } ) ; } public present ( message , duartion = 6000 ) { if ( Config . DEBUG ) { duartion = 2500 ; } if ( document . visibilityState == 'hidden' ) { this . paused = true ; } if ( ! this . paused ) { this . toastCtrl . create ( { message : message , duration : duartion , showCloseButton : true , closeButtonText : 'DISMISS' } ) . present ( ) ; this . lastToastMessage = null ; } else { this . lastToastMessage = message ; } } }