mirror of
https://github.com/Mahdi-zarei/nekoray.git
synced 2025-12-19 13:50:12 +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-box/adapter"
|
||||||
"github.com/sagernet/sing/common/metadata"
|
"github.com/sagernet/sing/common/metadata"
|
||||||
"github.com/sagernet/sing/service"
|
"github.com/sagernet/sing/service"
|
||||||
|
"nekobox_core/internal"
|
||||||
"nekobox_core/internal/boxbox"
|
"nekobox_core/internal/boxbox"
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
@ -225,16 +226,16 @@ func speedTestWithDialer(ctx context.Context, dialer func(ctx context.Context, n
|
|||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case <-done:
|
case <-done:
|
||||||
res.DlSpeed = srv[0].DLSpeed.String()
|
res.DlSpeed = internal.BrateToStr(float64(srv[0].DLSpeed))
|
||||||
res.UlSpeed = srv[0].ULSpeed.String()
|
res.UlSpeed = internal.BrateToStr(float64(srv[0].ULSpeed))
|
||||||
res.Latency = int32(srv[0].Latency.Milliseconds())
|
res.Latency = int32(srv[0].Latency.Milliseconds())
|
||||||
SpTQuerier.storeResult(res)
|
SpTQuerier.storeResult(res)
|
||||||
return nil
|
return nil
|
||||||
case <-ctx.Done():
|
case <-ctx.Done():
|
||||||
return nil
|
return nil
|
||||||
case <-ticker.C:
|
case <-ticker.C:
|
||||||
res.DlSpeed = speedtest.ByteRate(srv[0].Context.GetEWMADownloadRate()).String()
|
res.DlSpeed = internal.BrateToStr(srv[0].Context.GetEWMADownloadRate())
|
||||||
res.UlSpeed = speedtest.ByteRate(srv[0].Context.GetEWMAUploadRate()).String()
|
res.UlSpeed = internal.BrateToStr(srv[0].Context.GetEWMAUploadRate())
|
||||||
SpTQuerier.storeResult(res)
|
SpTQuerier.storeResult(res)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -200,6 +200,7 @@ private:
|
|||||||
SpeedWidget *speedChartWidget;
|
SpeedWidget *speedChartWidget;
|
||||||
//
|
//
|
||||||
// for data view
|
// for data view
|
||||||
|
QDateTime lastUpdated = QDateTime::currentDateTime();
|
||||||
QString currentSptProfileName;
|
QString currentSptProfileName;
|
||||||
bool showSpeedtestData = false;
|
bool showSpeedtestData = false;
|
||||||
bool showDownloadData = false;
|
bool showDownloadData = false;
|
||||||
|
|||||||
@ -930,6 +930,10 @@ void MainWindow::neko_set_spmode_vpn(bool enable, bool save) {
|
|||||||
|
|
||||||
void MainWindow::UpdateDataView()
|
void MainWindow::UpdateDataView()
|
||||||
{
|
{
|
||||||
|
if (lastUpdated.msecsTo(QDateTime::currentDateTime()) < 100)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
QString html;
|
QString html;
|
||||||
if (showDownloadData)
|
if (showDownloadData)
|
||||||
{
|
{
|
||||||
@ -959,6 +963,7 @@ void MainWindow::UpdateDataView()
|
|||||||
currentTestResult.server_name().c_str());
|
currentTestResult.server_name().c_str());
|
||||||
}
|
}
|
||||||
ui->data_view->setHtml(html);
|
ui->data_view->setHtml(html);
|
||||||
|
lastUpdated = QDateTime::currentDateTime();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::setDownloadReport(const DownloadProgressReport& report, bool show)
|
void MainWindow::setDownloadReport(const DownloadProgressReport& report, bool show)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user