Allow overriding MiraiConsole impl when stopped

This commit is contained in:
Him188 2021-04-10 16:09:03 +08:00
parent c3fbff1807
commit 39f0eeb508

View File

@ -265,7 +265,12 @@ public interface MiraiConsoleImplementation : CoroutineScope {
@ConsoleFrontEndImplementation
@Throws(MalformedMiraiConsoleImplementationError::class)
public fun MiraiConsoleImplementation.start(): Unit = initLock.withLock {
if (::instance.isInitialized) error("Mirai Console is already initialized.")
if (::instance.isInitialized && instance.isActive) {
error(
"Mirai Console is already initialized and is currently running. " +
"Run MiraiConsole.cancel to kill old instance before starting another instance."
)
}
this@Companion.instance = this
kotlin.runCatching {
MiraiConsoleImplementationBridge.doStart()