Fix build

This commit is contained in:
Him188 2020-06-27 01:28:19 +08:00
parent 9f8ce56f15
commit 91d2b0b7d2
3 changed files with 23 additions and 57 deletions

View File

@ -15,6 +15,7 @@ import kotlinx.io.charsets.Charset
import net.mamoe.mirai.Bot
import net.mamoe.mirai.console.MiraiConsole.INSTANCE
import net.mamoe.mirai.console.command.ConsoleCommandOwner
import net.mamoe.mirai.console.command.ConsoleCommandSender
import net.mamoe.mirai.console.plugin.PluginLoader
import net.mamoe.mirai.console.plugin.center.CuiPluginCenter
import net.mamoe.mirai.console.plugin.center.PluginCenter
@ -93,61 +94,42 @@ internal object MiraiConsoleBuildConstants { // auto-filled on build (task :mira
internal object MiraiConsoleInternal : CoroutineScope, IMiraiConsole, MiraiConsole {
override val pluginCenter: PluginCenter get() = CuiPluginCenter
private val instance: IMiraiConsole
get() = MiraiConsoleInitializer.instance
/**
* `mirai-console` build
*
* UTC+8 时间
*/
override val buildDate: Date
get() = MiraiConsoleBuildConstants.buildDate
/**
* `mirai-console` 版本
*/
private val instance: IMiraiConsole get() = MiraiConsoleInitializer.instance
override val buildDate: Date get() = MiraiConsoleBuildConstants.buildDate
override val version: String get() = MiraiConsoleBuildConstants.version
/**
* Console 运行路径
*/
override val rootDir: File get() = instance.rootDir
/**
* Console 前端接口
*/
override val frontEnd: MiraiConsoleFrontEnd get() = instance.frontEnd
/**
* 与前端交互所使用的 Logger
*/
@MiraiExperimentalAPI
override val mainLogger: MiraiLogger
get() = instance.mainLogger
override val coroutineContext: CoroutineContext get() = instance.coroutineContext
override val builtInPluginLoaders: List<PluginLoader<*, *>> get() = instance.builtInPluginLoaders
override val consoleCommandOwner: ConsoleCommandOwner
get() = instance.consoleCommandOwner
override val consoleCommandOwner: ConsoleCommandOwner get() = instance.consoleCommandOwner
override val consoleCommandSender: ConsoleCommandSender get() = instance.consoleCommandSender
init {
DefaultLogger = { identity -> this.newLogger(identity) }
this.coroutineContext[Job]!!.invokeOnCompletion {
Bot.botInstances.forEach { kotlin.runCatching { it.close() }.exceptionOrNull()?.let(mainLogger::error) }
}
}
@MiraiExperimentalAPI
override fun newLogger(identity: String?): MiraiLogger = frontEnd.loggerFor(identity)
internal fun initialize() {
if (coroutineContext[Job] == null) {
throw IllegalMiraiConsoleImplementationError("The coroutineContext given to MiraiConsole must have a Job in it.")
}
this.coroutineContext[Job]!!.invokeOnCompletion {
Bot.botInstances.forEach { kotlin.runCatching { it.close() }.exceptionOrNull()?.let(mainLogger::error) }
}
// Only for initialize
}
}
class IllegalMiraiConsoleImplementationError(
override val message: String?
) : Error()
// 前端使用
internal interface IMiraiConsole : CoroutineScope {
@ -173,6 +155,9 @@ internal interface IMiraiConsole : CoroutineScope {
@Suppress("WRONG_MODIFIER_CONTAINING_DECLARATION")
internal val consoleCommandOwner: ConsoleCommandOwner
@Suppress("WRONG_MODIFIER_CONTAINING_DECLARATION")
internal val consoleCommandSender: ConsoleCommandSender
}
/**

View File

@ -22,13 +22,6 @@ import net.mamoe.mirai.utils.MiraiLogger
interface MiraiConsoleFrontEnd {
fun loggerFor(identity: String?): MiraiLogger
/**
* UI 层准备接受新增的一个BOT
*/
fun prePushBot(
identity: Long
)
/**
* UI 层接受一个新的bot
* */
@ -41,18 +34,8 @@ interface MiraiConsoleFrontEnd {
*/
suspend fun requestInput(hint: String): String
/**
* UI 层更新 bot 管理员的数据
*/
fun pushBotAdminStatus(
identity: Long,
admins: List<Long>
)
/**
* UI 层创建一个 [LoginSolver]
*/
fun createLoginSolver(): LoginSolver
}

View File

@ -33,22 +33,20 @@ object JarPluginLoader : AbstractFilePluginLoader<JvmPlugin, JvmPluginDescriptio
}
@MiraiExperimentalAPI
val settingStorage: SettingStorage = TODO()
val settingStorage: SettingStorage by lazy { TODO() }
override val coroutineContext: CoroutineContext by lazy {
MiraiConsole.coroutineContext + SupervisorJob(
MiraiConsole.coroutineContext[Job]
) + CoroutineExceptionHandler { _, throwable ->
logger.error("Unhandled Jar plugin exception: ${throwable.message}", throwable)
}.also { init() }
}
}
private val supervisor: Job = coroutineContext[Job]!!
private val classLoader: PluginsLoader =
PluginsLoader(this.javaClass.classLoader)
private val classLoader: PluginsLoader by lazy { PluginsLoader(this.javaClass.classLoader) }
init {
supervisor.invokeOnCompletion {
private fun init() { // delayed
coroutineContext[Job]!!.invokeOnCompletion {
classLoader.clear()
}
}