mirror of
https://github.com/mamoe/mirai.git
synced 2025-01-27 08:50:15 +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] 选择后的实例.
|
* 由 [SingletonExtensionSelector] 选择后的实例.
|
||||||
*/
|
*/
|
||||||
@ConsoleExperimentalApi
|
@ConsoleExperimentalApi
|
||||||
public val selectedInstance: T by lazy {
|
public open val selectedInstance: T by lazy {
|
||||||
GlobalComponentStorage.run { this@AbstractSingletonExtensionPoint.findSingletonInstance(extensionType, builtinImplementation) }
|
GlobalComponentStorage.run { this@AbstractSingletonExtensionPoint.findSingletonInstance(extensionType, builtinImplementation) }
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -25,6 +25,8 @@ import net.mamoe.mirai.console.util.ConsoleExperimentalApi
|
|||||||
public interface PermissionServiceProvider : SingletonExtension<PermissionService<*>> {
|
public interface PermissionServiceProvider : SingletonExtension<PermissionService<*>> {
|
||||||
public companion object ExtensionPoint :
|
public companion object ExtensionPoint :
|
||||||
AbstractSingletonExtensionPoint<PermissionServiceProvider, PermissionService<*>>(PermissionServiceProvider::class, BuiltInPermissionService) {
|
AbstractSingletonExtensionPoint<PermissionServiceProvider, PermissionService<*>>(PermissionServiceProvider::class, BuiltInPermissionService) {
|
||||||
|
internal var permissionServiceOk = false
|
||||||
|
|
||||||
@ConsoleExperimentalApi
|
@ConsoleExperimentalApi
|
||||||
public val providerPlugin: Plugin? by lazy {
|
public val providerPlugin: Plugin? by lazy {
|
||||||
GlobalComponentStorage.run {
|
GlobalComponentStorage.run {
|
||||||
@ -33,6 +35,15 @@ public interface PermissionServiceProvider : SingletonExtension<PermissionServic
|
|||||||
PermissionServiceProvider.getExtensions().find { it.extension.instance === instance }?.plugin
|
PermissionServiceProvider.getExtensions().find { it.extension.instance === instance }?.plugin
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ConsoleExperimentalApi
|
||||||
|
override val selectedInstance: PermissionService<*>
|
||||||
|
get() {
|
||||||
|
if (!permissionServiceOk) {
|
||||||
|
error("PermissionService not yet loaded")
|
||||||
|
}
|
||||||
|
return super.selectedInstance
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -180,6 +180,7 @@ internal object MiraiConsoleImplementationBridge : CoroutineScope, MiraiConsoleI
|
|||||||
phase("load PermissionService") {
|
phase("load PermissionService") {
|
||||||
mainLogger.verbose { "Loading PermissionService..." }
|
mainLogger.verbose { "Loading PermissionService..." }
|
||||||
|
|
||||||
|
PermissionServiceProvider.permissionServiceOk = true
|
||||||
PermissionService.INSTANCE.let { ps ->
|
PermissionService.INSTANCE.let { ps ->
|
||||||
if (ps is BuiltInPermissionService) {
|
if (ps is BuiltInPermissionService) {
|
||||||
ConsoleDataScope.addAndReloadConfig(ps.config)
|
ConsoleDataScope.addAndReloadConfig(ps.config)
|
||||||
|
Loading…
Reference in New Issue
Block a user