mirror of
https://github.com/mamoe/mirai.git
synced 2025-02-13 20:02:57 +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.ConsoleCommandSender
|
||||
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.utils.MiraiConsoleUI
|
||||
import net.mamoe.mirai.network.WrongPasswordException
|
||||
@ -80,13 +81,14 @@ class MiraiGraphicalUIController : Controller(), MiraiConsoleUI {
|
||||
}
|
||||
|
||||
override suspend fun requestInput(hint: String): String {
|
||||
// TODO: 2020/3/21 HINT
|
||||
val model = VerificationCodeModel()
|
||||
find<VerificationCodeFragment>(Scope(model)).openModal(
|
||||
modality = Modality.APPLICATION_MODAL,
|
||||
resizable = false
|
||||
)
|
||||
return model.code.value
|
||||
var ret: String? = null
|
||||
|
||||
// UI必须在UI线程执行,requestInput在协程种被调用
|
||||
Platform.runLater {
|
||||
ret = InputDialog(hint).open()
|
||||
}
|
||||
while (ret == null) { delay(1000) }
|
||||
return ret!!
|
||||
}
|
||||
|
||||
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? {
|
||||
val code = VerificationCodeModel(VerificationCode(data))
|
||||
|
||||
// 界面需要运行在主线程
|
||||
// UI必须在UI线程执行,requestInput在协程种被调用
|
||||
Platform.runLater {
|
||||
find<VerificationCodeFragment>(Scope(code)).openModal(
|
||||
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 net.mamoe.mirai.console.graphical.model.VerificationCodeModel
|
||||
@ -30,7 +30,8 @@ class VerificationCodeFragment : Fragment() {
|
||||
this@VerificationCodeFragment.close()
|
||||
}
|
||||
button("取消").action {
|
||||
code.code.value = MAGIC_KEY
|
||||
code.code.value =
|
||||
MAGIC_KEY
|
||||
code.commit()
|
||||
this@VerificationCodeFragment.close()
|
||||
}
|
Loading…
Reference in New Issue
Block a user