From a58af39fae4cba38bbe33ac02266bea21c05734c Mon Sep 17 00:00:00 2001 From: Steve Johnson Date: Thu, 2 Nov 2023 18:57:55 +0800 Subject: [PATCH] feat: add some override options about sniffing --- .../clash/MetaFeatureSettingsActivity.kt | 10 +- .../clash/core/model/ConfigurationOverride.kt | 9 ++ .../clash/design/MetaFeatureSettingsDesign.kt | 95 ++++++++++++------- design/src/main/res/values-ja-rJP/strings.xml | 3 + design/src/main/res/values-ko-rKR/strings.xml | 3 + design/src/main/res/values-ru/strings.xml | 3 + design/src/main/res/values-zh-rHK/strings.xml | 3 + design/src/main/res/values-zh-rTW/strings.xml | 3 + design/src/main/res/values-zh/strings.xml | 3 + design/src/main/res/values/strings.xml | 3 + 10 files changed, 94 insertions(+), 41 deletions(-) diff --git a/app/src/main/java/com/github/kr328/clash/MetaFeatureSettingsActivity.kt b/app/src/main/java/com/github/kr328/clash/MetaFeatureSettingsActivity.kt index 9708fcd7..29ebbcb3 100644 --- a/app/src/main/java/com/github/kr328/clash/MetaFeatureSettingsActivity.kt +++ b/app/src/main/java/com/github/kr328/clash/MetaFeatureSettingsActivity.kt @@ -2,7 +2,6 @@ package com.github.kr328.clash import android.database.Cursor import android.net.Uri -import android.os.Bundle import android.provider.OpenableColumns import android.widget.Toast import androidx.activity.result.contract.ActivityResultContracts @@ -13,7 +12,6 @@ import com.github.kr328.clash.util.withClash import com.google.android.material.dialog.MaterialAlertDialogBuilder import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.isActive -import kotlinx.coroutines.launch import kotlinx.coroutines.selects.select import kotlinx.coroutines.withContext import java.io.File @@ -58,19 +56,19 @@ class MetaFeatureSettingsActivity : BaseActivity() { val uri = startActivityForResult( ActivityResultContracts.GetContent(), "*/*") - geoFilesImported(uri, MetaFeatureSettingsDesign.Request.ImportGeoIp) + importGeoFile(uri, MetaFeatureSettingsDesign.Request.ImportGeoIp) } MetaFeatureSettingsDesign.Request.ImportGeoSite -> { val uri = startActivityForResult( ActivityResultContracts.GetContent(), "*/*") - geoFilesImported(uri, MetaFeatureSettingsDesign.Request.ImportGeoSite) + importGeoFile(uri, MetaFeatureSettingsDesign.Request.ImportGeoSite) } MetaFeatureSettingsDesign.Request.ImportCountry -> { val uri = startActivityForResult( ActivityResultContracts.GetContent(), "*/*") - geoFilesImported(uri, MetaFeatureSettingsDesign.Request.ImportCountry) + importGeoFile(uri, MetaFeatureSettingsDesign.Request.ImportCountry) } } } @@ -82,7 +80,7 @@ class MetaFeatureSettingsActivity : BaseActivity() { ".metadb", ".db", ".dat", ".mmdb" ) - private suspend fun geoFilesImported(uri: Uri?, importType: MetaFeatureSettingsDesign.Request) { + private suspend fun importGeoFile(uri: Uri?, importType: MetaFeatureSettingsDesign.Request) { val cursor: Cursor? = uri?.let { contentResolver.query(it, null, null, null, null, null) } diff --git a/core/src/main/java/com/github/kr328/clash/core/model/ConfigurationOverride.kt b/core/src/main/java/com/github/kr328/clash/core/model/ConfigurationOverride.kt index 9fe4f2c6..a64baac8 100644 --- a/core/src/main/java/com/github/kr328/clash/core/model/ConfigurationOverride.kt +++ b/core/src/main/java/com/github/kr328/clash/core/model/ConfigurationOverride.kt @@ -159,6 +159,15 @@ data class ConfigurationOverride( @SerialName("sniffing") var sniffing: List? = null, + @SerialName("force-dns-mapping") + var forceDnsMapping: Boolean? = null, + + @SerialName("parse-pure-ip") + var parsePureIp: Boolean? = null, + + @SerialName("override-destination") + var overrideDestination: Boolean? = null, + @SerialName("force-domain") var forceDomain: List? = null, diff --git a/design/src/main/java/com/github/kr328/clash/design/MetaFeatureSettingsDesign.kt b/design/src/main/java/com/github/kr328/clash/design/MetaFeatureSettingsDesign.kt index e5c4704a..4e9d195e 100644 --- a/design/src/main/java/com/github/kr328/clash/design/MetaFeatureSettingsDesign.kt +++ b/design/src/main/java/com/github/kr328/clash/design/MetaFeatureSettingsDesign.kt @@ -117,9 +117,9 @@ class MetaFeatureSettingsDesign( false ), valuesText = arrayOf( - R.string.sniffer_config, - R.string.sniffer_override, - R.string.disable_sniffer, + R.string.dont_modify, + R.string.enabled, + R.string.disabled ), title = R.string.strategy ) { @@ -144,6 +144,30 @@ class MetaFeatureSettingsDesign( configure = snifferDependencies::add, ) + selectableList( + value = configuration.sniffer::forceDnsMapping, + values = booleanValues, + valuesText = booleanValuesText, + title = R.string.force_dns_mapping, + configure = snifferDependencies::add, + ) + + selectableList( + value = configuration.sniffer::parsePureIp, + values = booleanValues, + valuesText = booleanValuesText, + title = R.string.parse_pure_ip, + configure = snifferDependencies::add, + ) + + selectableList( + value = configuration.sniffer::overrideDestination, + values = booleanValues, + valuesText = booleanValuesText, + title = R.string.override_destination, + configure = snifferDependencies::add, + ) + editableTextList( value = configuration.sniffer::forceDomain, adapter = TextAdapter.String, @@ -170,6 +194,39 @@ class MetaFeatureSettingsDesign( sniffer.listener?.onChanged() + /* + category(R.string.geox_url_setting) + + val geoxUrlDependencies: MutableList = mutableListOf() + + editableText( + value = configuration.geoxurl::geoip, + adapter = NullableTextAdapter.String, + title = R.string.geox_geoip, + placeholder = R.string.dont_modify, + empty = R.string.geoip_url, + configure = geoxUrlDependencies::add, + ) + + editableText( + value = configuration.geoxurl::mmdb, + adapter = NullableTextAdapter.String, + title = R.string.geox_mmdb, + placeholder = R.string.dont_modify, + empty = R.string.mmdb_url, + configure = geoxUrlDependencies::add, + ) + + editableText( + value = configuration.geoxurl::geosite, + adapter = NullableTextAdapter.String, + title = R.string.geox_geosite, + placeholder = R.string.dont_modify, + empty = R.string.geosite_url, + configure = geoxUrlDependencies::add, + ) + */ + category(R.string.geox_files) clickable ( @@ -198,38 +255,6 @@ class MetaFeatureSettingsDesign( requests.trySend(Request.ImportCountry) } } - - /* - category(R.string.geox_url_setting) - - val geoxurlDependencies: MutableList = mutableListOf() - - editableText( - value = configuration.geoxurl::geoip, - adapter = NullableTextAdapter.String, - title = R.string.geox_geoip, - placeholder = R.string.dont_modify, - empty = R.string.geoip_url, - configure = geoxurlDependencies::add, - ) - - editableText( - value = configuration.geoxurl::mmdb, - adapter = NullableTextAdapter.String, - title = R.string.geox_mmdb, - placeholder = R.string.dont_modify, - empty = R.string.mmdb_url, - configure = geoxurlDependencies::add, - ) - - editableText( - value = configuration.geoxurl::geosite, - adapter = NullableTextAdapter.String, - title = R.string.geox_geosite, - placeholder = R.string.dont_modify, - empty = R.string.geosite_url, - configure = geoxurlDependencies::add, - ) */ } binding.content.addView(screen.root) diff --git a/design/src/main/res/values-ja-rJP/strings.xml b/design/src/main/res/values-ja-rJP/strings.xml index f5c6735f..65f2ed9f 100644 --- a/design/src/main/res/values-ja-rJP/strings.xml +++ b/design/src/main/res/values-ja-rJP/strings.xml @@ -251,4 +251,7 @@ External Control Clash.Meta service started Clash.Meta service stopped + Force DNS Mapping + Parse Pure IP + Override Destination \ No newline at end of file diff --git a/design/src/main/res/values-ko-rKR/strings.xml b/design/src/main/res/values-ko-rKR/strings.xml index 04756bf3..f09bd825 100644 --- a/design/src/main/res/values-ko-rKR/strings.xml +++ b/design/src/main/res/values-ko-rKR/strings.xml @@ -251,4 +251,7 @@ External Control Clash.Meta service started Clash.Meta service stopped + Force DNS Mapping + Parse Pure IP + Override Destination \ No newline at end of file diff --git a/design/src/main/res/values-ru/strings.xml b/design/src/main/res/values-ru/strings.xml index 1c0051b0..a1e42712 100644 --- a/design/src/main/res/values-ru/strings.xml +++ b/design/src/main/res/values-ru/strings.xml @@ -316,4 +316,7 @@ External Control Clash.Meta service started Clash.Meta service stopped + Force DNS Mapping + Parse Pure IP + Override Destination diff --git a/design/src/main/res/values-zh-rHK/strings.xml b/design/src/main/res/values-zh-rHK/strings.xml index cedc12ae..28fe0152 100644 --- a/design/src/main/res/values-zh-rHK/strings.xml +++ b/design/src/main/res/values-zh-rHK/strings.xml @@ -248,4 +248,7 @@ External Control Clash.Meta service started Clash.Meta service stopped + Force DNS Mapping + Parse Pure IP + Override Destination \ No newline at end of file diff --git a/design/src/main/res/values-zh-rTW/strings.xml b/design/src/main/res/values-zh-rTW/strings.xml index e3388099..42bf15cc 100644 --- a/design/src/main/res/values-zh-rTW/strings.xml +++ b/design/src/main/res/values-zh-rTW/strings.xml @@ -248,4 +248,7 @@ External Control Clash.Meta service started Clash.Meta service stopped + Force DNS Mapping + Parse Pure IP + Override Destination diff --git a/design/src/main/res/values-zh/strings.xml b/design/src/main/res/values-zh/strings.xml index 186d414f..dc92cdac 100644 --- a/design/src/main/res/values-zh/strings.xml +++ b/design/src/main/res/values-zh/strings.xml @@ -251,4 +251,7 @@ External Control Clash.Meta 服务已启动 Clash.Meta 服务已停止 + Force DNS Mapping + Parse Pure IP + Override Destination \ No newline at end of file diff --git a/design/src/main/res/values/strings.xml b/design/src/main/res/values/strings.xml index 90bc2341..a6c87acd 100644 --- a/design/src/main/res/values/strings.xml +++ b/design/src/main/res/values/strings.xml @@ -317,4 +317,7 @@ External Control Clash.Meta service started Clash.Meta service stopped + Force DNS Mapping + Parse Pure IP + Override Destination