From 39f0eeb5080819e6873a2cc01c254023495a85f0 Mon Sep 17 00:00:00 2001 From: Him188 Date: Sat, 10 Apr 2021 16:09:03 +0800 Subject: [PATCH] Allow overriding MiraiConsole impl when stopped --- backend/mirai-console/src/MiraiConsoleImplementation.kt | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/backend/mirai-console/src/MiraiConsoleImplementation.kt b/backend/mirai-console/src/MiraiConsoleImplementation.kt index 34b3fb3b0..128ccfba9 100644 --- a/backend/mirai-console/src/MiraiConsoleImplementation.kt +++ b/backend/mirai-console/src/MiraiConsoleImplementation.kt @@ -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()