package com.gh.gamecenter.vpn

import androidx.multidex.MultiDexApplication
import com.alibaba.android.arouter.launcher.ARouter
import com.gh.gamecenter.core.iinterface.IApplication
import java.util.*

class VpnModuleApp : MultiDexApplication() {

    private val mApplicationList = ServiceLoader.load(IApplication::class.java, this.javaClass.classLoader)

    override fun onCreate() {
        super.onCreate()
        initArouter()
        mApp = this
        for (application in mApplicationList) {
            application.onCreate(this)
        }
    }

    private fun initArouter() {
        if (BuildConfig.DEBUG) {  // 这两行必须写在init之前，否则这些配置在init过程中将无效
            ARouter.openLog() // 打印日志
            ARouter.openDebug() // 开启调试模式(如果在InstantRun模式下运行，必须开启调试模式！线上版本需要关闭,否则有安全风险)
        }
        ARouter.init(this) // 尽可能早，推荐在Application中初始化
    }

    companion object {
        private lateinit var mApp: VpnModuleApp

        fun getInstance(): VpnModuleApp {
            return mApp
        }
    }
}