mirror of
https://github.com/mamoe/mirai.git
synced 2025-01-25 15:40:28 +08:00
Ensure that the PermissionService is loaded correctly (#307)
* Ensure that the PermissionService is loaded correctly * Update backend/mirai-console/src/extensions/PermissionServiceProvider.kt * Mark `@ConsoleExperimentalApi` Co-authored-by: Him188 <Him188@mamoe.net>
This commit is contained in:
parent
5dc1c90ac4
commit
3ae575e9eb
@ -74,7 +74,7 @@ public abstract class AbstractSingletonExtensionPoint<E : SingletonExtension<T>,
|
||||
* 由 [SingletonExtensionSelector] 选择后的实例.
|
||||
*/
|
||||
@ConsoleExperimentalApi
|
||||
public val selectedInstance: T by lazy {
|
||||
public open val selectedInstance: T by lazy {
|
||||
GlobalComponentStorage.run { this@AbstractSingletonExtensionPoint.findSingletonInstance(extensionType, builtinImplementation) }
|
||||
}
|
||||
}
|
@ -25,6 +25,8 @@ import net.mamoe.mirai.console.util.ConsoleExperimentalApi
|
||||
public interface PermissionServiceProvider : SingletonExtension<PermissionService<*>> {
|
||||
public companion object ExtensionPoint :
|
||||
AbstractSingletonExtensionPoint<PermissionServiceProvider, PermissionService<*>>(PermissionServiceProvider::class, BuiltInPermissionService) {
|
||||
internal var permissionServiceOk = false
|
||||
|
||||
@ConsoleExperimentalApi
|
||||
public val providerPlugin: Plugin? by lazy {
|
||||
GlobalComponentStorage.run {
|
||||
@ -33,6 +35,15 @@ public interface PermissionServiceProvider : SingletonExtension<PermissionServic
|
||||
PermissionServiceProvider.getExtensions().find { it.extension.instance === instance }?.plugin
|
||||
}
|
||||
}
|
||||
|
||||
@ConsoleExperimentalApi
|
||||
override val selectedInstance: PermissionService<*>
|
||||
get() {
|
||||
if (!permissionServiceOk) {
|
||||
error("PermissionService not yet loaded")
|
||||
}
|
||||
return super.selectedInstance
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -46,4 +57,4 @@ public class PermissionServiceProviderImpl(override val instance: PermissionServ
|
||||
*/
|
||||
public class PermissionServiceProviderImplLazy(initializer: () -> PermissionService<*>) : PermissionServiceProvider {
|
||||
override val instance: PermissionService<*> by lazy(initializer)
|
||||
}
|
||||
}
|
||||
|
@ -180,6 +180,7 @@ internal object MiraiConsoleImplementationBridge : CoroutineScope, MiraiConsoleI
|
||||
phase("load PermissionService") {
|
||||
mainLogger.verbose { "Loading PermissionService..." }
|
||||
|
||||
PermissionServiceProvider.permissionServiceOk = true
|
||||
PermissionService.INSTANCE.let { ps ->
|
||||
if (ps is BuiltInPermissionService) {
|
||||
ConsoleDataScope.addAndReloadConfig(ps.config)
|
||||
|
Loading…
Reference in New Issue
Block a user