use ServiceStatusProvider instead of requery database
This commit is contained in:
2 files changed
+5
-7
No files matched your search
+3
-4
@@ -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"
|
||||
}
|
||||
}
|
||||
+2
-3
@@ -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)
|
||||
|
||||
Reference in new issue
Block a user