Reload BuiltInSingletonExtensionSelector on startup

This commit is contained in:
Him188 2020-09-10 20:03:57 +08:00
parent cea884c3d7
commit d7fe94acbd
2 changed files with 11 additions and 5 deletions

View File

@ -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.command.CommandManagerImpl
import net.mamoe.mirai.console.internal.data.builtins.AutoLoginConfig import net.mamoe.mirai.console.internal.data.builtins.AutoLoginConfig
import net.mamoe.mirai.console.internal.data.builtins.ConsoleDataScope 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.plugin.PluginManagerImpl
import net.mamoe.mirai.console.internal.util.autoHexToBytes import net.mamoe.mirai.console.internal.util.autoHexToBytes
import net.mamoe.mirai.console.permission.BuiltInPermissionService import net.mamoe.mirai.console.permission.BuiltInPermissionService
@ -125,7 +126,7 @@ internal object MiraiConsoleImplementationBridge : CoroutineScope, MiraiConsoleI
val pluginLoadSession: PluginManagerImpl.PluginLoadSession val pluginLoadSession: PluginManagerImpl.PluginLoadSession
phase `load plugins`@{ phase `load plugin provider plugins and high priority extension plugins`@{
PluginManager // init PluginManager // init
mainLogger.verbose { "Loading PluginLoader provider plugins..." } mainLogger.verbose { "Loading PluginLoader provider plugins..." }
@ -141,7 +142,12 @@ internal object MiraiConsoleImplementationBridge : CoroutineScope, MiraiConsoleI
mainLogger.verbose { "${PluginManager.plugins.size} such plugin(s) loaded." } 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`@{ phase `load PermissionService`@{
mainLogger.verbose { "Loading PermissionService..." } mainLogger.verbose { "Loading PermissionService..." }

View File

@ -2,7 +2,7 @@ package net.mamoe.mirai.console.internal.extensions
import kotlinx.coroutines.runBlocking import kotlinx.coroutines.runBlocking
import net.mamoe.mirai.console.MiraiConsole 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.data.value
import net.mamoe.mirai.console.extension.Extension import net.mamoe.mirai.console.extension.Extension
import net.mamoe.mirai.console.extension.ExtensionRegistry import net.mamoe.mirai.console.extension.ExtensionRegistry
@ -15,9 +15,9 @@ import kotlin.reflect.KClass
internal object BuiltInSingletonExtensionSelector : SingletonExtensionSelector { 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" override val saveName: String get() = "ExtensionSelector"
val value: MutableMap<String, String> by value() val value: MutableMap<String, String> by value()