mirror of
https://github.com/mamoe/mirai.git
synced 2025-01-03 02:29:21 +08:00
Add FrontendLoggingInitContext.invokeAfterInitialization
This commit is contained in:
parent
637fe1a5b9
commit
a94c98d990
@ -409,6 +409,11 @@ public interface MiraiConsoleImplementation : CoroutineScope {
|
||||
* 调用此函数会立即初始化平台日志实现. 在未完成准备工作前切勿使用此方法
|
||||
*/
|
||||
public fun acquirePlatformImplementation(): MiraiLogger.Factory
|
||||
|
||||
/**
|
||||
* 在完成 [MiraiLogger.Factory] 接管后马上执行 [action]
|
||||
*/
|
||||
public fun invokeAfterInitialization(action: () -> Unit)
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
@ -129,10 +129,15 @@ internal class MiraiConsoleImplementationBridge(
|
||||
// 3. [externalImplementation] decides how to log the message
|
||||
// 4. [externalImplementation] outputs by using [platform]
|
||||
val context = object : MiraiConsoleImplementation.FrontendLoggingInitContext {
|
||||
val pendingActions = mutableListOf<() -> Unit>()
|
||||
override fun acquirePlatformImplementation(): MiraiLogger.Factory {
|
||||
@Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
|
||||
return MiraiLoggerFactoryImplementationBridge.instance
|
||||
}
|
||||
|
||||
override fun invokeAfterInitialization(action: () -> Unit) {
|
||||
pendingActions.add(action)
|
||||
}
|
||||
}
|
||||
|
||||
val response = externalImplementation.createLoggerFactory(context)
|
||||
@ -142,6 +147,7 @@ internal class MiraiConsoleImplementationBridge(
|
||||
@Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
|
||||
MiraiLoggerFactoryImplementationBridge.freeze() // forbid any further overrides
|
||||
|
||||
context.pendingActions.forEach { it.invoke() }
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user