This commit is contained in:
lisonge 2024-03-05 15:02:15 +08:00
parent 474cf63661
commit eb71b9420a
2 changed files with 17 additions and 10 deletions

View File

@ -3,17 +3,24 @@ package li.songe.gkd.db
import androidx.room.Room
import li.songe.gkd.app
import li.songe.gkd.util.dbFolder
import java.io.File
object DbSet {
private val appDb by lazy {
Room.databaseBuilder(
app, AppDb::class.java, File(dbFolder, "gkd.db").absolutePath
private fun buildDb(): AppDb {
return Room.databaseBuilder(
app, AppDb::class.java, dbFolder.resolve("gkd.db").absolutePath
).fallbackToDestructiveMigration().build()
}
val subsItemDao by lazy { appDb.subsItemDao() }
val subsConfigDao by lazy { appDb.subsConfigDao() }
val snapshotDao by lazy { appDb.snapshotDao() }
val clickLogDao by lazy { appDb.clickLogDao() }
val categoryConfigDao by lazy { appDb.categoryConfigDao() }
private val db by lazy { buildDb() }
val subsItemDao
get() = db.subsItemDao()
val subsConfigDao
get() = db.subsConfigDao()
val snapshotDao
get() = db.snapshotDao()
val clickLogDao
get() = db.clickLogDao()
val categoryConfigDao
get() = db.categoryConfigDao()
}

View File

@ -109,7 +109,7 @@ fun updateLauncherAppId() {
launcherAppId = app.packageManager.getDefaultLauncherAppId() ?: ""
}
val clickLogMutex = Mutex()
val clickLogMutex by lazy { Mutex() }
suspend fun insertClickLog(rule: ResolvedRule) {
clickLogMutex.withLock {
increaseClickCount()