Skip to content

Commit

Permalink
backport: 20230323
Browse files Browse the repository at this point in the history
  • Loading branch information
arm64v8a committed Apr 17, 2023
1 parent b30ccfa commit 9c8b285
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-zh-rCN/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -482,4 +482,5 @@
<string name="bypass_lan_in_core">在核心中绕过 LAN</string>
<string name="ads">推广</string>
<string name="share_subscription">分享订阅</string>
<string name="show_group_in_notification">在通知中显示组名</string>
</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -522,5 +522,6 @@ Anyone can write advanced plugins, which can control Matsuri. please download an
<string name="bypass_lan_in_core">Bypass LAN in Core</string>
<string name="ads">Ads</string>
<string name="share_subscription">Share Subscription</string>
<string name="show_group_in_notification">Show group name in in notification</string>

</resources>
3 changes: 3 additions & 0 deletions app/src/main/res/xml/global_preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@
app:key="speedInterval"
app:title="@string/speed_interval"
app:useSimpleSummaryProvider="true" />
<SwitchPreference
app:key="showGroupInNotification"
app:title="@string/show_group_in_notification" />
<SwitchPreference
app:icon="@drawable/ic_baseline_center_focus_weak_24"
app:key="alwaysShowAddress"
Expand Down

0 comments on commit 9c8b285

Please sign in to comment.