Commit b9cb3438 authored by Daniel Wolf's avatar Daniel Wolf
Browse files

Use default for unparseable server configs

parent b8ea717f
......@@ -12,6 +12,7 @@ import com.frostnerd.preferenceskt.typedpreferences.TypedPreferences
import com.frostnerd.preferenceskt.typedpreferences.types.PreferenceType
import com.frostnerd.smokescreen.type
import com.frostnerd.smokescreen.util.ServerType
import java.lang.NullPointerException
import kotlin.reflect.KProperty
/*
......@@ -46,20 +47,24 @@ class DnsServerInformationPreference(key: String) :
thisRef: TypedPreferences<SharedPreferences>,
property: KProperty<*>
): DnsServerInformation<*>? {
return if(thisRef.sharedPreferences.contains(key + "_type")) {
val type = thisRef.sharedPreferences.getString(key + "_type", "")
val json = thisRef.sharedPreferences.getString(key, "")
if(json.isNullOrBlank()) {
null
} else {
when (type) {
"https" -> httpsTypeAdapter.fromJson(json)
"tls" -> tlsTypeAdapter.fromJson(json) as DnsServerInformation<TLSUpstreamAddress>
"quic" -> tlsTypeAdapter.fromJson(json) as DnsServerInformation<QuicUpstreamAddress>
else -> throw IllegalStateException("Unknown type $type")
return try{
if(thisRef.sharedPreferences.contains(key + "_type")) {
val type = thisRef.sharedPreferences.getString(key + "_type", "")
val json = thisRef.sharedPreferences.getString(key, "")
if(json.isNullOrBlank()) {
null
} else {
when (type) {
"https" -> httpsTypeAdapter.fromJson(json)
"tls" -> tlsTypeAdapter.fromJson(json) as DnsServerInformation<TLSUpstreamAddress>
"quic" -> tlsTypeAdapter.fromJson(json) as DnsServerInformation<QuicUpstreamAddress>
else -> throw IllegalStateException("Unknown type $type")
}
}
}
} else null
} else null
} catch (err:Throwable){
null
}
}
override fun setValue(
......
Supports Markdown
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