Commit 13460b93 authored by jiahua.liu's avatar jiahua.liu

Mirai Console Fix

parent bb244a8e
...@@ -117,7 +117,8 @@ object MiraiConsoleTerminalUI : MiraiConsoleUI { ...@@ -117,7 +117,8 @@ object MiraiConsoleTerminalUI : MiraiConsoleUI {
} }
} }
pushLog(0, "[Login Solver]请输入 4 位字母验证码. 若要更换验证码, 请直接回车") pushLog(0, "[Login Solver]请输入 4 位字母验证码. 若要更换验证码, 请直接回车")
return requestInput("[Login Solver]请输入 4 位字母验证码. 若要更换验证码, 请直接回车")!!.takeUnless { it.isEmpty() || it.length != 4 } return requestInput("[Login Solver]请输入 4 位字母验证码. 若要更换验证码, 请直接回车")!!
.takeUnless { it.isEmpty() || it.length != 4 }
.also { .also {
pushLog(0, "[Login Solver]正在提交[$it]中...") pushLog(0, "[Login Solver]正在提交[$it]中...")
} }
...@@ -133,7 +134,6 @@ object MiraiConsoleTerminalUI : MiraiConsoleUI { ...@@ -133,7 +134,6 @@ object MiraiConsoleTerminalUI : MiraiConsoleUI {
} }
} }
override suspend fun onSolveUnsafeDeviceLoginVerify(bot: Bot, url: String): String? { override suspend fun onSolveUnsafeDeviceLoginVerify(bot: Bot, url: String): String? {
pushLog(0, "[Login Solver]需要进行账户安全认证") pushLog(0, "[Login Solver]需要进行账户安全认证")
pushLog(0, "[Login Solver]该账户有[设备锁]/[不常用登陆地点]/[不常用设备登陆]的问题") pushLog(0, "[Login Solver]该账户有[设备锁]/[不常用登陆地点]/[不常用设备登陆]的问题")
...@@ -235,13 +235,17 @@ object MiraiConsoleTerminalUI : MiraiConsoleUI { ...@@ -235,13 +235,17 @@ object MiraiConsoleTerminalUI : MiraiConsoleUI {
var lastJob: Job? = null var lastJob: Job? = null
terminal.addResizeListener(TerminalResizeListener { terminal1: Terminal, newSize: TerminalSize -> terminal.addResizeListener(TerminalResizeListener { terminal1: Terminal, newSize: TerminalSize ->
lastJob = GlobalScope.launch { lastJob = GlobalScope.launch {
delay(300) try {
if (lastJob == coroutineContext[Job]) { delay(300)
terminal.clearScreen() if (lastJob == coroutineContext[Job]) {
//inited = false terminal.clearScreen()
update() //inited = false
redrawCommand() update()
redrawLogs(log[screens[currentScreenId]]!!) redrawCommand()
redrawLogs(log[screens[currentScreenId]]!!)
}
} catch (e: Exception) {
pushLog(0, "[UI ERROR] ${e.message}")
} }
} }
}) })
...@@ -264,45 +268,53 @@ object MiraiConsoleTerminalUI : MiraiConsoleUI { ...@@ -264,45 +268,53 @@ object MiraiConsoleTerminalUI : MiraiConsoleUI {
System.setErr(System.out) System.setErr(System.out)
update() try {
update()
} catch (e: Exception) {
pushLog(0, "[UI ERROR] ${e.message}")
}
val charList = listOf(',', '.', '/', '@', '#', '$', '%', '^', '&', '*', '(', ')', '_', '=', '+', '!', ' ') val charList = listOf(',', '.', '/', '@', '#', '$', '%', '^', '&', '*', '(', ')', '_', '=', '+', '!', ' ')
thread { thread {
while (true) { while (true) {
var keyStroke: KeyStroke = terminal.readInput() try {
var keyStroke: KeyStroke = terminal.readInput()
when (keyStroke.keyType) {
KeyType.ArrowLeft -> { when (keyStroke.keyType) {
currentScreenId = KeyType.ArrowLeft -> {
getLeftScreenId() currentScreenId =
clearRows(2) getLeftScreenId()
cleanPage() clearRows(2)
update() cleanPage()
} update()
KeyType.ArrowRight -> { }
currentScreenId = KeyType.ArrowRight -> {
getRightScreenId() currentScreenId =
clearRows(2) getRightScreenId()
cleanPage() clearRows(2)
update() cleanPage()
} update()
KeyType.Enter -> { }
provideInput(commandBuilder.toString()) KeyType.Enter -> {
emptyCommand() provideInput(commandBuilder.toString())
} emptyCommand()
KeyType.Escape -> { }
exitProcess(0) KeyType.Escape -> {
} exitProcess(0)
else -> { }
if (keyStroke.character != null) { else -> {
if (keyStroke.character.toInt() == 8) { if (keyStroke.character != null) {
deleteCommandChar() if (keyStroke.character.toInt() == 8) {
} deleteCommandChar()
if (keyStroke.character.isLetterOrDigit() || charList.contains(keyStroke.character)) { }
addCommandChar(keyStroke.character) if (keyStroke.character.isLetterOrDigit() || charList.contains(keyStroke.character)) {
addCommandChar(keyStroke.character)
}
} }
} }
} }
} catch (e: Exception) {
pushLog(0, "[UI ERROR] ${e.message}")
} }
} }
} }
...@@ -542,13 +554,17 @@ object MiraiConsoleTerminalUI : MiraiConsoleUI { ...@@ -542,13 +554,17 @@ object MiraiConsoleTerminalUI : MiraiConsoleUI {
terminal.flush() terminal.flush()
} else { } else {
lastEmpty = GlobalScope.launch { lastEmpty = GlobalScope.launch {
delay(100) try {
if (lastEmpty == coroutineContext[Job]) { delay(100)
terminal.clearScreen() if (lastEmpty == coroutineContext[Job]) {
//inited = false terminal.clearScreen()
update() //inited = false
redrawCommand() update()
redrawLogs(log[screens[currentScreenId]]!!) redrawCommand()
redrawLogs(log[screens[currentScreenId]]!!)
}
} catch (e: Exception) {
pushLog(0, "[UI ERROR] ${e.message}")
} }
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment