From 9c8b28549cbf5c213263cf990fcc6f49d5036dfd Mon Sep 17 00:00:00 2001
From: arm64v8a <48624112+arm64v8a@users.noreply.github.com>
Date: Mon, 17 Apr 2023 13:32:09 +0900
Subject: [PATCH] backport: 20230323
---
.../java/io/nekohasekai/sagernet/bg/BaseService.kt | 2 +-
.../nekohasekai/sagernet/bg/ServiceNotification.kt | 14 ++++++++++++--
.../io/nekohasekai/sagernet/database/DataStore.kt | 1 +
app/src/main/res/values-zh-rCN/strings.xml | 1 +
app/src/main/res/values/strings.xml | 1 +
app/src/main/res/xml/global_preferences.xml | 3 +++
6 files changed, 19 insertions(+), 3 deletions(-)
diff --git a/app/src/main/java/io/nekohasekai/sagernet/bg/BaseService.kt b/app/src/main/java/io/nekohasekai/sagernet/bg/BaseService.kt
index 214b0031d..d6eb41be2 100644
--- a/app/src/main/java/io/nekohasekai/sagernet/bg/BaseService.kt
+++ b/app/src/main/java/io/nekohasekai/sagernet/bg/BaseService.kt
@@ -503,7 +503,7 @@ class BaseService {
data.changeState(State.Connecting)
runOnMainDispatcher {
try {
- data.notification = createNotification(profile.displayName())
+ data.notification = createNotification(ServiceNotification.genTitle(profile))
Executable.killAll() // clean up old processes
preInit()
diff --git a/app/src/main/java/io/nekohasekai/sagernet/bg/ServiceNotification.kt b/app/src/main/java/io/nekohasekai/sagernet/bg/ServiceNotification.kt
index a05a1667b..e6d9f7e61 100644
--- a/app/src/main/java/io/nekohasekai/sagernet/bg/ServiceNotification.kt
+++ b/app/src/main/java/io/nekohasekai/sagernet/bg/ServiceNotification.kt
@@ -38,6 +38,8 @@ import io.nekohasekai.sagernet.aidl.AppStatsList
import io.nekohasekai.sagernet.aidl.ISagerNetServiceCallback
import io.nekohasekai.sagernet.aidl.TrafficStats
import io.nekohasekai.sagernet.database.DataStore
+import io.nekohasekai.sagernet.database.ProxyEntity
+import io.nekohasekai.sagernet.database.SagerDatabase
import io.nekohasekai.sagernet.ktx.app
import io.nekohasekai.sagernet.ktx.getColorAttr
import io.nekohasekai.sagernet.ui.SwitchActivity
@@ -59,7 +61,14 @@ class ServiceNotification(
) : BroadcastReceiver() {
companion object {
const val notificationId = 1
- val flags = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) PendingIntent.FLAG_IMMUTABLE else 0
+ val flags =
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) PendingIntent.FLAG_IMMUTABLE else 0
+
+ fun genTitle(ent: ProxyEntity): String {
+ val gn = if (DataStore.showGroupInNotification)
+ SagerDatabase.groupDao.getById(ent.groupId)?.displayName() else null
+ return if (gn == null) ent.displayName() else "[$gn] ${ent.displayName()}"
+ }
}
val trafficStatistics = DataStore.profileTrafficStatistics
@@ -119,7 +128,8 @@ class ServiceNotification(
override fun updateWakeLockStatus(acquired: Boolean) {
updateActions(acquired)
- builder.priority = if (acquired) NotificationCompat.PRIORITY_HIGH else NotificationCompat.PRIORITY_LOW
+ builder.priority =
+ if (acquired) NotificationCompat.PRIORITY_HIGH else NotificationCompat.PRIORITY_LOW
update()
}
}
diff --git a/app/src/main/java/io/nekohasekai/sagernet/database/DataStore.kt b/app/src/main/java/io/nekohasekai/sagernet/database/DataStore.kt
index 181a42686..b61def972 100644
--- a/app/src/main/java/io/nekohasekai/sagernet/database/DataStore.kt
+++ b/app/src/main/java/io/nekohasekai/sagernet/database/DataStore.kt
@@ -116,6 +116,7 @@ object DataStore : OnPreferenceDataStoreChangeListener {
var allowAccess by configurationStore.boolean(Key.ALLOW_ACCESS)
var speedInterval by configurationStore.stringToInt(Key.SPEED_INTERVAL)
+ var showGroupInNotification by configurationStore.boolean("showGroupInNotification")
var enhanceDomain by configurationStore.boolean(Key.ENHANCE_RESOLVE_SERVER_DOMAIN)
var remoteDns by configurationStore.string(Key.REMOTE_DNS) { "https://8.8.8.8/dns-query" }
diff --git a/app/src/main/res/values-zh-rCN/strings.xml b/app/src/main/res/values-zh-rCN/strings.xml
index 21ea5be2f..3cc9f8c0d 100644
--- a/app/src/main/res/values-zh-rCN/strings.xml
+++ b/app/src/main/res/values-zh-rCN/strings.xml
@@ -482,4 +482,5 @@
在核心中绕过 LAN
推广
分享订阅
+ 在通知中显示组名
\ No newline at end of file
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 7272ef67a..21b743603 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -522,5 +522,6 @@ Anyone can write advanced plugins, which can control Matsuri. please download an
Bypass LAN in Core
Ads
Share Subscription
+ Show group name in in notification
\ No newline at end of file
diff --git a/app/src/main/res/xml/global_preferences.xml b/app/src/main/res/xml/global_preferences.xml
index 6d989bfaf..b00eb3969 100644
--- a/app/src/main/res/xml/global_preferences.xml
+++ b/app/src/main/res/xml/global_preferences.xml
@@ -51,6 +51,9 @@
app:key="speedInterval"
app:title="@string/speed_interval"
app:useSimpleSummaryProvider="true" />
+