mirror of
https://github.com/mamoe/mirai.git
synced 2025-01-09 18:00:33 +08:00
Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
ddd6aa45c3
@ -3,12 +3,15 @@ package net.mamoe.mirai.console.graphical.controller
|
||||
import javafx.application.Platform
|
||||
import javafx.collections.ObservableList
|
||||
import javafx.stage.Modality
|
||||
import javafx.stage.StageStyle
|
||||
import kotlinx.coroutines.delay
|
||||
import net.mamoe.mirai.Bot
|
||||
import net.mamoe.mirai.console.MiraiConsole
|
||||
import net.mamoe.mirai.console.graphical.model.*
|
||||
import net.mamoe.mirai.console.graphical.view.VerificationCodeFragment
|
||||
import net.mamoe.mirai.console.plugins.PluginManager
|
||||
import net.mamoe.mirai.console.utils.MiraiConsoleUI
|
||||
import net.mamoe.mirai.network.WrongPasswordException
|
||||
import net.mamoe.mirai.utils.LoginSolver
|
||||
import net.mamoe.mirai.utils.SimpleLogger.LogPriority
|
||||
import tornadofx.*
|
||||
@ -34,8 +37,6 @@ class MiraiGraphicalUIController : Controller(), MiraiConsoleUI {
|
||||
|
||||
override fun pushLog(identity: Long, message: String) = Platform.runLater {
|
||||
fun ObservableList<*>.trim() {
|
||||
println(size)
|
||||
println(settingModel.item.maxLongNum)
|
||||
if (size > settingModel.item.maxLongNum) {
|
||||
this.removeAt(0)
|
||||
}
|
||||
@ -99,7 +100,27 @@ class MiraiGraphicalUIController : Controller(), MiraiConsoleUI {
|
||||
|
||||
class GraphicalLoginSolver : LoginSolver() {
|
||||
override suspend fun onSolvePicCaptcha(bot: Bot, data: ByteArray): String? {
|
||||
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
|
||||
val code = VerificationCodeModel(VerificationCode(data))
|
||||
|
||||
// 界面需要运行在主线程
|
||||
Platform.runLater {
|
||||
find<VerificationCodeFragment>(Scope(code)).openModal(
|
||||
stageStyle = StageStyle.UNDECORATED,
|
||||
escapeClosesWindow = false,
|
||||
modality = Modality.NONE,
|
||||
resizable = false,
|
||||
block = true
|
||||
)
|
||||
}
|
||||
|
||||
// 阻塞协程直到验证码已经输入
|
||||
while (code.isDirty || code.code.value == null) {
|
||||
delay(1000)
|
||||
if (code.code.value === VerificationCodeFragment.MAGIC_KEY) {
|
||||
throw WrongPasswordException("取消登录")
|
||||
}
|
||||
}
|
||||
return code.code.value
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,17 +1,26 @@
|
||||
package net.mamoe.mirai.console.graphical.model
|
||||
|
||||
import javafx.beans.property.SimpleObjectProperty
|
||||
import javafx.beans.property.SimpleStringProperty
|
||||
import tornadofx.ItemViewModel
|
||||
import tornadofx.getValue
|
||||
import tornadofx.setValue
|
||||
|
||||
class VerificationCode {
|
||||
val codeProperty = SimpleStringProperty("")
|
||||
var code: String by codeProperty
|
||||
class VerificationCode(data: ByteArray = ByteArray(0)) {
|
||||
val codeProperty = SimpleStringProperty(null)
|
||||
var code: String? by codeProperty
|
||||
|
||||
val dataProperty: SimpleObjectProperty<ByteArray> = SimpleObjectProperty()
|
||||
val data: ByteArray by dataProperty
|
||||
|
||||
init {
|
||||
dataProperty.set(data)
|
||||
}
|
||||
}
|
||||
|
||||
class VerificationCodeModel(code: VerificationCode) : ItemViewModel<VerificationCode>(code) {
|
||||
constructor() : this(VerificationCode())
|
||||
|
||||
val code = bind(VerificationCode::codeProperty)
|
||||
val data = bind(VerificationCode::dataProperty)
|
||||
}
|
@ -5,5 +5,8 @@ import tornadofx.View
|
||||
|
||||
class Decorator : View() {
|
||||
|
||||
override val root = JFXDecorator(primaryStage, find<PrimaryView>().root)
|
||||
override val root = JFXDecorator(primaryStage, find<PrimaryView>().root).apply {
|
||||
prefWidth = 1000.0
|
||||
prefHeight = 650.0
|
||||
}
|
||||
}
|
@ -6,6 +6,7 @@ import javafx.scene.control.Tab
|
||||
import javafx.scene.control.TabPane
|
||||
import javafx.scene.image.Image
|
||||
import javafx.scene.input.KeyCode
|
||||
import javafx.stage.FileChooser
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import net.mamoe.mirai.console.graphical.controller.MiraiGraphicalUIController
|
||||
import net.mamoe.mirai.console.graphical.model.BotModel
|
||||
@ -16,12 +17,10 @@ import tornadofx.*
|
||||
class PrimaryView : View() {
|
||||
|
||||
private val controller = find<MiraiGraphicalUIController>()
|
||||
private lateinit var mainTabPane: TabPane
|
||||
|
||||
override val root = borderpane {
|
||||
|
||||
prefWidth = 1000.0
|
||||
prefHeight = 650.0
|
||||
|
||||
left = vbox {
|
||||
|
||||
imageview(Image(PrimaryView::class.java.classLoader.getResourceAsStream("logo.png")))
|
||||
@ -71,29 +70,66 @@ class PrimaryView : View() {
|
||||
|
||||
center = jfxTabPane {
|
||||
|
||||
tab("Login").content = find<LoginView>().root
|
||||
logTab("Main", controller.mainLog, closeable = false)
|
||||
|
||||
tab("Plugins").content = find<PluginsView>().root
|
||||
|
||||
tab("Settings").content = find<SettingsView>().root
|
||||
|
||||
logTab("Main", controller.mainLog)
|
||||
tab("Login").content = find<LoginView>().root
|
||||
|
||||
mainTabPane = this
|
||||
}
|
||||
}
|
||||
|
||||
fun Tab.select() = apply {
|
||||
if (!mainTabPane.tabs.contains(this)) mainTabPane.tabs.add(this)
|
||||
mainTabPane.selectionModel.select(this)
|
||||
}
|
||||
}
|
||||
|
||||
private fun TabPane.logTab(
|
||||
text: String? = null,
|
||||
logs: ObservableList<String>,
|
||||
closeable: Boolean = true,
|
||||
op: Tab.() -> Unit = {}
|
||||
) = tab(text) {
|
||||
listview(logs) {
|
||||
|
||||
fitToParentSize()
|
||||
cellFormat {
|
||||
graphic = label(it) {
|
||||
maxWidthProperty().bind(this@listview.widthProperty())
|
||||
isWrapText = true
|
||||
vbox {
|
||||
buttonbar {
|
||||
|
||||
button("导出日志").action {
|
||||
val path = chooseFile(
|
||||
"选择保存路径",
|
||||
arrayOf(FileChooser.ExtensionFilter("日志", "txt")),
|
||||
FileChooserMode.Save
|
||||
) {
|
||||
initialFileName = "$text.txt"
|
||||
}
|
||||
runAsyncWithOverlay {
|
||||
path.firstOrNull()?.run {
|
||||
if (!exists()) createNewFile()
|
||||
writer().use {
|
||||
logs.forEach { log -> it.appendln(log) }
|
||||
}
|
||||
true
|
||||
} ?: false
|
||||
}.ui {// isSucceed: Boolean ->
|
||||
// notify something
|
||||
}
|
||||
|
||||
if (closeable) button("关闭").action { close() }
|
||||
}
|
||||
}
|
||||
|
||||
listview(logs) {
|
||||
|
||||
fitToParentSize()
|
||||
cellFormat {
|
||||
graphic = label(it) {
|
||||
maxWidthProperty().bind(this@listview.widthProperty())
|
||||
isWrapText = true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,16 +1,38 @@
|
||||
package net.mamoe.mirai.console.graphical.view
|
||||
|
||||
import javafx.scene.image.Image
|
||||
import net.mamoe.mirai.console.graphical.model.VerificationCodeModel
|
||||
import tornadofx.*
|
||||
import java.io.ByteArrayInputStream
|
||||
|
||||
class VerificationCodeFragment : Fragment() {
|
||||
|
||||
companion object {
|
||||
val MAGIC_KEY = String("CANCEL".toByteArray())
|
||||
}
|
||||
|
||||
val code = find<VerificationCodeModel>()
|
||||
|
||||
override val root = vbox {
|
||||
//TODO: 显示验证码
|
||||
// 显示验证码
|
||||
imageview(Image(ByteArrayInputStream(code.data.value)))
|
||||
|
||||
form {
|
||||
fieldset {
|
||||
field("验证码") {
|
||||
textfield()
|
||||
textfield(code.code)
|
||||
}
|
||||
}
|
||||
|
||||
buttonbar {
|
||||
button("提交").action {
|
||||
code.commit()
|
||||
this@VerificationCodeFragment.close()
|
||||
}
|
||||
button("取消").action {
|
||||
code.code.value = MAGIC_KEY
|
||||
code.commit()
|
||||
this@VerificationCodeFragment.close()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user