auto bypass domain of ConfigBean

This commit is contained in:
arm64v8a 2023-04-10 09:41:57 +09:00
parent f94fb6a961
commit 28e4c16839
3 changed files with 22 additions and 14 deletions

View File

@ -654,6 +654,13 @@ fun buildConfig(
if (it is HysteriaBean && it.isMultiPort()) {
serverAddr = it.serverAddress.substringBeforeLast(":")
}
if (it is ConfigBean) {
var config = mutableMapOf<String, Any>()
config = gson.fromJson(it.config, config.javaClass)
config["server"]?.apply {
serverAddr = toString()
}
}
if (!serverAddr.isIpAddress()) {
domainListDNSDirectForce.add("full:${serverAddr}")

View File

@ -34,6 +34,11 @@ fun SingBoxOptions.DNSRule_DefaultOptions.makeSingBoxRule(list: List<String>) {
domain.plusAssign(it.lowercase())
}
}
geosite?.removeIf { it.isNullOrBlank() }
domain?.removeIf { it.isNullOrBlank() }
domain_suffix?.removeIf { it.isNullOrBlank() }
domain_regex?.removeIf { it.isNullOrBlank() }
domain_keyword?.removeIf { it.isNullOrBlank() }
if (geosite?.isEmpty() == true) geosite = null
if (domain?.isEmpty() == true) domain = null
if (domain_suffix?.isEmpty() == true) domain_suffix = null
@ -86,6 +91,13 @@ fun SingBoxOptions.Rule_DefaultOptions.makeSingBoxRule(list: List<String>, isIP:
domain.plusAssign(it.lowercase())
}
}
ip_cidr?.removeIf { it.isNullOrBlank() }
geoip?.removeIf { it.isNullOrBlank() }
geosite?.removeIf { it.isNullOrBlank() }
domain?.removeIf { it.isNullOrBlank() }
domain_suffix?.removeIf { it.isNullOrBlank() }
domain_regex?.removeIf { it.isNullOrBlank() }
domain_keyword?.removeIf { it.isNullOrBlank() }
if (ip_cidr?.isEmpty() == true) ip_cidr = null
if (geoip?.isEmpty() == true) geoip = null
if (geosite?.isEmpty() == true) geosite = null

View File

@ -3,7 +3,6 @@ package moe.matsuri.nb4a.proxy.config
import android.os.Bundle
import androidx.preference.PreferenceDataStore
import androidx.preference.PreferenceFragmentCompat
import androidx.preference.SwitchPreference
import io.nekohasekai.sagernet.Key
import io.nekohasekai.sagernet.R
import io.nekohasekai.sagernet.database.DataStore
@ -15,36 +14,28 @@ class ConfigSettingActivity :
ProfileSettingsActivity<ConfigBean>(),
OnPreferenceDataStoreChangeListener {
private var beanType: Int = 0
private val isOutboundOnlyKey = "isOutboundOnly"
override fun createEntity() = ConfigBean()
override fun ConfigBean.init() {
// CustomBean to input
beanType = type
DataStore.profileCacheStore.putBoolean(isOutboundOnlyKey, type == 1)
DataStore.profileName = name
DataStore.serverConfig = config
}
override fun ConfigBean.serialize() {
// CustomBean from input
type = beanType
type = if (DataStore.profileCacheStore.getBoolean(isOutboundOnlyKey, false)) 1 else 0
name = DataStore.profileName
config = DataStore.serverConfig
}
override fun onCreate(savedInstanceState: Bundle?) {
intent?.getIntExtra("type", 0)?.apply { beanType = this }
super.onCreate(savedInstanceState)
}
override fun onPreferenceDataStoreChanged(store: PreferenceDataStore, key: String) {
if (key != Key.PROFILE_DIRTY) {
DataStore.dirty = true
}
if (key == "isOutboundOnly") {
beanType = if (store.getBoolean(key, false)) 1 else 0
}
}
private lateinit var editConfigPreference: EditConfigPreference
@ -56,8 +47,6 @@ class ConfigSettingActivity :
addPreferencesFromResource(R.xml.config_preferences)
editConfigPreference = findPreference(Key.SERVER_CONFIG)!!
findPreference<SwitchPreference>("isOutboundOnly")!!.isChecked = beanType == 1
}
override fun onResume() {