mirror of
https://github.com/mamoe/mirai.git
synced 2025-03-24 14:30:09 +08:00
Make MiraiConsoleImplementationBridge class, add MiraiConsoleImplementation.origin
. MiraiConsoleImplementation.Companion.getInstance
will now return the bridge object instead of the user-defined implementation.
This commit is contained in:
parent
5af3d63e25
commit
2ebd017786
@ -39,7 +39,7 @@ object Versions {
|
||||
const val coroutinesIo = "0.1.16"
|
||||
|
||||
const val blockingBridge = "2.0.0-160.3"
|
||||
const val dynamicDelegation = "0.1.1-160.1"
|
||||
const val dynamicDelegation = "0.2.0-160.1"
|
||||
|
||||
const val androidGradlePlugin = "4.1.1"
|
||||
const val android = "4.1.1.4"
|
||||
|
@ -1,10 +1,10 @@
|
||||
/*
|
||||
* Copyright 2019-2021 Mamoe Technologies and contributors.
|
||||
* Copyright 2019-2022 Mamoe Technologies and contributors.
|
||||
*
|
||||
* 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
|
||||
* Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
|
||||
* 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
|
||||
* Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
|
||||
*
|
||||
* https://github.com/mamoe/mirai/blob/master/LICENSE
|
||||
* https://github.com/mamoe/mirai/blob/dev/LICENSE
|
||||
*/
|
||||
|
||||
@file:Suppress("WRONG_MODIFIER_CONTAINING_DECLARATION", "unused")
|
||||
@ -14,6 +14,7 @@ package net.mamoe.mirai.console
|
||||
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Job
|
||||
import me.him188.kotlin.dynamic.delegation.dynamicDelegation
|
||||
import net.mamoe.mirai.Bot
|
||||
import net.mamoe.mirai.BotFactory
|
||||
import net.mamoe.mirai.console.MiraiConsole.INSTANCE
|
||||
@ -124,6 +125,7 @@ public interface MiraiConsole : CoroutineScope {
|
||||
|
||||
@ConsoleExperimentalApi
|
||||
public val pluginCenter: PluginCenter
|
||||
get() = throw UnsupportedOperationException("PluginCenter is not supported yet")
|
||||
|
||||
/**
|
||||
* 创建一个 logger
|
||||
@ -147,7 +149,7 @@ public interface MiraiConsole : CoroutineScope {
|
||||
*
|
||||
* 对象以 [bridge][MiraiConsoleImplementationBridge] 实现, 将会桥接特定前端实现的 [MiraiConsoleImplementation] 到 [MiraiConsole].
|
||||
*/
|
||||
public companion object INSTANCE : MiraiConsole by MiraiConsoleImplementationBridge {
|
||||
public companion object INSTANCE : MiraiConsole by dynamicDelegation({ MiraiConsoleImplementation.getBridge() }) {
|
||||
/**
|
||||
* 获取 [MiraiConsole] 的 [Job]
|
||||
*/ // MiraiConsole.INSTANCE.getJob()
|
||||
@ -219,7 +221,7 @@ public interface MiraiConsole : CoroutineScope {
|
||||
parentCoroutineContext = MiraiConsole.childScopeContext("Bot $id")
|
||||
autoReconnectOnForceOffline()
|
||||
|
||||
this.loginSolver = MiraiConsoleImplementationBridge.createLoginSolver(id, this)
|
||||
this.loginSolver = MiraiConsoleImplementation.getInstance().createLoginSolver(id, this)
|
||||
configuration()
|
||||
}
|
||||
|
||||
|
@ -1,10 +1,10 @@
|
||||
/*
|
||||
* Copyright 2019-2021 Mamoe Technologies and contributors.
|
||||
* Copyright 2019-2022 Mamoe Technologies and contributors.
|
||||
*
|
||||
* 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
|
||||
* Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
|
||||
* 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
|
||||
* Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
|
||||
*
|
||||
* https://github.com/mamoe/mirai/blob/master/LICENSE
|
||||
* https://github.com/mamoe/mirai/blob/dev/LICENSE
|
||||
*/
|
||||
|
||||
@file:Suppress("unused")
|
||||
@ -67,6 +67,16 @@ public annotation class ConsoleFrontEndImplementation
|
||||
*/
|
||||
@ConsoleFrontEndImplementation
|
||||
public interface MiraiConsoleImplementation : CoroutineScope {
|
||||
/**
|
||||
* 获取原始 [MiraiConsoleImplementation] 实例.
|
||||
*
|
||||
* [MiraiConsoleImplementation.start] 实际上会创建 [MiraiConsoleImplementationBridge] 并启动该 bridge, 不会直接使用提供的 [MiraiConsoleImplementation] 实例.
|
||||
* [MiraiConsoleImplementation.getInstance] 获取到的将会是 bridge. 可通过 `bridge.origin` 获取原始在 [start] 传递的实例.
|
||||
*
|
||||
* @since 2.11.0-RC
|
||||
*/
|
||||
public val origin: MiraiConsoleImplementation get() = this
|
||||
|
||||
/**
|
||||
* [MiraiConsole] 的 [CoroutineScope.coroutineContext], 必须拥有如下元素
|
||||
*
|
||||
@ -366,39 +376,43 @@ public interface MiraiConsoleImplementation : CoroutineScope {
|
||||
}
|
||||
|
||||
@Volatile
|
||||
internal var instance: MiraiConsoleImplementation? = null
|
||||
internal val instanceInitialized: Boolean get() = instance != null
|
||||
|
||||
@JvmSynthetic
|
||||
internal var options: ConsoleLaunchOptions = ConsoleLaunchOptions()
|
||||
internal var currentBridge: MiraiConsoleImplementationBridge? = null
|
||||
internal val instanceInitialized: Boolean get() = currentBridge != null
|
||||
|
||||
private val initLock = ReentrantLock()
|
||||
|
||||
/**
|
||||
* 可由前端调用, 获取当前的 [MiraiConsoleImplementation] 实例
|
||||
* 可由前端调用, 获取当前的 [MiraiConsoleImplementation] 实例. 注意该实例不是 [start] 时传递的实例, 而会是 [MiraiConsoleImplementationBridge].
|
||||
*
|
||||
* 必须在 [start] 之后才能使用, 否则抛出 [UninitializedPropertyAccessException]
|
||||
* 必须在 [start] 之后才能使用, 否则抛出 [UninitializedPropertyAccessException].
|
||||
*/
|
||||
@JvmStatic
|
||||
@ConsoleFrontEndImplementation
|
||||
public fun getInstance(): MiraiConsoleImplementation = instance ?: throw UninitializedPropertyAccessException()
|
||||
public fun getInstance(): MiraiConsoleImplementation =
|
||||
currentBridge ?: throw UninitializedPropertyAccessException()
|
||||
|
||||
/**
|
||||
* @since 2.11
|
||||
*/
|
||||
internal fun getBridge(): MiraiConsoleImplementationBridge =
|
||||
currentBridge ?: throw UninitializedPropertyAccessException()
|
||||
|
||||
/** 由前端调用, 初始化 [MiraiConsole] 实例并启动 */
|
||||
@JvmStatic
|
||||
@ConsoleFrontEndImplementation
|
||||
@Throws(MalformedMiraiConsoleImplementationError::class)
|
||||
public fun MiraiConsoleImplementation.start(): Unit = initLock.withLock {
|
||||
val instance = instance
|
||||
if (instance != null && instance.isActive) {
|
||||
val currentBridge = currentBridge
|
||||
if (currentBridge != null && currentBridge.isActive) {
|
||||
error(
|
||||
"Mirai Console is already initialized and is currently running. " +
|
||||
"Run MiraiConsole.cancel to kill old instance before starting another instance."
|
||||
)
|
||||
}
|
||||
options = this.consoleLaunchOptions
|
||||
this@Companion.instance = this
|
||||
val newBridge = MiraiConsoleImplementationBridge(this)
|
||||
this@Companion.currentBridge = newBridge
|
||||
kotlin.runCatching {
|
||||
MiraiConsoleImplementationBridge.doStart()
|
||||
newBridge.doStart()
|
||||
}.onFailure { e ->
|
||||
kotlin.runCatching {
|
||||
MiraiConsole.mainLogger.error("Failed to init MiraiConsole.", e)
|
||||
|
@ -14,6 +14,7 @@ import kotlinx.coroutines.sync.Mutex
|
||||
import kotlinx.coroutines.sync.withLock
|
||||
import net.mamoe.mirai.Bot
|
||||
import net.mamoe.mirai.console.MiraiConsole
|
||||
import net.mamoe.mirai.console.MiraiConsoleImplementation
|
||||
import net.mamoe.mirai.console.command.CommandManager.INSTANCE.allRegisteredCommands
|
||||
import net.mamoe.mirai.console.command.CommandManager.INSTANCE.register
|
||||
import net.mamoe.mirai.console.command.descriptor.CommandArgumentParserException
|
||||
@ -23,7 +24,6 @@ import net.mamoe.mirai.console.command.descriptor.PermitteeIdValueArgumentParser
|
||||
import net.mamoe.mirai.console.command.descriptor.buildCommandArgumentContext
|
||||
import net.mamoe.mirai.console.extensions.PermissionServiceProvider
|
||||
import net.mamoe.mirai.console.internal.MiraiConsoleBuildConstants
|
||||
import net.mamoe.mirai.console.internal.MiraiConsoleImplementationBridge
|
||||
import net.mamoe.mirai.console.internal.data.builtins.AutoLoginConfig
|
||||
import net.mamoe.mirai.console.internal.data.builtins.AutoLoginConfig.Account.*
|
||||
import net.mamoe.mirai.console.internal.data.builtins.AutoLoginConfig.Account.PasswordKind.MD5
|
||||
@ -478,7 +478,7 @@ public object BuiltInCommands {
|
||||
gold().append(MiraiConsoleBuildConstants.versionConst)
|
||||
reset().append(", built on ")
|
||||
lightBlue().append(buildDateFormatted).reset().append(".\n")
|
||||
append(MiraiConsoleImplementationBridge.frontEndDescription.render()).append("\n\n")
|
||||
append(MiraiConsoleImplementation.getInstance().frontEndDescription.render()).append("\n\n")
|
||||
append("Permission Service: ").append(
|
||||
if (PermissionService.INSTANCE is BuiltInPermissionService) {
|
||||
lightYellow()
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2019-2021 Mamoe Technologies and contributors.
|
||||
* Copyright 2019-2022 Mamoe Technologies and contributors.
|
||||
*
|
||||
* 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
|
||||
* Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
|
||||
@ -24,7 +24,6 @@ import net.mamoe.mirai.console.command.parse.CommandCall
|
||||
import net.mamoe.mirai.console.command.parse.CommandCallParser
|
||||
import net.mamoe.mirai.console.command.resolve.CommandCallResolver
|
||||
import net.mamoe.mirai.console.command.resolve.ResolvedCommandCall
|
||||
import net.mamoe.mirai.console.internal.MiraiConsoleImplementationBridge
|
||||
import net.mamoe.mirai.console.internal.command.executeCommandImpl
|
||||
import net.mamoe.mirai.console.util.ConsoleExperimentalApi
|
||||
import net.mamoe.mirai.message.data.*
|
||||
@ -175,7 +174,7 @@ public interface CommandManager {
|
||||
* [CommandManager] 实例. 转发所有调用到 [MiraiConsoleImplementation.commandManager].
|
||||
*/
|
||||
public companion object INSTANCE :
|
||||
CommandManager by (dynamicDelegation { MiraiConsoleImplementationBridge.commandManager }) {
|
||||
CommandManager by (dynamicDelegation { MiraiConsoleImplementation.getInstance().commandManager }) {
|
||||
|
||||
/**
|
||||
* @see CommandManager.getRegisteredCommands
|
||||
|
@ -1,10 +1,10 @@
|
||||
/*
|
||||
* Copyright 2019-2021 Mamoe Technologies and contributors.
|
||||
* Copyright 2019-2022 Mamoe Technologies and contributors.
|
||||
*
|
||||
* 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
|
||||
* Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
|
||||
* 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
|
||||
* Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
|
||||
*
|
||||
* https://github.com/mamoe/mirai/blob/master/LICENSE
|
||||
* https://github.com/mamoe/mirai/blob/dev/LICENSE
|
||||
*/
|
||||
|
||||
@file:Suppress(
|
||||
@ -18,11 +18,11 @@ import kotlinx.coroutines.CoroutineScope
|
||||
import me.him188.kotlin.jvm.blocking.bridge.JvmBlockingBridge
|
||||
import net.mamoe.mirai.Bot
|
||||
import net.mamoe.mirai.console.MiraiConsole
|
||||
import net.mamoe.mirai.console.MiraiConsoleImplementation
|
||||
import net.mamoe.mirai.console.command.CommandSender.Companion.asCommandSender
|
||||
import net.mamoe.mirai.console.command.CommandSender.Companion.asMemberCommandSender
|
||||
import net.mamoe.mirai.console.command.CommandSender.Companion.asTempCommandSender
|
||||
import net.mamoe.mirai.console.command.CommandSender.Companion.toCommandSender
|
||||
import net.mamoe.mirai.console.internal.MiraiConsoleImplementationBridge
|
||||
import net.mamoe.mirai.console.internal.data.castOrNull
|
||||
import net.mamoe.mirai.console.internal.data.qualifiedNameOrTip
|
||||
import net.mamoe.mirai.console.permission.AbstractPermitteeId
|
||||
@ -35,9 +35,9 @@ import net.mamoe.mirai.event.events.*
|
||||
import net.mamoe.mirai.message.MessageReceipt
|
||||
import net.mamoe.mirai.message.data.Message
|
||||
import net.mamoe.mirai.message.data.PlainText
|
||||
import net.mamoe.mirai.utils.DeprecatedSinceMirai
|
||||
import net.mamoe.mirai.utils.childScope
|
||||
import net.mamoe.mirai.utils.childScopeContext
|
||||
import net.mamoe.mirai.utils.DeprecatedSinceMirai
|
||||
import kotlin.contracts.InvocationKind
|
||||
import kotlin.contracts.contract
|
||||
import kotlin.coroutines.CoroutineContext
|
||||
@ -462,13 +462,13 @@ public object ConsoleCommandSender : AbstractCommandSender() {
|
||||
|
||||
@JvmBlockingBridge
|
||||
public override suspend fun sendMessage(message: Message): Nothing? {
|
||||
MiraiConsoleImplementationBridge.consoleCommandSender.sendMessage(message)
|
||||
MiraiConsoleImplementation.getInstance().consoleCommandSender.sendMessage(message)
|
||||
return null
|
||||
}
|
||||
|
||||
@JvmBlockingBridge
|
||||
public override suspend fun sendMessage(message: String): Nothing? {
|
||||
MiraiConsoleImplementationBridge.consoleCommandSender.sendMessage(message)
|
||||
MiraiConsoleImplementation.getInstance().consoleCommandSender.sendMessage(message)
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
@ -1,10 +1,10 @@
|
||||
/*
|
||||
* Copyright 2019-2021 Mamoe Technologies and contributors.
|
||||
* Copyright 2019-2022 Mamoe Technologies and contributors.
|
||||
*
|
||||
* 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
|
||||
* Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
|
||||
* 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
|
||||
* Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
|
||||
*
|
||||
* https://github.com/mamoe/mirai/blob/master/LICENSE
|
||||
* https://github.com/mamoe/mirai/blob/dev/LICENSE
|
||||
*/
|
||||
|
||||
@file:OptIn(ConsoleExperimentalApi::class)
|
||||
@ -12,7 +12,6 @@
|
||||
package net.mamoe.mirai.console.internal
|
||||
|
||||
import kotlinx.coroutines.CoroutineExceptionHandler
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Job
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import me.him188.kotlin.dynamic.delegation.dynamicDelegation
|
||||
@ -32,8 +31,8 @@ import net.mamoe.mirai.console.internal.data.builtins.AutoLoginConfig.Account.Co
|
||||
import net.mamoe.mirai.console.internal.data.builtins.AutoLoginConfig.Account.PasswordKind.MD5
|
||||
import net.mamoe.mirai.console.internal.data.builtins.AutoLoginConfig.Account.PasswordKind.PLAIN
|
||||
import net.mamoe.mirai.console.internal.data.builtins.LoggerConfig
|
||||
import net.mamoe.mirai.console.internal.extension.SingletonExtensionSelectorImpl
|
||||
import net.mamoe.mirai.console.internal.extension.GlobalComponentStorage
|
||||
import net.mamoe.mirai.console.internal.extension.SingletonExtensionSelectorImpl
|
||||
import net.mamoe.mirai.console.internal.logging.LoggerControllerImpl
|
||||
import net.mamoe.mirai.console.internal.logging.MiraiConsoleLogger
|
||||
import net.mamoe.mirai.console.internal.permission.BuiltInPermissionService
|
||||
@ -44,7 +43,6 @@ import net.mamoe.mirai.console.permission.PermissionService
|
||||
import net.mamoe.mirai.console.permission.PermissionService.Companion.permit
|
||||
import net.mamoe.mirai.console.permission.RootPermission
|
||||
import net.mamoe.mirai.console.plugin.PluginManager
|
||||
import net.mamoe.mirai.console.plugin.center.PluginCenter
|
||||
import net.mamoe.mirai.console.plugin.name
|
||||
import net.mamoe.mirai.console.util.ConsoleExperimentalApi
|
||||
import net.mamoe.mirai.console.util.ConsoleInput
|
||||
@ -65,12 +63,12 @@ internal val MiraiConsole.pluginManagerImpl: PluginManagerImpl get() = this.plug
|
||||
* [MiraiConsole] 公开 API 与前端实现的连接桥.
|
||||
*/
|
||||
@Suppress("SpellCheckingInspection")
|
||||
internal object MiraiConsoleImplementationBridge : CoroutineScope,
|
||||
MiraiConsoleImplementation by (dynamicDelegation { MiraiConsoleImplementation.getInstance() }),
|
||||
MiraiConsole {
|
||||
override val pluginCenter: PluginCenter get() = throw UnsupportedOperationException("PluginCenter is not supported yet")
|
||||
|
||||
private val instance: MiraiConsoleImplementation get() = MiraiConsoleImplementation.getInstance()
|
||||
internal class MiraiConsoleImplementationBridge(
|
||||
private val externalImplementation: MiraiConsoleImplementation,
|
||||
) : MiraiConsole,
|
||||
MiraiConsoleImplementation by (dynamicDelegation(MiraiConsoleImplementationBridge::externalImplementation)) {
|
||||
override val origin: MiraiConsoleImplementation
|
||||
get() = externalImplementation
|
||||
|
||||
// FIXME: 12/12/2021 Workaround for compiler regression, should remove when using Kotlin compiller 1.6.20
|
||||
private operator fun <V> KProperty0<V>.getValue(thisRef: Any?, property: KProperty<*>): V = this.get()
|
||||
@ -81,8 +79,6 @@ internal object MiraiConsoleImplementationBridge : CoroutineScope,
|
||||
|
||||
override val mainLogger: MiraiLogger by lazy { createLogger("main") }
|
||||
|
||||
override val consoleLaunchOptions: MiraiConsoleImplementation.ConsoleLaunchOptions get() = MiraiConsoleImplementation.options
|
||||
|
||||
init {
|
||||
// TODO: Replace to standard api
|
||||
@Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
|
||||
@ -96,12 +92,12 @@ internal object MiraiConsoleImplementationBridge : CoroutineScope,
|
||||
|
||||
override fun createLogger(identity: String?): MiraiLogger {
|
||||
val controller = loggerController
|
||||
return MiraiConsoleLogger(controller, instance.createLogger(identity))
|
||||
return MiraiConsoleLogger(controller, externalImplementation.createLogger(identity))
|
||||
}
|
||||
|
||||
@Suppress("RemoveRedundantBackticks")
|
||||
internal fun doStart() {
|
||||
instance.preStart()
|
||||
externalImplementation.preStart()
|
||||
|
||||
phase("setup logger controller") {
|
||||
if (loggerController === LoggerControllerImpl) {
|
||||
@ -267,7 +263,7 @@ internal object MiraiConsoleImplementationBridge : CoroutineScope,
|
||||
}
|
||||
}
|
||||
|
||||
instance.postStart()
|
||||
externalImplementation.postStart()
|
||||
|
||||
mainLogger.info { "mirai-console started successfully." }
|
||||
}
|
||||
@ -291,10 +287,10 @@ internal object MiraiConsoleImplementationBridge : CoroutineScope,
|
||||
}
|
||||
|
||||
override fun prePhase(phase: String) {
|
||||
instance.prePhase(phase)
|
||||
externalImplementation.prePhase(phase)
|
||||
}
|
||||
|
||||
override fun postPhase(phase: String) {
|
||||
instance.postPhase(phase)
|
||||
externalImplementation.postPhase(phase)
|
||||
}
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2019-2021 Mamoe Technologies and contributors.
|
||||
* Copyright 2019-2022 Mamoe Technologies and contributors.
|
||||
*
|
||||
* 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
|
||||
* Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
|
||||
@ -13,8 +13,8 @@ import kotlinx.coroutines.CoroutineExceptionHandler
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.ensureActive
|
||||
import net.mamoe.mirai.console.MiraiConsole
|
||||
import net.mamoe.mirai.console.MiraiConsoleImplementation
|
||||
import net.mamoe.mirai.console.data.PluginDataStorage
|
||||
import net.mamoe.mirai.console.internal.MiraiConsoleImplementationBridge
|
||||
import net.mamoe.mirai.console.internal.util.PluginServiceHelper.findServices
|
||||
import net.mamoe.mirai.console.internal.util.PluginServiceHelper.loadAllServices
|
||||
import net.mamoe.mirai.console.plugin.PluginManager
|
||||
@ -46,10 +46,10 @@ internal class BuiltInJvmPluginLoaderImpl(
|
||||
}
|
||||
|
||||
override val configStorage: PluginDataStorage
|
||||
get() = MiraiConsoleImplementationBridge.configStorageForJvmPluginLoader
|
||||
get() = MiraiConsoleImplementation.getInstance().configStorageForJvmPluginLoader
|
||||
|
||||
override val dataStorage: PluginDataStorage
|
||||
get() = MiraiConsoleImplementationBridge.dataStorageForJvmPluginLoader
|
||||
get() = MiraiConsoleImplementation.getInstance().dataStorageForJvmPluginLoader
|
||||
|
||||
override val classLoaders: MutableList<JvmPluginClassLoader> = mutableListOf()
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2019-2021 Mamoe Technologies and contributors.
|
||||
* Copyright 2019-2022 Mamoe Technologies and contributors.
|
||||
*
|
||||
* 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
|
||||
* Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
|
||||
@ -94,7 +94,7 @@ internal abstract class JvmPluginInternal(
|
||||
},
|
||||
onFailure = {
|
||||
cancel(CancellationException("Exception while disabling plugin", it))
|
||||
if (MiraiConsoleImplementation.options.crashWhenPluginLoadFailed) {
|
||||
if (MiraiConsoleImplementation.getInstance().consoleLaunchOptions.crashWhenPluginLoadFailed) {
|
||||
throw it
|
||||
}
|
||||
}
|
||||
@ -123,7 +123,7 @@ internal abstract class JvmPluginInternal(
|
||||
onFailure = {
|
||||
cancel(CancellationException("Exception while enabling plugin", it))
|
||||
logger.error(it)
|
||||
if (MiraiConsoleImplementation.options.crashWhenPluginLoadFailed) {
|
||||
if (MiraiConsoleImplementation.getInstance().consoleLaunchOptions.crashWhenPluginLoadFailed) {
|
||||
throw it
|
||||
}
|
||||
return false
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2019-2021 Mamoe Technologies and contributors.
|
||||
* Copyright 2019-2022 Mamoe Technologies and contributors.
|
||||
*
|
||||
* 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
|
||||
* Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
|
||||
@ -11,7 +11,7 @@ package net.mamoe.mirai.console.internal.util
|
||||
|
||||
import kotlinx.coroutines.sync.Mutex
|
||||
import kotlinx.coroutines.sync.withLock
|
||||
import net.mamoe.mirai.console.internal.MiraiConsoleImplementationBridge
|
||||
import net.mamoe.mirai.console.MiraiConsoleImplementation
|
||||
import net.mamoe.mirai.console.util.ConsoleInput
|
||||
|
||||
@Suppress("unused")
|
||||
@ -19,5 +19,5 @@ internal object ConsoleInputImpl : ConsoleInput {
|
||||
private val inputLock = Mutex()
|
||||
|
||||
override suspend fun requestInput(hint: String): String =
|
||||
inputLock.withLock { MiraiConsoleImplementationBridge.consoleInput.requestInput(hint) }
|
||||
inputLock.withLock { MiraiConsoleImplementation.getInstance().consoleInput.requestInput(hint) }
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2019-2021 Mamoe Technologies and contributors.
|
||||
* Copyright 2019-2022 Mamoe Technologies and contributors.
|
||||
*
|
||||
* 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
|
||||
* Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
|
||||
@ -139,7 +139,7 @@ public interface PluginManager {
|
||||
/**
|
||||
* [PluginManager] 实例. 转发所有调用到 [MiraiConsole.pluginManager].
|
||||
*/
|
||||
public companion object INSTANCE : PluginManager by (dynamicDelegation(MiraiConsole::pluginManager)) {
|
||||
public companion object INSTANCE : PluginManager by (dynamicDelegation { MiraiConsole.pluginManager }) {
|
||||
/**
|
||||
* 经过泛型类型转换的 [Plugin.loader]
|
||||
*/
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2019-2021 Mamoe Technologies and contributors.
|
||||
* Copyright 2019-2022 Mamoe Technologies and contributors.
|
||||
*
|
||||
* 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
|
||||
* Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
|
||||
@ -11,8 +11,8 @@ package net.mamoe.mirai.console.plugin.jvm
|
||||
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import me.him188.kotlin.dynamic.delegation.dynamicDelegation
|
||||
import net.mamoe.mirai.console.MiraiConsoleImplementation
|
||||
import net.mamoe.mirai.console.data.PluginDataStorage
|
||||
import net.mamoe.mirai.console.internal.MiraiConsoleImplementationBridge
|
||||
import net.mamoe.mirai.console.internal.plugin.BuiltInJvmPluginLoaderImpl
|
||||
import net.mamoe.mirai.console.plugin.loader.FilePluginLoader
|
||||
import net.mamoe.mirai.utils.MiraiInternalApi
|
||||
@ -45,7 +45,7 @@ public interface JvmPluginLoader : CoroutineScope, FilePluginLoader<JvmPlugin, J
|
||||
public val classLoaders: List<ClassLoader>
|
||||
|
||||
public companion object BuiltIn :
|
||||
JvmPluginLoader by (dynamicDelegation { MiraiConsoleImplementationBridge.jvmPluginLoader }) {
|
||||
JvmPluginLoader by (dynamicDelegation { MiraiConsoleImplementation.getInstance().jvmPluginLoader }) {
|
||||
|
||||
@Suppress("EXTENSION_SHADOWED_BY_MEMBER")
|
||||
override fun getPluginDescription(plugin: JvmPlugin): JvmPluginDescription =
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2019-2021 Mamoe Technologies and contributors.
|
||||
* Copyright 2019-2022 Mamoe Technologies and contributors.
|
||||
*
|
||||
* 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
|
||||
* Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
|
||||
@ -10,9 +10,9 @@
|
||||
|
||||
package net.mamoe.mirai.console.util
|
||||
|
||||
import net.mamoe.mirai.console.MiraiConsoleImplementation
|
||||
import net.mamoe.mirai.console.command.CommandSender
|
||||
import net.mamoe.mirai.console.command.ConsoleCommandSender
|
||||
import net.mamoe.mirai.console.internal.MiraiConsoleImplementationBridge
|
||||
import net.mamoe.mirai.console.util.AnsiMessageBuilder.Companion.asAnsiMessageBuilder
|
||||
import net.mamoe.mirai.console.util.AnsiMessageBuilder.Companion.dropAnsi
|
||||
import net.mamoe.mirai.contact.Contact
|
||||
@ -102,7 +102,7 @@ public open class AnsiMessageBuilder public constructor(
|
||||
@JvmStatic
|
||||
public fun isAnsiSupported(sender: CommandSender): Boolean =
|
||||
if (sender is ConsoleCommandSender) {
|
||||
MiraiConsoleImplementationBridge.isAnsiSupported
|
||||
MiraiConsoleImplementation.getInstance().isAnsiSupported
|
||||
} else false
|
||||
|
||||
/**
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2019-2021 Mamoe Technologies and contributors.
|
||||
* Copyright 2019-2022 Mamoe Technologies and contributors.
|
||||
*
|
||||
* 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
|
||||
* Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
|
||||
@ -12,6 +12,7 @@
|
||||
package net.mamoe.mirai.console.command
|
||||
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import net.mamoe.mirai.console.MiraiConsoleImplementation
|
||||
import net.mamoe.mirai.console.Testing
|
||||
import net.mamoe.mirai.console.Testing.withTesting
|
||||
import net.mamoe.mirai.console.command.CommandManager.INSTANCE.getRegisteredCommands
|
||||
@ -22,7 +23,6 @@ import net.mamoe.mirai.console.command.CommandManager.INSTANCE.unregisterCommand
|
||||
import net.mamoe.mirai.console.command.descriptor.CommandValueArgumentParser
|
||||
import net.mamoe.mirai.console.command.descriptor.ExperimentalCommandDescriptors
|
||||
import net.mamoe.mirai.console.command.descriptor.buildCommandArgumentContext
|
||||
import net.mamoe.mirai.console.internal.MiraiConsoleImplementationBridge
|
||||
import net.mamoe.mirai.console.internal.command.CommandManagerImpl
|
||||
import net.mamoe.mirai.console.internal.command.flattenCommandComponents
|
||||
import net.mamoe.mirai.console.testFramework.AbstractConsoleInstanceTest
|
||||
@ -161,7 +161,7 @@ internal val owner by lazy { TestUnitCommandOwner }
|
||||
|
||||
@OptIn(ExperimentalCommandDescriptors::class)
|
||||
internal class InstanceTestCommand : AbstractConsoleInstanceTest() {
|
||||
private val manager by lazy { MiraiConsoleImplementationBridge.commandManager as CommandManagerImpl }
|
||||
private val manager by lazy { MiraiConsoleImplementation.getBridge().commandManager as CommandManagerImpl }
|
||||
|
||||
@Test
|
||||
fun testRegister() {
|
||||
|
@ -42,7 +42,7 @@ abstract class AbstractConsoleInstanceTest {
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
} finally {
|
||||
MiraiConsoleImplementation.instance = null
|
||||
MiraiConsoleImplementation.currentBridge = null
|
||||
}
|
||||
}
|
||||
println("=========".repeat(4) + "CONSOLE STOPPED" + "=========".repeat(4))
|
||||
|
Loading…
Reference in New Issue
Block a user