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 ...@@ -142,7 +142,7 @@ class ProxyInstance(val profile: Profile, private val route: String = profile.ro
fun scheduleUpdate() { fun scheduleUpdate() {
if (route !in arrayOf(Acl.ALL, Acl.CUSTOM_RULES)) AclSyncer.schedule(route) if (route !in arrayOf(Acl.ALL, Acl.CUSTOM_RULES)) AclSyncer.schedule(route)
if (scheduleConfigUpdate) RemoteConfig.scheduleFetch() if (scheduleConfigUpdate) RemoteConfig.fetchAsync()
} }
fun shutdown(scope: CoroutineScope) { fun shutdown(scope: CoroutineScope) {
......
...@@ -25,25 +25,26 @@ import androidx.core.os.bundleOf ...@@ -25,25 +25,26 @@ import androidx.core.os.bundleOf
import com.github.shadowsocks.Core import com.github.shadowsocks.Core
import com.github.shadowsocks.core.R import com.github.shadowsocks.core.R
import com.google.firebase.remoteconfig.FirebaseRemoteConfig import com.google.firebase.remoteconfig.FirebaseRemoteConfig
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.async
import kotlinx.coroutines.tasks.await import kotlinx.coroutines.tasks.await
object RemoteConfig { object RemoteConfig {
private val config = FirebaseRemoteConfig.getInstance().apply { setDefaults(R.xml.default_configs) } private val config = GlobalScope.async(Dispatchers.Main.immediate) {
FirebaseRemoteConfig.getInstance().apply { setDefaultsAsync(R.xml.default_configs).await() }
private fun Exception.log() {
Log.w("RemoteConfig", this)
Core.analytics.logEvent("femote_config_failure", bundleOf(Pair(javaClass.simpleName, message)))
} }
fun scheduleFetch() = config.fetch().addOnCompleteListener { fun fetchAsync() = GlobalScope.async(Dispatchers.Main.immediate) { fetch() }
if (it.isSuccessful) config.activate() else it.exception?.log()
}
suspend fun fetch() = try { suspend fun fetch() = config.await().run {
config.fetch().await() try {
config to true fetch().await()
} catch (e: Exception) { this to true
e.log() } catch (e: Exception) {
config to false 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