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