mirror of
https://github.com/MetaCubeX/ClashMetaForAndroid.git
synced 2025-02-16 14:53:15 +03:00
Avoid starting foreground service repeatedly
This commit is contained in:
parent
a9b10acac2
commit
26c2ecef6d
@ -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 {
|
||||
|
Loading…
x
Reference in New Issue
Block a user