From d7fe94acbda45f426b1866ebe32fda576973f715 Mon Sep 17 00:00:00 2001 From: Him188 Date: Thu, 10 Sep 2020 20:03:57 +0800 Subject: [PATCH] Reload BuiltInSingletonExtensionSelector on startup --- .../internal/MiraiConsoleImplementationBridge.kt | 10 ++++++++-- .../extensions/BuiltInSingletonExtensionSelector.kt | 6 +++--- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/MiraiConsoleImplementationBridge.kt b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/MiraiConsoleImplementationBridge.kt index f33678d94..9649308c2 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/MiraiConsoleImplementationBridge.kt +++ b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/MiraiConsoleImplementationBridge.kt @@ -33,6 +33,7 @@ import net.mamoe.mirai.console.extensions.SingletonExtensionSelector import net.mamoe.mirai.console.internal.command.CommandManagerImpl import net.mamoe.mirai.console.internal.data.builtins.AutoLoginConfig import net.mamoe.mirai.console.internal.data.builtins.ConsoleDataScope +import net.mamoe.mirai.console.internal.extensions.BuiltInSingletonExtensionSelector import net.mamoe.mirai.console.internal.plugin.PluginManagerImpl import net.mamoe.mirai.console.internal.util.autoHexToBytes import net.mamoe.mirai.console.permission.BuiltInPermissionService @@ -125,7 +126,7 @@ internal object MiraiConsoleImplementationBridge : CoroutineScope, MiraiConsoleI val pluginLoadSession: PluginManagerImpl.PluginLoadSession - phase `load plugins`@{ + phase `load plugin provider plugins and high priority extension plugins`@{ PluginManager // init mainLogger.verbose { "Loading PluginLoader provider plugins..." } @@ -141,7 +142,12 @@ internal object MiraiConsoleImplementationBridge : CoroutineScope, MiraiConsoleI mainLogger.verbose { "${PluginManager.plugins.size} such plugin(s) loaded." } } - SingletonExtensionSelector.instance // init + phase `load SingletonExtensionSelector`@{ + val instance = SingletonExtensionSelector.instance + if (instance is BuiltInSingletonExtensionSelector) { + ConsoleDataScope.addAndReloadConfig(instance.config) + } + } phase `load PermissionService`@{ mainLogger.verbose { "Loading PermissionService..." } diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/extensions/BuiltInSingletonExtensionSelector.kt b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/extensions/BuiltInSingletonExtensionSelector.kt index 5d84aabdf..8621e0c01 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/extensions/BuiltInSingletonExtensionSelector.kt +++ b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/extensions/BuiltInSingletonExtensionSelector.kt @@ -2,7 +2,7 @@ package net.mamoe.mirai.console.internal.extensions import kotlinx.coroutines.runBlocking import net.mamoe.mirai.console.MiraiConsole -import net.mamoe.mirai.console.data.AutoSavePluginData +import net.mamoe.mirai.console.data.AutoSavePluginConfig import net.mamoe.mirai.console.data.value import net.mamoe.mirai.console.extension.Extension import net.mamoe.mirai.console.extension.ExtensionRegistry @@ -15,9 +15,9 @@ import kotlin.reflect.KClass internal object BuiltInSingletonExtensionSelector : SingletonExtensionSelector { - private val config: SaveData = SaveData() + internal val config: SaveData = SaveData() - private class SaveData : AutoSavePluginData() { + internal class SaveData : AutoSavePluginConfig() { override val saveName: String get() = "ExtensionSelector" val value: MutableMap by value()