mirror of
https://github.com/MetaCubeX/ClashMetaForAndroid.git
synced 2026-05-09 18:11:26 +08:00
fix notification cancel delay
This commit is contained in:
@@ -6,10 +6,12 @@ import android.os.Build
|
||||
import androidx.core.app.NotificationCompat
|
||||
import androidx.core.app.NotificationManagerCompat
|
||||
import com.github.kr328.clash.core.Clash
|
||||
import com.github.kr328.clash.core.utils.Log
|
||||
import com.github.kr328.clash.core.utils.asBytesString
|
||||
import com.github.kr328.clash.core.utils.asSpeedString
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.withContext
|
||||
import kotlinx.serialization.serializer
|
||||
|
||||
class ClashNotification(
|
||||
private val context: Service
|
||||
@@ -49,9 +51,9 @@ class ClashNotification(
|
||||
}
|
||||
|
||||
fun destroy() {
|
||||
updateDestroy()
|
||||
|
||||
context.stopForeground(true)
|
||||
|
||||
updateDestroy()
|
||||
}
|
||||
|
||||
fun setProfile(profile: String) {
|
||||
@@ -78,10 +80,17 @@ class ClashNotification(
|
||||
private fun updateDestroy() {
|
||||
// just waiting system cancel our notification :)
|
||||
// fxxking google
|
||||
|
||||
val notification = baseBuilder
|
||||
.setContentTitle(context.getText(R.string.destroying))
|
||||
.setContentText(context.getText(R.string.recycling_resources))
|
||||
.setSubText(null)
|
||||
.build()
|
||||
|
||||
NotificationManagerCompat.from(context).apply {
|
||||
notify(CLASH_STATUS_NOTIFICATION_ID, notification)
|
||||
cancel(CLASH_STATUS_NOTIFICATION_ID)
|
||||
}
|
||||
}
|
||||
|
||||
private fun createNotification(): Notification {
|
||||
|
||||
@@ -9,4 +9,6 @@
|
||||
<string name="format_update_failure">更新 %s 失败\\n%s</string>
|
||||
<string name="process_result">处理结果</string>
|
||||
<string name="processing_profiles">正在处理配置文件</string>
|
||||
<string name="recycling_resources">正在回收资源</string>
|
||||
<string name="destroying">销毁中</string>
|
||||
</resources>
|
||||
Reference in New Issue
Block a user