diff --git a/app/src/main/java/io/nekohasekai/sagernet/database/DataStore.kt b/app/src/main/java/io/nekohasekai/sagernet/database/DataStore.kt index 41ad25c..c413ee6 100644 --- a/app/src/main/java/io/nekohasekai/sagernet/database/DataStore.kt +++ b/app/src/main/java/io/nekohasekai/sagernet/database/DataStore.kt @@ -155,6 +155,7 @@ object DataStore : OnPreferenceDataStoreChangeListener { var requireTransproxy by configurationStore.boolean(Key.REQUIRE_TRANSPROXY) var transproxyMode by configurationStore.stringToInt(Key.TRANSPROXY_MODE) var connectionTestURL by configurationStore.string(Key.CONNECTION_TEST_URL) { CONNECTION_TEST_URL } + var connectionTestConcurrent by configurationStore.int("connectionTestConcurrent") { 5 } var alwaysShowAddress by configurationStore.boolean(Key.ALWAYS_SHOW_ADDRESS) var tunImplementation by configurationStore.stringToInt(Key.TUN_IMPLEMENTATION) { TunImplementation.SYSTEM } diff --git a/app/src/main/java/io/nekohasekai/sagernet/ui/ConfigurationFragment.kt b/app/src/main/java/io/nekohasekai/sagernet/ui/ConfigurationFragment.kt index e7728d1..fc8eefe 100644 --- a/app/src/main/java/io/nekohasekai/sagernet/ui/ConfigurationFragment.kt +++ b/app/src/main/java/io/nekohasekai/sagernet/ui/ConfigurationFragment.kt @@ -517,9 +517,6 @@ class ConfigurationFragment @JvmOverloads constructor( } } } - R.id.action_connection_icmp_ping -> { - pingTest(true) - } R.id.action_connection_tcp_ping -> { pingTest(false) } @@ -611,6 +608,7 @@ class ConfigurationFragment @JvmOverloads constructor( if (DataStore.serviceState.started) SagerNet.stopService() } + @OptIn(DelicateCoroutinesApi::class) @Suppress("EXPERIMENTAL_API_USAGE") fun pingTest(icmpPing: Boolean) { val test = TestDialog() @@ -625,8 +623,11 @@ class ConfigurationFragment @JvmOverloads constructor( val profilesUnfiltered = SagerDatabase.proxyDao.getByGroup(group.id) test.proxyN = profilesUnfiltered.size val profiles = ConcurrentLinkedQueue(profilesUnfiltered) - val testPool = newFixedThreadPoolContext(5, "Connection test pool") - repeat(5) { + val testPool = newFixedThreadPoolContext( + DataStore.connectionTestConcurrent, + "Connection test pool" + ) + repeat(DataStore.connectionTestConcurrent) { testJobs.add(launch(testPool) { while (isActive) { val profile = profiles.poll() ?: break @@ -764,7 +765,7 @@ class ConfigurationFragment @JvmOverloads constructor( val profiles = ConcurrentLinkedQueue(profilesUnfiltered) val urlTest = UrlTest() // note: this is NOT in bg process - repeat(5) { + repeat(DataStore.connectionTestConcurrent) { testJobs.add(launch { while (isActive) { val profile = profiles.poll() ?: break diff --git a/app/src/main/java/io/nekohasekai/sagernet/widget/LinkOrContentPreference.kt b/app/src/main/java/io/nekohasekai/sagernet/widget/LinkOrContentPreference.kt index dffa94b..b4f03af 100644 --- a/app/src/main/java/io/nekohasekai/sagernet/widget/LinkOrContentPreference.kt +++ b/app/src/main/java/io/nekohasekai/sagernet/widget/LinkOrContentPreference.kt @@ -25,7 +25,7 @@ constructor( ) : EditTextPreference(context, attrs, defStyleAttr, defStyleRes) { init { - dialogLayoutResource = R.layout.layout_link_dialog + dialogLayoutResource = R.layout.layout_urltest_preference_dialog setOnBindEditTextListener { val linkLayout = it.rootView.findViewById(R.id.input_layout) diff --git a/app/src/main/java/io/nekohasekai/sagernet/widget/LinkPreference.kt b/app/src/main/java/io/nekohasekai/sagernet/widget/LinkPreference.kt deleted file mode 100644 index 110743e..0000000 --- a/app/src/main/java/io/nekohasekai/sagernet/widget/LinkPreference.kt +++ /dev/null @@ -1,71 +0,0 @@ -package io.nekohasekai.sagernet.widget - -import android.content.Context -import android.util.AttributeSet -import androidx.core.content.res.TypedArrayUtils -import androidx.core.widget.addTextChangedListener -import androidx.preference.EditTextPreference -import com.google.android.material.textfield.TextInputLayout -import io.nekohasekai.sagernet.R -import io.nekohasekai.sagernet.ktx.app -import io.nekohasekai.sagernet.ktx.readableMessage -import okhttp3.HttpUrl.Companion.toHttpUrl - -class LinkPreference -@JvmOverloads -constructor( - context: Context, - attrs: AttributeSet? = null, - defStyleAttr: Int = TypedArrayUtils.getAttr( - context, R.attr.editTextPreferenceStyle, - android.R.attr.editTextPreferenceStyle - ), - defStyleRes: Int = 0 -) : EditTextPreference(context, attrs, defStyleAttr, defStyleRes) { - -// var defaultValue: String? = null - - init { - dialogLayoutResource = R.layout.layout_link_dialog - - setOnBindEditTextListener { - val linkLayout = it.rootView.findViewById(R.id.input_layout) - fun validate() { - val link = it.text - if (link.isBlank()) { - linkLayout.isErrorEnabled = false - return - } - try { - val url = link.toString().toHttpUrl() - if ("http".equals(url.scheme, true)) { - linkLayout.error = app.getString(R.string.cleartext_http_warning) - linkLayout.isErrorEnabled = true - } else { - linkLayout.isErrorEnabled = false - } - } catch (e: Exception) { - linkLayout.error = e.readableMessage - linkLayout.isErrorEnabled = true - } - } - validate() - it.addTextChangedListener { - validate() - } - } - - setOnPreferenceChangeListener { _, newValue -> - if ((newValue as String).isBlank()) { -// text = defaultValue - false - } else try { - newValue.toHttpUrl() - true - } catch (ignored: Exception) { - false - } - } - } - -} \ No newline at end of file diff --git a/app/src/main/java/moe/matsuri/nb4a/ui/UrlTestPreference.kt b/app/src/main/java/moe/matsuri/nb4a/ui/UrlTestPreference.kt new file mode 100644 index 0000000..7a339b3 --- /dev/null +++ b/app/src/main/java/moe/matsuri/nb4a/ui/UrlTestPreference.kt @@ -0,0 +1,47 @@ +package moe.matsuri.nb4a.ui + +import android.content.Context +import android.util.AttributeSet +import android.widget.EditText +import androidx.core.content.res.TypedArrayUtils +import androidx.preference.EditTextPreference +import io.nekohasekai.sagernet.R +import io.nekohasekai.sagernet.database.DataStore + +class UrlTestPreference +@JvmOverloads +constructor( + context: Context, + attrs: AttributeSet? = null, + defStyleAttr: Int = TypedArrayUtils.getAttr( + context, R.attr.editTextPreferenceStyle, + android.R.attr.editTextPreferenceStyle + ), + defStyleRes: Int = 0 +) : EditTextPreference(context, attrs, defStyleAttr, defStyleRes) { + + var concurrent: EditText? = null + + init { + dialogLayoutResource = R.layout.layout_urltest_preference_dialog + + setOnBindEditTextListener { + concurrent = it.rootView.findViewById(R.id.edit_concurrent) + concurrent?.apply { + setText(DataStore.connectionTestConcurrent.toString()) + } + } + + setOnPreferenceChangeListener { _, _ -> + concurrent?.apply { + var newConcurrent = text?.toString()?.toIntOrNull() + if (newConcurrent == null || newConcurrent <= 0) { + newConcurrent = 5 + } + DataStore.connectionTestConcurrent = newConcurrent + } + true + } + } + +} \ No newline at end of file diff --git a/app/src/main/res/layout/layout_link_dialog.xml b/app/src/main/res/layout/layout_urltest_preference_dialog.xml similarity index 61% rename from app/src/main/res/layout/layout_link_dialog.xml rename to app/src/main/res/layout/layout_urltest_preference_dialog.xml index d5dc440..d1c2b9e 100644 --- a/app/src/main/res/layout/layout_link_dialog.xml +++ b/app/src/main/res/layout/layout_urltest_preference_dialog.xml @@ -10,18 +10,6 @@ android:layout_height="wrap_content" android:orientation="vertical"> - - + + + + + + + + + diff --git a/app/src/main/res/menu/add_profile_menu.xml b/app/src/main/res/menu/add_profile_menu.xml index 725e806..b6a6524 100644 --- a/app/src/main/res/menu/add_profile_menu.xml +++ b/app/src/main/res/menu/add_profile_menu.xml @@ -93,10 +93,6 @@ android:id="@+id/action_connection_test" android:title="@string/connection_test"> - diff --git a/app/src/main/res/values-zh-rCN/strings.xml b/app/src/main/res/values-zh-rCN/strings.xml index c6cc26a..5ba3efe 100644 --- a/app/src/main/res/values-zh-rCN/strings.xml +++ b/app/src/main/res/values-zh-rCN/strings.xml @@ -471,4 +471,7 @@ 重置连接 删除重复的服务器 TLS 伪装设置 + 长按设置项以设置自定义 MTU。 + 长按设置项以设置缓冲区大小。 + 测试并发 \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 88e00fe..3cf2cc1 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -514,5 +514,6 @@ Anyone can write advanced plugins, which can control NekoBox. please download an Long press the preference to set custom MTU. Long press the preference to set the buffer size. TLS Camouflage Settings + Test concurrency \ No newline at end of file diff --git a/app/src/main/res/xml/global_preferences.xml b/app/src/main/res/xml/global_preferences.xml index 91c1913..d5f61bd 100644 --- a/app/src/main/res/xml/global_preferences.xml +++ b/app/src/main/res/xml/global_preferences.xml @@ -215,7 +215,7 @@ -