use ServiceStatusProvider instead of requery database

This commit is contained in:
Kr328 committed 2020-04-08 02:05:05 +08:00
1 parent 2b63997b22
commit b648d21068
2 files changed
+5 -7

No files matched your search

@@ -11,6 +11,7 @@ import com.github.kr328.clash.common.ids.NotificationIds
import com.github.kr328.clash.core.Clash
import com.github.kr328.clash.core.utils.asBytesString
import com.github.kr328.clash.service.R
import com.github.kr328.clash.service.ServiceStatusProvider
import com.github.kr328.clash.service.data.ClashDatabase
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
@@ -93,9 +94,7 @@ class DynamicNotificationModule(private val service: Service) : Module() {
}
}
private suspend fun reload() {
val active =
ClashDatabase.getInstance(service).openClashProfileDao().queryActiveProfile()
currentProfile = active?.name ?: "Not selected"
private fun reload() {
currentProfile = ServiceStatusProvider.currentProfile ?: "Not selected"
}
}
@@ -12,6 +12,7 @@ import com.github.kr328.clash.common.ids.Intents
import com.github.kr328.clash.common.ids.NotificationChannels
import com.github.kr328.clash.common.ids.NotificationIds
import com.github.kr328.clash.service.R
import com.github.kr328.clash.service.ServiceStatusProvider
import com.github.kr328.clash.service.data.ClashDatabase
class StaticNotificationModule(private val service: Service) : Module() {
@@ -51,9 +52,7 @@ class StaticNotificationModule(private val service: Service) : Module() {
}
private suspend fun update() {
val database = ClashDatabase.getInstance(service).openClashProfileDao()
val profileName = database.queryActiveProfile()?.name ?: "Not selected"
val profileName = ServiceStatusProvider.currentProfile ?: "Not selected"
val notification = builder
.setContentTitle(profileName)