mirror of
https://github.com/mamoe/mirai.git
synced 2025-03-23 13:50:12 +08:00
Trim log size
This commit is contained in:
parent
fe250735f3
commit
0e28121182
@ -5,10 +5,7 @@ import javafx.collections.ObservableList
|
||||
import javafx.stage.Modality
|
||||
import net.mamoe.mirai.Bot
|
||||
import net.mamoe.mirai.console.MiraiConsole
|
||||
import net.mamoe.mirai.console.graphical.model.BotModel
|
||||
import net.mamoe.mirai.console.graphical.model.ConsoleInfo
|
||||
import net.mamoe.mirai.console.graphical.model.PluginModel
|
||||
import net.mamoe.mirai.console.graphical.model.VerificationCodeModel
|
||||
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
|
||||
@ -17,6 +14,7 @@ import tornadofx.*
|
||||
|
||||
class MiraiGraphicalUIController : Controller(), MiraiConsoleUI {
|
||||
|
||||
private val settingModel = find<GlobalSettingModel>()
|
||||
private val loginSolver = GraphicalLoginSolver()
|
||||
private val cache = mutableMapOf<Long, BotModel>()
|
||||
val mainLog = observableListOf<String>()
|
||||
@ -34,9 +32,23 @@ class MiraiGraphicalUIController : Controller(), MiraiConsoleUI {
|
||||
fun sendCommand(command: String) = MiraiConsole.CommandProcessor.runConsoleCommandBlocking(command)
|
||||
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
when (identity) {
|
||||
0L -> mainLog.add(message)
|
||||
else -> cache[identity]?.logHistory?.add(message)
|
||||
0L -> mainLog.apply {
|
||||
add(message)
|
||||
mainLog.trim()
|
||||
}
|
||||
else -> cache[identity]?.logHistory?.apply {
|
||||
add(message)
|
||||
trim()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,17 @@
|
||||
package net.mamoe.mirai.console.graphical.model
|
||||
|
||||
import javafx.beans.property.SimpleLongProperty
|
||||
import tornadofx.ItemViewModel
|
||||
import tornadofx.getValue
|
||||
import tornadofx.setValue
|
||||
|
||||
class GlobalSetting {
|
||||
val maxLogNumProperty = SimpleLongProperty(4096)
|
||||
var maxLongNum: Long by maxLogNumProperty
|
||||
}
|
||||
|
||||
class GlobalSettingModel(setting: GlobalSetting) : ItemViewModel<GlobalSetting>(setting) {
|
||||
constructor() : this(GlobalSetting())
|
||||
|
||||
val maxLogNum = bind(GlobalSetting::maxLogNumProperty)
|
||||
}
|
@ -1,38 +1,45 @@
|
||||
package net.mamoe.mirai.console.graphical.view
|
||||
|
||||
import net.mamoe.mirai.console.graphical.controller.MiraiGraphicalUIController
|
||||
import net.mamoe.mirai.console.graphical.model.GlobalSettingModel
|
||||
import net.mamoe.mirai.console.graphical.util.jfxButton
|
||||
import net.mamoe.mirai.console.graphical.util.jfxTextfield
|
||||
import tornadofx.View
|
||||
import tornadofx.field
|
||||
import tornadofx.fieldset
|
||||
import tornadofx.form
|
||||
import tornadofx.*
|
||||
import java.awt.Desktop
|
||||
import java.io.File
|
||||
|
||||
class SettingsView : View() {
|
||||
|
||||
private val controller = find<MiraiGraphicalUIController>()
|
||||
private val settingModel = find<GlobalSettingModel>()
|
||||
|
||||
override val root = form {
|
||||
|
||||
fieldset {
|
||||
field {
|
||||
jfxButton("撤掉") { }
|
||||
jfxButton("保存") { }
|
||||
jfxButton("撤掉").action {
|
||||
settingModel.rollback()
|
||||
}
|
||||
jfxButton("保存").action {
|
||||
settingModel.commit()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fieldset("插件目录") {
|
||||
field {
|
||||
jfxTextfield("...") { isEditable = false }
|
||||
jfxButton("打开目录")
|
||||
jfxTextfield((System.getProperty("user.dir") + "/plugins/").replace("//", "/")) { isEditable = false }
|
||||
jfxButton("打开目录").action {
|
||||
(System.getProperty("user.dir") + "/plugins/").replace("//", "/").also { path ->
|
||||
Desktop.getDesktop().takeIf { it.isSupported(Desktop.Action.OPEN) }?.open(File(path))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fieldset("最大日志容量") {
|
||||
field {
|
||||
jfxTextfield("...") {
|
||||
|
||||
}
|
||||
jfxTextfield().bind(settingModel.maxLogNum)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user