Commit 98774ac6 authored by Mygod's avatar Mygod

Fix deprecation

parent 5b9af4e1
......@@ -142,7 +142,7 @@ class ProxyInstance(val profile: Profile, private val route: String = profile.ro
fun scheduleUpdate() {
if (route !in arrayOf(Acl.ALL, Acl.CUSTOM_RULES)) AclSyncer.schedule(route)
if (scheduleConfigUpdate) RemoteConfig.scheduleFetch()
if (scheduleConfigUpdate) RemoteConfig.fetchAsync()
}
fun shutdown(scope: CoroutineScope) {
......
......@@ -25,25 +25,26 @@ import androidx.core.os.bundleOf
import com.github.shadowsocks.Core
import com.github.shadowsocks.core.R
import com.google.firebase.remoteconfig.FirebaseRemoteConfig
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.async
import kotlinx.coroutines.tasks.await
object RemoteConfig {
private val config = FirebaseRemoteConfig.getInstance().apply { setDefaults(R.xml.default_configs) }
private fun Exception.log() {
Log.w("RemoteConfig", this)
Core.analytics.logEvent("femote_config_failure", bundleOf(Pair(javaClass.simpleName, message)))
private val config = GlobalScope.async(Dispatchers.Main.immediate) {
FirebaseRemoteConfig.getInstance().apply { setDefaultsAsync(R.xml.default_configs).await() }
}
fun scheduleFetch() = config.fetch().addOnCompleteListener {
if (it.isSuccessful) config.activate() else it.exception?.log()
}
fun fetchAsync() = GlobalScope.async(Dispatchers.Main.immediate) { fetch() }
suspend fun fetch() = try {
config.fetch().await()
config to true
} catch (e: Exception) {
e.log()
config to false
suspend fun fetch() = config.await().run {
try {
fetch().await()
this to true
} catch (e: Exception) {
Log.w("RemoteConfig", e)
Core.analytics.logEvent("femote_config_failure", bundleOf(Pair(javaClass.simpleName, e.message)))
this to false
}
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment