This commit is contained in:
arm64v8a 2023-03-22 10:11:44 +09:00
parent 8a5a8c75ab
commit faf964e992
8 changed files with 28 additions and 11 deletions

View File

@ -156,7 +156,7 @@ class BaseService {
if (success) runOnDefaultDispatcher {
data.proxy!!.looper?.selectMain(ent.id)
data.binder.broadcast {
it.stateChanged(-1, ent.displayName(), null)
it.stateChanged(-1, ServiceNotification.genTitle(ent), null)
}
}
}
@ -321,7 +321,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()

View File

@ -17,6 +17,8 @@ import io.nekohasekai.sagernet.aidl.ISagerNetServiceCallback
import io.nekohasekai.sagernet.aidl.SpeedDisplayData
import io.nekohasekai.sagernet.aidl.TrafficData
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
@ -40,6 +42,12 @@ class ServiceNotification(
const val notificationId = 1
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 showDirectSpeed = DataStore.showDirectSpeed

View File

@ -18,7 +18,7 @@ class TrafficLooper
) {
private var job: Job? = null
private val items = mutableMapOf<Long, TrafficUpdater.TrafficLooperData>()
private val items = mutableMapOf<Long, TrafficUpdater.TrafficLooperData>() // associate ent id
suspend fun stop() {
job?.cancel()
@ -50,7 +50,7 @@ class TrafficLooper
job = sc.launch { loop() }
}
var selectorNowId = -1L
var selectorNowId = -114514L
var selectorNowFakeTag = ""
fun selectMain(id: Long) {
@ -111,6 +111,7 @@ class TrafficLooper
if (proxy.config.selectorGroupId >= 0L) {
itemMain = TrafficUpdater.TrafficLooperData(tag = TAG_PROXY)
itemMainBase = TrafficUpdater.TrafficLooperData(tag = TAG_PROXY)
items[-2] = itemMain!!
selectMain(proxy.config.mainEntId)
}
//
@ -136,9 +137,9 @@ class TrafficLooper
// traffic
val traffic = mutableMapOf<Long, TrafficData>()
if (DataStore.profileTrafficStatistics) {
proxy.config.trafficMap.forEach { (tag, ents) ->
proxy.config.trafficMap.forEach { (_, ents) ->
for (ent in ents) {
val item = items[ent.id] ?: return@forEach
val item = items[ent.id] ?: continue
ent.rx = item.rx
ent.tx = item.tx
// ProfileManager.updateProfile(ent) // update DB

View File

@ -66,5 +66,7 @@ class TrafficUpdater(
item.txRate = diff.txRate
}
}
// Logs.d(JavaUtil.gson.toJson(items))
// Logs.d(JavaUtil.gson.toJson(updated))
}
}

View File

@ -97,6 +97,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 remoteDns by configurationStore.string(Key.REMOTE_DNS) { "https://8.8.8.8/dns-query" }
var directDns by configurationStore.string(Key.DIRECT_DNS) { "https://223.5.5.5/dns-query" }

View File

@ -467,4 +467,5 @@
<string name="landing_proxy">落地代理</string>
<string name="shadowtls_version">ShadowTLS 版本</string>
<string name="share_subscription">分享订阅</string>
<string name="show_group_in_notification">在通知中显示组名</string>
</resources>

View File

@ -508,5 +508,6 @@ Anyone can write advanced plugins, which can control NekoBox. please download an
<string name="action_shadowtls" translatable="false">ShadowTLS</string>
<string name="shadowtls_version">ShadowTLS Version</string>
<string name="share_subscription">Share Subscription</string>
<string name="show_group_in_notification">Show group name in in notification</string>
</resources>

View File

@ -41,11 +41,6 @@
app:icon="@drawable/baseline_public_24"
app:key="mtu"
app:title="@string/mtu" />
<SwitchPreference
app:defaultValue="true"
app:key="profileTrafficStatistics"
app:summary="@string/profile_traffic_statistics_summary"
app:title="@string/profile_traffic_statistics" />
<moe.matsuri.nb4a.ui.SimpleMenuPreference
app:defaultValue="1000"
app:entries="@array/notification_entry"
@ -54,6 +49,14 @@
app:key="speedInterval"
app:title="@string/speed_interval"
app:useSimpleSummaryProvider="true" />
<SwitchPreference
app:defaultValue="true"
app:key="profileTrafficStatistics"
app:summary="@string/profile_traffic_statistics_summary"
app:title="@string/profile_traffic_statistics" />
<SwitchPreference
app:key="showGroupInNotification"
app:title="@string/show_group_in_notification" />
<SwitchPreference
app:icon="@drawable/ic_baseline_center_focus_weak_24"
app:key="alwaysShowAddress"