mirror of
https://github.com/mamoe/mirai.git
synced 2025-02-19 15:40:15 +08:00
Adapt requestInput
This commit is contained in:
parent
765c240ffb
commit
97b566f60e
@ -9,7 +9,8 @@ import net.mamoe.mirai.Bot
|
|||||||
import net.mamoe.mirai.console.command.CommandManager
|
import net.mamoe.mirai.console.command.CommandManager
|
||||||
import net.mamoe.mirai.console.command.ConsoleCommandSender
|
import net.mamoe.mirai.console.command.ConsoleCommandSender
|
||||||
import net.mamoe.mirai.console.graphical.model.*
|
import net.mamoe.mirai.console.graphical.model.*
|
||||||
import net.mamoe.mirai.console.graphical.view.VerificationCodeFragment
|
import net.mamoe.mirai.console.graphical.view.dialog.InputDialog
|
||||||
|
import net.mamoe.mirai.console.graphical.view.dialog.VerificationCodeFragment
|
||||||
import net.mamoe.mirai.console.plugins.PluginManager
|
import net.mamoe.mirai.console.plugins.PluginManager
|
||||||
import net.mamoe.mirai.console.utils.MiraiConsoleUI
|
import net.mamoe.mirai.console.utils.MiraiConsoleUI
|
||||||
import net.mamoe.mirai.network.WrongPasswordException
|
import net.mamoe.mirai.network.WrongPasswordException
|
||||||
@ -80,13 +81,14 @@ class MiraiGraphicalUIController : Controller(), MiraiConsoleUI {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun requestInput(hint: String): String {
|
override suspend fun requestInput(hint: String): String {
|
||||||
// TODO: 2020/3/21 HINT
|
var ret: String? = null
|
||||||
val model = VerificationCodeModel()
|
|
||||||
find<VerificationCodeFragment>(Scope(model)).openModal(
|
// UI必须在UI线程执行,requestInput在协程种被调用
|
||||||
modality = Modality.APPLICATION_MODAL,
|
Platform.runLater {
|
||||||
resizable = false
|
ret = InputDialog(hint).open()
|
||||||
)
|
}
|
||||||
return model.code.value
|
while (ret == null) { delay(1000) }
|
||||||
|
return ret!!
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun pushBotAdminStatus(identity: Long, admins: List<Long>) = Platform.runLater {
|
override fun pushBotAdminStatus(identity: Long, admins: List<Long>) = Platform.runLater {
|
||||||
@ -104,7 +106,7 @@ class GraphicalLoginSolver : LoginSolver() {
|
|||||||
override suspend fun onSolvePicCaptcha(bot: Bot, data: ByteArray): String? {
|
override suspend fun onSolvePicCaptcha(bot: Bot, data: ByteArray): String? {
|
||||||
val code = VerificationCodeModel(VerificationCode(data))
|
val code = VerificationCodeModel(VerificationCode(data))
|
||||||
|
|
||||||
// 界面需要运行在主线程
|
// UI必须在UI线程执行,requestInput在协程种被调用
|
||||||
Platform.runLater {
|
Platform.runLater {
|
||||||
find<VerificationCodeFragment>(Scope(code)).openModal(
|
find<VerificationCodeFragment>(Scope(code)).openModal(
|
||||||
stageStyle = StageStyle.UNDECORATED,
|
stageStyle = StageStyle.UNDECORATED,
|
||||||
|
@ -0,0 +1,39 @@
|
|||||||
|
package net.mamoe.mirai.console.graphical.view.dialog
|
||||||
|
|
||||||
|
import javafx.scene.control.TextField
|
||||||
|
import javafx.stage.Modality
|
||||||
|
import javafx.stage.StageStyle
|
||||||
|
import tornadofx.*
|
||||||
|
|
||||||
|
class InputDialog(title: String) : Fragment() {
|
||||||
|
|
||||||
|
private lateinit var input: TextField
|
||||||
|
|
||||||
|
init {
|
||||||
|
titleProperty.value = title
|
||||||
|
}
|
||||||
|
|
||||||
|
override val root = form {
|
||||||
|
|
||||||
|
fieldset {
|
||||||
|
field(title) {
|
||||||
|
input = textfield("")
|
||||||
|
}
|
||||||
|
|
||||||
|
buttonbar {
|
||||||
|
|
||||||
|
button("提交").action { close() }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun open(): String {
|
||||||
|
// 阻塞窗口直到关闭
|
||||||
|
openModal(
|
||||||
|
stageStyle = StageStyle.DECORATED,
|
||||||
|
modality = Modality.APPLICATION_MODAL,
|
||||||
|
block = true
|
||||||
|
)
|
||||||
|
return input.text
|
||||||
|
}
|
||||||
|
}
|
@ -1,4 +1,4 @@
|
|||||||
package net.mamoe.mirai.console.graphical.view
|
package net.mamoe.mirai.console.graphical.view.dialog
|
||||||
|
|
||||||
import javafx.scene.image.Image
|
import javafx.scene.image.Image
|
||||||
import net.mamoe.mirai.console.graphical.model.VerificationCodeModel
|
import net.mamoe.mirai.console.graphical.model.VerificationCodeModel
|
||||||
@ -30,7 +30,8 @@ class VerificationCodeFragment : Fragment() {
|
|||||||
this@VerificationCodeFragment.close()
|
this@VerificationCodeFragment.close()
|
||||||
}
|
}
|
||||||
button("取消").action {
|
button("取消").action {
|
||||||
code.code.value = MAGIC_KEY
|
code.code.value =
|
||||||
|
MAGIC_KEY
|
||||||
code.commit()
|
code.commit()
|
||||||
this@VerificationCodeFragment.close()
|
this@VerificationCodeFragment.close()
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user