cloudroam
2025-04-10 5fc9567cfa6b6beee4f52a9f835f304865d693e1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package com.example.firstapp.core
 
import android.app.Application
import androidx.work.Configuration
import com.example.firstapp.App
import com.example.firstapp.database.repository.CodeRepository
import com.example.firstapp.database.repository.KeywordRepository
import com.example.firstapp.database.repository.MsgRepository
 
import kotlinx.coroutines.launch
 
object Core : Configuration.Provider {
    lateinit var app: Application
 
    val msg: MsgRepository by lazy { (app as App).msgRepository }
    val code: CodeRepository by lazy { (app as App).codeRepository }
    val keyword: KeywordRepository by lazy { (app as App).keywordRepository }
 
    fun init(app: Application) {
        this.app = app
    }
 
    override fun getWorkManagerConfiguration(): Configuration {
        return Configuration.Builder().apply {
            setDefaultProcessName(app.packageName + ":bg")
//            setMinimumLoggingLevel(if (BuildConfig.DEBUG) Log.VERBOSE else Log.INFO)
            setExecutor { (app as App).applicationScope.launch { it.run() } }
            setTaskExecutor { (app as App).applicationScope.launch { it.run() } }
        }.build()
    }
}