mirror of
https://github.com/mamoe/mirai.git
synced 2025-01-13 20:10:09 +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.workingDirPath
|
||||
import net.mamoe.mirai.utils.buildTypeSafeMap
|
||||
import net.mamoe.mirai.utils.childScope
|
||||
|
||||
internal interface EncryptServiceHolder {
|
||||
companion object : ComponentKey<EncryptServiceHolder>
|
||||
@ -52,7 +53,9 @@ internal class EncryptServiceHolderImpl(
|
||||
set(EncryptServiceContext.KEY_DEVICE_INFO, ssoProcessorContext.device)
|
||||
set(EncryptServiceContext.KEY_BOT_WORKING_DIR, bot.configuration.workingDirPath)
|
||||
set(EncryptServiceContext.KEY_BOT_CACHING_DIR, bot.configuration.actualCacheDir().absolutePath)
|
||||
})
|
||||
}),
|
||||
|
||||
bot.childScope(name = "Encrypt Service"),
|
||||
)
|
||||
isAvailable = true
|
||||
}
|
||||
|
@ -10,6 +10,7 @@
|
||||
|
||||
package net.mamoe.mirai.internal.spi
|
||||
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import net.mamoe.mirai.Bot
|
||||
import net.mamoe.mirai.spi.BaseService
|
||||
import net.mamoe.mirai.spi.SpiServiceLoader
|
||||
@ -43,7 +44,12 @@ public class EncryptServiceContext @MiraiInternalApi constructor(
|
||||
*/
|
||||
public interface EncryptService : BaseService {
|
||||
/** 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)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user