Merge pull request #304 from aviraxp/patch-1

Avoid starting foreground service repeatedly
This commit is contained in:
汐殇 2024-08-31 01:35:26 +08:00 committed by GitHub
commit fec7df02e4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -5,6 +5,7 @@ import android.app.Service
import android.content.Intent
import android.os.PowerManager
import androidx.core.app.NotificationCompat
import androidx.core.app.NotificationManagerCompat
import androidx.core.content.getSystemService
import com.github.kr328.clash.common.compat.getColorCompat
import com.github.kr328.clash.common.compat.pendingIntentFlags
@ -40,6 +41,8 @@ class DynamicNotificationModule(service: Service) : Module<Unit>(service) {
)
)
private val notificationManager = NotificationManagerCompat.from(service)
private fun update() {
val now = Clash.queryTrafficNow()
val total = Clash.queryTrafficTotal()
@ -64,7 +67,7 @@ class DynamicNotificationModule(service: Service) : Module<Unit>(service) {
)
.build()
service.startForeground(R.id.nf_clash_status, notification)
notificationManager.notify(R.id.nf_clash_status, notification)
}
override suspend fun run() = coroutineScope {