mirror of
https://github.com/yJason/ClashX-Dashboard.git
synced 2026-03-01 00:35:19 +08:00
feat: connections speeds
This commit is contained in:
@@ -66,6 +66,11 @@ class DBConnectionObject: NSObject {
|
||||
@objc let destinationIP: String?
|
||||
@objc let type: String
|
||||
|
||||
@objc var downloadSpeed: Int64
|
||||
@objc var uploadSpeed: Int64
|
||||
var downloadSpeedString: String
|
||||
var uploadSpeedString: String
|
||||
|
||||
|
||||
func isContentEqual(to source: DBConnectionObject) -> Bool {
|
||||
download == source.download &&
|
||||
@@ -99,6 +104,40 @@ class DBConnectionObject: NSObject {
|
||||
metadata.host].first(where: { $0 != "" })
|
||||
|
||||
type = "\(metadata.type)(\(metadata.network))"
|
||||
|
||||
downloadSpeed = 0
|
||||
uploadSpeed = 0
|
||||
downloadSpeedString = ""
|
||||
uploadSpeedString = ""
|
||||
}
|
||||
|
||||
|
||||
func updateSpeeds(_ old: (download: Int64, upload: Int64)?) {
|
||||
guard let old = old else {
|
||||
downloadSpeed = 0
|
||||
uploadSpeed = 0
|
||||
downloadSpeedString = ""
|
||||
uploadSpeedString = ""
|
||||
return
|
||||
}
|
||||
|
||||
let byteCountFormatter = ByteCountFormatter()
|
||||
|
||||
downloadSpeed = download - old.download
|
||||
uploadSpeed = upload - old.upload
|
||||
|
||||
if downloadSpeed >= 0 {
|
||||
downloadSpeedString = byteCountFormatter.string(fromByteCount: downloadSpeed) + "/s"
|
||||
} else {
|
||||
downloadSpeed = 0
|
||||
downloadSpeedString = ""
|
||||
}
|
||||
|
||||
if uploadSpeed >= 0 {
|
||||
uploadSpeedString = byteCountFormatter.string(fromByteCount: uploadSpeed) + "/s"
|
||||
} else {
|
||||
uploadSpeed = 0
|
||||
uploadSpeedString = ""
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user