Skip to content

Commit

Permalink
Merge pull request #304 from aviraxp/patch-1
Browse files Browse the repository at this point in the history
Avoid starting foreground service repeatedly
  • Loading branch information
xishang0128 authored Aug 30, 2024
2 parents 0a1406e + 26c2ece commit fec7df0
Showing 1 changed file with 4 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand All @@ -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 {
Expand Down

0 comments on commit fec7df0

Please sign in to comment.