mirror of
https://github.com/mamoe/mirai.git
synced 2025-01-30 02:30:12 +08:00
[core] Provide CoroutineScope to service
This commit is contained in:
parent
c080cd19f2
commit
19132b359b
@ -17,6 +17,7 @@ import net.mamoe.mirai.internal.spi.GlobalEncryptServiceUsage
|
|||||||
import net.mamoe.mirai.internal.utils.actualCacheDir
|
import net.mamoe.mirai.internal.utils.actualCacheDir
|
||||||
import net.mamoe.mirai.internal.utils.workingDirPath
|
import net.mamoe.mirai.internal.utils.workingDirPath
|
||||||
import net.mamoe.mirai.utils.buildTypeSafeMap
|
import net.mamoe.mirai.utils.buildTypeSafeMap
|
||||||
|
import net.mamoe.mirai.utils.childScope
|
||||||
|
|
||||||
internal interface EncryptServiceHolder {
|
internal interface EncryptServiceHolder {
|
||||||
companion object : ComponentKey<EncryptServiceHolder>
|
companion object : ComponentKey<EncryptServiceHolder>
|
||||||
@ -52,7 +53,9 @@ internal class EncryptServiceHolderImpl(
|
|||||||
set(EncryptServiceContext.KEY_DEVICE_INFO, ssoProcessorContext.device)
|
set(EncryptServiceContext.KEY_DEVICE_INFO, ssoProcessorContext.device)
|
||||||
set(EncryptServiceContext.KEY_BOT_WORKING_DIR, bot.configuration.workingDirPath)
|
set(EncryptServiceContext.KEY_BOT_WORKING_DIR, bot.configuration.workingDirPath)
|
||||||
set(EncryptServiceContext.KEY_BOT_CACHING_DIR, bot.configuration.actualCacheDir().absolutePath)
|
set(EncryptServiceContext.KEY_BOT_CACHING_DIR, bot.configuration.actualCacheDir().absolutePath)
|
||||||
})
|
}),
|
||||||
|
|
||||||
|
bot.childScope(name = "Encrypt Service"),
|
||||||
)
|
)
|
||||||
isAvailable = true
|
isAvailable = true
|
||||||
}
|
}
|
||||||
|
@ -10,6 +10,7 @@
|
|||||||
|
|
||||||
package net.mamoe.mirai.internal.spi
|
package net.mamoe.mirai.internal.spi
|
||||||
|
|
||||||
|
import kotlinx.coroutines.CoroutineScope
|
||||||
import net.mamoe.mirai.Bot
|
import net.mamoe.mirai.Bot
|
||||||
import net.mamoe.mirai.spi.BaseService
|
import net.mamoe.mirai.spi.BaseService
|
||||||
import net.mamoe.mirai.spi.SpiServiceLoader
|
import net.mamoe.mirai.spi.SpiServiceLoader
|
||||||
@ -43,7 +44,12 @@ public class EncryptServiceContext @MiraiInternalApi constructor(
|
|||||||
*/
|
*/
|
||||||
public interface EncryptService : BaseService {
|
public interface EncryptService : BaseService {
|
||||||
/** service per bot */
|
/** service per bot */
|
||||||
public fun attachToBot(context: EncryptServiceContext): EncryptService = this
|
public fun attachToBot(context: EncryptServiceContext, serviceSubScope: CoroutineScope): EncryptService {
|
||||||
|
/* cleanup:
|
||||||
|
serviceSubScope.coroutineContext.job.invokeOnCompletion { }
|
||||||
|
*/
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
public fun initialize(context: EncryptServiceContext)
|
public fun initialize(context: EncryptServiceContext)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user