mirror of
https://github.com/mamoe/mirai.git
synced 2025-03-24 14:30:09 +08:00
Fix the resource leak when closing TxCaptchaHelper(Swing) directly
This commit is contained in:
parent
c89d31cef6
commit
1e95482158
@ -11,15 +11,13 @@ package net.mamoe.mirai.utils
|
||||
|
||||
import io.ktor.client.*
|
||||
import io.ktor.client.request.*
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.isActive
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.*
|
||||
import net.mamoe.mirai.Mirai
|
||||
|
||||
internal abstract class TxCaptchaHelper {
|
||||
private val newClient: Boolean
|
||||
val client: HttpClient
|
||||
private lateinit var queue: Job
|
||||
|
||||
init {
|
||||
var newClient = false
|
||||
@ -62,5 +60,10 @@ internal abstract class TxCaptchaHelper {
|
||||
if (newClient) {
|
||||
queue.invokeOnCompletion { client.close() }
|
||||
}
|
||||
this.queue = queue
|
||||
}
|
||||
|
||||
fun dispose() {
|
||||
queue.cancel()
|
||||
}
|
||||
}
|
||||
|
@ -86,6 +86,7 @@ public object SwingSolver : LoginSolver() {
|
||||
}
|
||||
}
|
||||
helper.start(this, url)
|
||||
txhelperSolver.def.invokeOnCompletion { helper.dispose() }
|
||||
solver.def.complete(txhelperSolver.openAndWait().trim())
|
||||
}
|
||||
openWithTxCaptchaHelper.onClick { doClickEvent() }
|
||||
|
Loading…
Reference in New Issue
Block a user