From b648d21068c49d71f650cdbdd75a8e3de76e6cf8 Mon Sep 17 00:00:00 2001 From: Kr328 <39107975+Kr328@users.noreply.github.com> Date: Wed, 8 Apr 2020 02:05:05 +0800 Subject: [PATCH] use ServiceStatusProvider instead of requery database --- .../service/clash/module/DynamicNotificationModule.kt | 7 +++---- .../clash/service/clash/module/StaticNotificationModule.kt | 5 ++--- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/service/src/main/java/com/github/kr328/clash/service/clash/module/DynamicNotificationModule.kt b/service/src/main/java/com/github/kr328/clash/service/clash/module/DynamicNotificationModule.kt index 6888d8c..7ec52e6 100644 --- a/service/src/main/java/com/github/kr328/clash/service/clash/module/DynamicNotificationModule.kt +++ b/service/src/main/java/com/github/kr328/clash/service/clash/module/DynamicNotificationModule.kt @@ -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" } } \ No newline at end of file diff --git a/service/src/main/java/com/github/kr328/clash/service/clash/module/StaticNotificationModule.kt b/service/src/main/java/com/github/kr328/clash/service/clash/module/StaticNotificationModule.kt index c835b3f..1c154fb 100644 --- a/service/src/main/java/com/github/kr328/clash/service/clash/module/StaticNotificationModule.kt +++ b/service/src/main/java/com/github/kr328/clash/service/clash/module/StaticNotificationModule.kt @@ -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)