import lang from "lang" ; import { UIAlertViewStyle } from "types/UIKit" ; import { Addon , MN } from "../const" ; const console = { log ( obj , suffix = "normal" ) { JSB . log ( `${ Addon . key }-${ suffix } %@` , obj ) ; } , error ( obj , suffix = "error" ) { JSB . log ( `${ Addon . key }-${ suffix } %@` , obj ) ; } } ; const showHUD = ( message , duration = 1 , window = self . window ) => void MN . app . showHUD ( message , window , duration ) ; const HUDController = { show ( message , window = self . window ) { MN . app . waitHUDOnView ( message , window ) ; } , hidden ( window = self . window ) { MN . app . stopWaitHUDOnView ( window ) ; } } ; const alert = ( message ) => void MN . app . alert ( message ) ; const getObjCClassDeclar = ( name , type , delegate = [ ] ) => { let str = `${ name } : ${ type }` ; if ( delegate . length ) { delegate . forEach ( value => { str = `${ str } ${ value }Delegate` ; } ) ; } return str ; } ; const delay = ( sec ) => new Promise ( resolve => NSTimer . scheduledTimerWithTimeInterval ( sec , false , resolve ) ) ; const delayBreak = async ( times , sec , f ) : Promise < boolean > => { for ( let i = 0 ; i < times ; i ++ ) { await delay ( sec ) ; if ( f ( ) ) return true ; } return false ; } ; const openUrl = ( url ) => void MN . app . openURL ( NSURL . URLWithString ( encodeURI ( url ) ) ) ; const postNotification = ( key , userInfo ) => { NSNotificationCenter . defaultCenter ( ) . postNotificationNameObjectUserInfo ( key , self , userInfo ) ; } ; const isThisWindow = ( sender , window = self . window ) => MN . app . checkNotifySenderInWindow ( sender , window ) ; const popup = ( title , message , type , buttons , f ) => new Promise < { option ? : number ; content ? : string ; } > ( resolve => UIAlertView . showWithTitleMessageStyleCancelButtonTitleOtherButtonTitlesTapBlock ( title , message , type , lang . other . cancel , buttons , ( alert , buttonIndex ) => { if ( buttonIndex != 0 ) resolve ( f ( alert , buttonIndex - 1 ) ) ; } ) ) ; /**
 * 用来判断是否是 OC 的 NSNull 对象
 */ const isOCNull = ( obj ) => obj == NSNull . new ( ) ; export { console , showHUD , HUDController , alert , delay , delayBreak , getObjCClassDeclar , openUrl , postNotification , isThisWindow , isOCNull , popup } ;