This commit is contained in:
Kr328 committed 2019-12-17 13:59:54 +08:00
1 parent 62910f5e7e
commit 5bcbc4563e
6 files changed
+24 -11

No files matched your search

+2 -2
View File
@@ -13,8 +13,8 @@ android {
applicationId "com.github.kr328.clash"
minSdkVersion 24
targetSdkVersion 29
versionCode 10019
versionName "1.0.19-alpha"
versionCode 10020
versionName "1.0.20-alpha"
}
buildTypes {
release {
@@ -90,7 +90,7 @@ class MainActivity : BaseActivity() {
activity_main_clash_status_icon.setImageResource(R.drawable.ic_clash_started)
activity_main_clash_status_title.text = getString(R.string.clash_status_started)
activity_main_clash_status_summary.text =
getString(R.string.clash_status_forwarded_traffic, "0 Bytes")
getString(R.string.clash_status_forwarded_traffic, ByteFormatter.byteToString(0))
activity_main_clash_proxies.visibility = View.VISIBLE
activity_main_clash_logs.visibility = View.VISIBLE
}
+16 -4
View File
@@ -31,6 +31,13 @@ func PollTraffic(traffic Traffic) *EventPoll {
stopChannel := make(chan int, 1)
ticker := time.NewTicker(time.Second)
tick := func() {
up, down := tunnel.DefaultManager.Now()
traffic.OnEvent(down, up)
}
tick()
go func() {
defer close(stopChannel)
defer log.Infoln("Traffic Poll Stopped")
@@ -40,8 +47,7 @@ func PollTraffic(traffic Traffic) *EventPoll {
case <-stopChannel:
return
case <-ticker.C:
up, down := tunnel.DefaultManager.Now()
traffic.OnEvent(down, up)
tick()
}
}
}()
@@ -57,6 +63,13 @@ func PollBandwidth(bandwidth Bandwidth) *EventPoll {
stopChannel := make(chan int, 1)
ticker := time.NewTicker(time.Second)
tick := func() {
s := tunnel.DefaultManager.Snapshot()
bandwidth.OnEvent(s.DownloadTotal + s.UploadTotal)
}
tick()
go func() {
defer close(stopChannel)
defer log.Infoln("Bandwidth Poll Stopped")
@@ -66,8 +79,7 @@ func PollBandwidth(bandwidth Bandwidth) *EventPoll {
case <-stopChannel:
return
case <-ticker.C:
s := tunnel.DefaultManager.Snapshot()
bandwidth.OnEvent(s.DownloadTotal + s.UploadTotal)
tick()
}
}
}()
@@ -4,11 +4,11 @@ object ByteFormatter {
fun byteToString(bytes: Long): String {
return when {
bytes > 1024 * 1024 * 1024 ->
String.format("%.2f GB", (bytes.toDouble() / 1024 / 1024 / 1024))
String.format("%.2f GiB", (bytes.toDouble() / 1024 / 1024 / 1024))
bytes > 1024 * 1024 ->
String.format("%.2f MB", (bytes.toDouble() / 1024 / 1024))
String.format("%.2f MiB", (bytes.toDouble() / 1024 / 1024))
bytes > 1024 ->
String.format("%.2f KB", (bytes.toDouble() / 1024))
String.format("%.2f KiB", (bytes.toDouble() / 1024))
else ->
"$bytes Bytes"
}
@@ -25,6 +25,7 @@ class ClashNotification(private val context: Service) {
.setOngoing(true)
.setColor(context.getColor(R.color.colorAccentService))
//.setColorized(true)
.setOnlyAlertOnce(true)
.setShowWhen(false)
.setContentIntent(
PendingIntent.getActivity(