mirror of
https://github.com/Mahdi-zarei/nekoray.git
synced 2025-12-19 05:30:06 +08:00
improve data view
This commit is contained in:
parent
2731e479ce
commit
313b9161e5
20
core/server/internal/utils.go
Normal file
20
core/server/internal/utils.go
Normal file
@ -0,0 +1,20 @@
|
||||
package internal
|
||||
|
||||
import "fmt"
|
||||
|
||||
const (
|
||||
Gb = 1000 * Mb
|
||||
Mb = 1000 * Kb
|
||||
Kb = 1000
|
||||
)
|
||||
|
||||
func BrateToStr(brate float64) string {
|
||||
brate *= 8
|
||||
if brate >= Gb {
|
||||
return fmt.Sprintf("%.2f%s", brate/Gb, "Gbps")
|
||||
}
|
||||
if brate >= Mb {
|
||||
return fmt.Sprintf("%.2f%s", brate/Mb, "Mbps")
|
||||
}
|
||||
return fmt.Sprintf("%.2f%s", brate/Kb, "Kbps")
|
||||
}
|
||||
@ -8,6 +8,7 @@ import (
|
||||
"github.com/sagernet/sing-box/adapter"
|
||||
"github.com/sagernet/sing/common/metadata"
|
||||
"github.com/sagernet/sing/service"
|
||||
"nekobox_core/internal"
|
||||
"nekobox_core/internal/boxbox"
|
||||
"net"
|
||||
"net/http"
|
||||
@ -225,16 +226,16 @@ func speedTestWithDialer(ctx context.Context, dialer func(ctx context.Context, n
|
||||
for {
|
||||
select {
|
||||
case <-done:
|
||||
res.DlSpeed = srv[0].DLSpeed.String()
|
||||
res.UlSpeed = srv[0].ULSpeed.String()
|
||||
res.DlSpeed = internal.BrateToStr(float64(srv[0].DLSpeed))
|
||||
res.UlSpeed = internal.BrateToStr(float64(srv[0].ULSpeed))
|
||||
res.Latency = int32(srv[0].Latency.Milliseconds())
|
||||
SpTQuerier.storeResult(res)
|
||||
return nil
|
||||
case <-ctx.Done():
|
||||
return nil
|
||||
case <-ticker.C:
|
||||
res.DlSpeed = speedtest.ByteRate(srv[0].Context.GetEWMADownloadRate()).String()
|
||||
res.UlSpeed = speedtest.ByteRate(srv[0].Context.GetEWMAUploadRate()).String()
|
||||
res.DlSpeed = internal.BrateToStr(srv[0].Context.GetEWMADownloadRate())
|
||||
res.UlSpeed = internal.BrateToStr(srv[0].Context.GetEWMAUploadRate())
|
||||
SpTQuerier.storeResult(res)
|
||||
}
|
||||
}
|
||||
|
||||
@ -200,6 +200,7 @@ private:
|
||||
SpeedWidget *speedChartWidget;
|
||||
//
|
||||
// for data view
|
||||
QDateTime lastUpdated = QDateTime::currentDateTime();
|
||||
QString currentSptProfileName;
|
||||
bool showSpeedtestData = false;
|
||||
bool showDownloadData = false;
|
||||
|
||||
@ -930,6 +930,10 @@ void MainWindow::neko_set_spmode_vpn(bool enable, bool save) {
|
||||
|
||||
void MainWindow::UpdateDataView()
|
||||
{
|
||||
if (lastUpdated.msecsTo(QDateTime::currentDateTime()) < 100)
|
||||
{
|
||||
return;
|
||||
}
|
||||
QString html;
|
||||
if (showDownloadData)
|
||||
{
|
||||
@ -959,6 +963,7 @@ void MainWindow::UpdateDataView()
|
||||
currentTestResult.server_name().c_str());
|
||||
}
|
||||
ui->data_view->setHtml(html);
|
||||
lastUpdated = QDateTime::currentDateTime();
|
||||
}
|
||||
|
||||
void MainWindow::setDownloadReport(const DownloadProgressReport& report, bool show)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user