[core] Add QRCodeLoginListener.onCompleted

This commit is contained in:
Karlatemp 2023-03-27 00:55:54 +08:00
parent 434ef0cc39
commit e2d7332ac0
No known key found for this signature in database
GPG Key ID: BA173CA2B9956C59
4 changed files with 16 additions and 0 deletions

View File

@ -205,6 +205,7 @@ public abstract interface class net/mamoe/mirai/auth/QRCodeLoginListener {
public fun getQrCodeMargin ()I
public fun getQrCodeSize ()I
public fun getQrCodeStateUpdateInterval ()J
public fun onCompleted ()V
public abstract fun onFetchQRCode (Lnet/mamoe/mirai/Bot;[B)V
public fun onIntervalLoop ()V
public abstract fun onStateChanged (Lnet/mamoe/mirai/Bot;Lnet/mamoe/mirai/auth/QRCodeLoginListener$State;)V

View File

@ -205,6 +205,7 @@ public abstract interface class net/mamoe/mirai/auth/QRCodeLoginListener {
public fun getQrCodeMargin ()I
public fun getQrCodeSize ()I
public fun getQrCodeStateUpdateInterval ()J
public fun onCompleted ()V
public abstract fun onFetchQRCode (Lnet/mamoe/mirai/Bot;[B)V
public fun onIntervalLoop ()V
public abstract fun onStateChanged (Lnet/mamoe/mirai/Bot;Lnet/mamoe/mirai/auth/QRCodeLoginListener$State;)V

View File

@ -60,6 +60,12 @@ public interface QRCodeLoginListener {
public fun onIntervalLoop() {
}
/**
* 当二维码登录扫描完毕时执行, 在此执行资源释放
*/
public fun onCompleted() {
}
public enum class State {
/**
* 等待扫描中请在此阶段请扫描二维码.

View File

@ -112,6 +112,14 @@ internal class QRCodeLoginProcessorImpl(
}
override suspend fun process(handler: NetworkHandler, client: QQAndroidClient): QRCodeLoginData {
return try {
process0(handler, client)
} finally {
qrCodeLoginListener.onCompleted()
}
}
private suspend fun process0(handler: NetworkHandler, client: QQAndroidClient): QRCodeLoginData {
main@ while (true) {
val qrCodeData = requestQRCode(handler, client)
state@ while (true) {