mirror of
https://github.com/MatsuriDayo/NekoBoxForAndroid.git
synced 2025-12-19 06:30:05 +08:00
fix test cancel
This commit is contained in:
parent
6c3eea7ef9
commit
a75a15146e
@ -110,7 +110,7 @@ import okhttp3.internal.closeQuietly
|
|||||||
import java.net.InetSocketAddress
|
import java.net.InetSocketAddress
|
||||||
import java.net.Socket
|
import java.net.Socket
|
||||||
import java.net.UnknownHostException
|
import java.net.UnknownHostException
|
||||||
import java.util.Collections
|
import java.util.concurrent.ConcurrentHashMap
|
||||||
import java.util.concurrent.ConcurrentLinkedQueue
|
import java.util.concurrent.ConcurrentLinkedQueue
|
||||||
import java.util.concurrent.atomic.AtomicInteger
|
import java.util.concurrent.atomic.AtomicInteger
|
||||||
import java.util.zip.ZipInputStream
|
import java.util.zip.ZipInputStream
|
||||||
@ -608,22 +608,30 @@ class ConfigurationFragment @JvmOverloads constructor(
|
|||||||
lateinit var cancel: () -> Unit
|
lateinit var cancel: () -> Unit
|
||||||
lateinit var minimize: () -> Unit
|
lateinit var minimize: () -> Unit
|
||||||
|
|
||||||
var dialogHidden = false
|
val dialogStatus = AtomicInteger(0) // 1: hidden 2: cancelled
|
||||||
var notification: ConnectionTestNotification? = null
|
var notification: ConnectionTestNotification? = null
|
||||||
|
|
||||||
val results = Collections.synchronizedSet(mutableSetOf<ProxyEntity>())
|
val results: MutableSet<ProxyEntity> = ConcurrentHashMap.newKeySet()
|
||||||
var proxyN = 0
|
var proxyN = 0
|
||||||
val finishedN = AtomicInteger(0)
|
val finishedN = AtomicInteger(0)
|
||||||
|
|
||||||
fun update(profile: ProxyEntity) {
|
fun update(profile: ProxyEntity) {
|
||||||
results.add(profile)
|
if (dialogStatus.get() != 2) {
|
||||||
|
results.add(profile)
|
||||||
|
}
|
||||||
runOnMainDispatcher {
|
runOnMainDispatcher {
|
||||||
val context = context ?: return@runOnMainDispatcher
|
val context = context ?: return@runOnMainDispatcher
|
||||||
|
val progress = finishedN.addAndGet(1)
|
||||||
|
val status = dialogStatus.get()
|
||||||
|
notification?.updateNotification(
|
||||||
|
progress,
|
||||||
|
proxyN,
|
||||||
|
progress >= proxyN || status == 2
|
||||||
|
)
|
||||||
|
if (status >= 1) return@runOnMainDispatcher
|
||||||
if (!isAdded) return@runOnMainDispatcher
|
if (!isAdded) return@runOnMainDispatcher
|
||||||
|
|
||||||
val progress = finishedN.addAndGet(1)
|
// refresh dialog
|
||||||
notification?.updateNotification(progress, proxyN, progress >= proxyN)
|
|
||||||
if (dialogHidden) return@runOnMainDispatcher
|
|
||||||
|
|
||||||
var profileStatusText: String? = null
|
var profileStatusText: String? = null
|
||||||
var profileStatusColor = 0
|
var profileStatusColor = 0
|
||||||
@ -797,8 +805,11 @@ class ConfigurationFragment @JvmOverloads constructor(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
test.cancel = {
|
test.cancel = {
|
||||||
|
test.dialogStatus.set(2)
|
||||||
dialog.dismiss()
|
dialog.dismiss()
|
||||||
runOnDefaultDispatcher {
|
runOnDefaultDispatcher {
|
||||||
|
mainJob.cancel()
|
||||||
|
testJobs.forEach { it.cancel() }
|
||||||
test.results.forEach {
|
test.results.forEach {
|
||||||
try {
|
try {
|
||||||
ProfileManager.updateProfile(it)
|
ProfileManager.updateProfile(it)
|
||||||
@ -807,13 +818,11 @@ class ConfigurationFragment @JvmOverloads constructor(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
GroupManager.postReload(DataStore.currentGroupId())
|
GroupManager.postReload(DataStore.currentGroupId())
|
||||||
mainJob.cancel()
|
|
||||||
testJobs.forEach { it.cancel() }
|
|
||||||
DataStore.runningTest = false
|
DataStore.runningTest = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
test.minimize = {
|
test.minimize = {
|
||||||
test.dialogHidden = true
|
test.dialogStatus.set(1)
|
||||||
test.notification = ConnectionTestNotification(
|
test.notification = ConnectionTestNotification(
|
||||||
dialog.context,
|
dialog.context,
|
||||||
"[${group.displayName()}] ${getString(R.string.connection_test)}"
|
"[${group.displayName()}] ${getString(R.string.connection_test)}"
|
||||||
@ -865,8 +874,11 @@ class ConfigurationFragment @JvmOverloads constructor(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
test.cancel = {
|
test.cancel = {
|
||||||
|
test.dialogStatus.set(2)
|
||||||
dialog.dismiss()
|
dialog.dismiss()
|
||||||
runOnDefaultDispatcher {
|
runOnDefaultDispatcher {
|
||||||
|
mainJob.cancel()
|
||||||
|
testJobs.forEach { it.cancel() }
|
||||||
test.results.forEach {
|
test.results.forEach {
|
||||||
try {
|
try {
|
||||||
ProfileManager.updateProfile(it)
|
ProfileManager.updateProfile(it)
|
||||||
@ -875,13 +887,11 @@ class ConfigurationFragment @JvmOverloads constructor(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
GroupManager.postReload(DataStore.currentGroupId())
|
GroupManager.postReload(DataStore.currentGroupId())
|
||||||
mainJob.cancel()
|
|
||||||
testJobs.forEach { it.cancel() }
|
|
||||||
DataStore.runningTest = false
|
DataStore.runningTest = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
test.minimize = {
|
test.minimize = {
|
||||||
test.dialogHidden = true
|
test.dialogStatus.set(1)
|
||||||
test.notification = ConnectionTestNotification(
|
test.notification = ConnectionTestNotification(
|
||||||
dialog.context,
|
dialog.context,
|
||||||
"[${group.displayName()}] ${getString(R.string.connection_test)}"
|
"[${group.displayName()}] ${getString(R.string.connection_test)}"
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
PACKAGE_NAME=moe.nb4a
|
PACKAGE_NAME=moe.nb4a
|
||||||
VERSION_NAME=1.3.9
|
VERSION_NAME=1.3.9
|
||||||
PRE_VERSION_NAME=pre-1.4.0-20250905-1
|
PRE_VERSION_NAME=pre-1.4.0-20250906-1
|
||||||
VERSION_CODE=43
|
VERSION_CODE=43
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user