optimized test

This commit is contained in:
arm64v8a
2023-02-15 17:03:05 +09:00
parent e88021eb88
commit 705e9e0152
7 changed files with 38 additions and 31 deletions

View File

@@ -198,10 +198,7 @@ namespace NekoRay {
}
QSharedPointer<ProxyEntity> ProfileManager::GetProfile(int id) {
if (profiles.contains(id)) {
return profiles[id];
}
return nullptr;
return profiles.value(id, nullptr);
}
// Group
@@ -264,10 +261,7 @@ namespace NekoRay {
}
QSharedPointer<Group> ProfileManager::GetGroup(int id) {
if (groups.contains(id)) {
return groups[id];
}
return nullptr;
return groups.value(id, nullptr);
}
QSharedPointer<Group> ProfileManager::CurrentGroup() {

View File

@@ -49,7 +49,7 @@ namespace QtGrpc {
}
};
class Http2GrpcChannelPrivate : public QObject {
class Http2GrpcChannelPrivate {
private:
QThread *thread;
QNetworkAccessManager *nm;
@@ -117,7 +117,7 @@ namespace QtGrpc {
abortTimer = new QTimer;
abortTimer->setSingleShot(true);
abortTimer->setInterval(timeout_ms);
connect(abortTimer, &QTimer::timeout, abortTimer, [=]() {
QObject::connect(abortTimer, &QTimer::timeout, abortTimer, [=]() {
networkReply->abort();
});
abortTimer->start();
@@ -156,6 +156,13 @@ namespace QtGrpc {
thread->start();
}
~Http2GrpcChannelPrivate() {
nm->deleteLater();
thread->quit();
thread->wait();
thread->deleteLater();
}
QNetworkReply::NetworkError Call(const QString &methodName,
const google::protobuf::Message &req, google::protobuf::Message *rsp,
int timeout_ms = 0) {
@@ -194,8 +201,10 @@ namespace QtGrpc {
} // namespace QtGrpc
namespace NekoRay::rpc {
Client::Client(std::function<void(const QString &)> onError, const QString &target, const QString &token) {
this->grpc_channel = std::make_unique<QtGrpc::Http2GrpcChannelPrivate>(target, token, "libcore.LibcoreService");
this->make_grpc_channel = [=]() { return std::make_unique<QtGrpc::Http2GrpcChannelPrivate>(target, token, "libcore.LibcoreService"); };
this->default_grpc_channel = make_grpc_channel();
this->onError = std::move(onError);
}
@@ -206,12 +215,12 @@ namespace NekoRay::rpc {
void Client::Exit() {
libcore::EmptyReq request;
libcore::EmptyResp reply;
grpc_channel->Call("Exit", request, &reply, 500);
default_grpc_channel->Call("Exit", request, &reply, 500);
}
QString Client::Start(bool *rpcOK, const libcore::LoadConfigReq &request) {
libcore::ErrorResp reply;
auto status = grpc_channel->Call("Start", request, &reply, 3000);
auto status = default_grpc_channel->Call("Start", request, &reply, 3000);
if (status == QNetworkReply::NoError) {
*rpcOK = true;
@@ -225,7 +234,7 @@ namespace NekoRay::rpc {
QString Client::Stop(bool *rpcOK) {
libcore::EmptyReq request;
libcore::ErrorResp reply;
auto status = grpc_channel->Call("Stop", request, &reply, 3000);
auto status = default_grpc_channel->Call("Stop", request, &reply, 3000);
if (status == QNetworkReply::NoError) {
*rpcOK = true;
@@ -242,7 +251,7 @@ namespace NekoRay::rpc {
request.set_direct(direct);
libcore::QueryStatsResp reply;
auto status = grpc_channel->Call("QueryStats", request, &reply, 500);
auto status = default_grpc_channel->Call("QueryStats", request, &reply, 500);
if (status == QNetworkReply::NoError) {
return reply.traffic();
@@ -254,7 +263,7 @@ namespace NekoRay::rpc {
std::string Client::ListConnections() {
libcore::EmptyReq request;
libcore::ListConnectionsResp reply;
auto status = grpc_channel->Call("ListConnections", request, &reply, 500);
auto status = default_grpc_channel->Call("ListConnections", request, &reply, 500);
if (status == QNetworkReply::NoError) {
return reply.nekoray_connections_json();
@@ -267,7 +276,7 @@ namespace NekoRay::rpc {
libcore::TestResp Client::Test(bool *rpcOK, const libcore::TestReq &request) {
libcore::TestResp reply;
auto status = grpc_channel->Call("Test", request, &reply);
auto status = make_grpc_channel()->Call("Test", request, &reply);
if (status == QNetworkReply::NoError) {
*rpcOK = true;
@@ -280,7 +289,7 @@ namespace NekoRay::rpc {
libcore::UpdateResp Client::Update(bool *rpcOK, const libcore::UpdateReq &request) {
libcore::UpdateResp reply;
auto status = grpc_channel->Call("Update", request, &reply);
auto status = default_grpc_channel->Call("Update", request, &reply);
if (status == QNetworkReply::NoError) {
*rpcOK = true;

View File

@@ -33,7 +33,8 @@ namespace NekoRay::rpc {
libcore::UpdateResp Update(bool *rpcOK, const libcore::UpdateReq &request);
private:
std::unique_ptr<QtGrpc::Http2GrpcChannelPrivate> grpc_channel;
std::function<std::unique_ptr<QtGrpc::Http2GrpcChannelPrivate>()> make_grpc_channel;
std::unique_ptr<QtGrpc::Http2GrpcChannelPrivate> default_grpc_channel;
std::function<void(const QString &)> onError;
};

View File

@@ -694,7 +694,7 @@
</message>
<message>
<source>Certificate</source>
<translation type="unfinished"></translation>
<translation type="unfinished">گواهی</translation>
</message>
<message>
<source>Insecure concurrency</source>

View File

@@ -75,9 +75,9 @@ DialogEditProfile::DialogEditProfile(const QString &_type, int profileOrGroupId,
if (IS_NEKO_BOX) {
ui->header_type->setVisible(false);
ui->header_type_l->setVisible(false);
ui->utlsFingerprint->addItems({"", "chrome", "firefox", "edge", "safari", "360", "qq", "ios", "android", "random"});
if (!ui->utlsFingerprint->count()) ui->utlsFingerprint->addItems({"", "chrome", "firefox", "edge", "safari", "360", "qq", "ios", "android", "random"});
} else {
ui->utlsFingerprint->addItems({"", "randomized", "randomizedalpn", "randomizednoalpn", "firefox_auto", "firefox_55", "firefox_56", "firefox_63", "firefox_65", "firefox_99", "firefox_102", "firefox_105", "chrome_auto", "chrome_58", "chrome_62", "chrome_70", "chrome_72", "chrome_83", "chrome_87", "chrome_96", "chrome_100", "chrome_102", "ios_auto", "ios_11_1", "ios_12_1", "ios_13", "ios_14", "android_11_okhttp", "edge_auto", "edge_85", "edge_106", "safari_auto", "safari_16_0", "360_auto", "360_7_5", "360_11_0", "qq_auto", "qq_11_1"});
if (!ui->utlsFingerprint->count()) ui->utlsFingerprint->addItems({"", "randomized", "randomizedalpn", "randomizednoalpn", "firefox_auto", "firefox_55", "firefox_56", "firefox_63", "firefox_65", "firefox_99", "firefox_102", "firefox_105", "chrome_auto", "chrome_58", "chrome_62", "chrome_70", "chrome_72", "chrome_83", "chrome_87", "chrome_96", "chrome_100", "chrome_102", "ios_auto", "ios_11_1", "ios_12_1", "ios_13", "ios_14", "android_11_okhttp", "edge_auto", "edge_85", "edge_106", "safari_auto", "safari_16_0", "360_auto", "360_7_5", "360_11_0", "qq_auto", "qq_11_1"});
}
// 传输设置 是否可见
int networkBoxVisible = 0;

View File

@@ -883,16 +883,17 @@ void MainWindow::refresh_proxy_list_impl(const int &id, NekoRay::GroupSortAction
void MainWindow::refresh_proxy_list_impl_refresh_data(const int &id) {
// 绘制或更新item(s)
for (int row = 0; row < ui->proxyListTable->rowCount(); row++) {
auto profile = NekoRay::profileManager->GetProfile(ui->proxyListTable->row2Id[row]);
auto profileId = ui->proxyListTable->row2Id[row];
if (id >= 0 && profileId != id) continue; // refresh ONE item
auto profile = NekoRay::profileManager->GetProfile(profileId);
if (profile == nullptr) continue;
if (id >= 0 && profile->id != id) continue; // refresh ONE item
auto f0 = std::make_unique<QTableWidgetItem>();
f0->setData(114514, profile->id);
f0->setData(114514, profileId);
// Check state
auto check = f0->clone();
check->setText(profile->id == NekoRay::dataStore->started_id ? "" : Int2String(row + 1));
check->setText(profileId == NekoRay::dataStore->started_id ? "" : Int2String(row + 1));
ui->proxyListTable->setVerticalHeaderItem(row, check);
// C0: Type

View File

@@ -131,11 +131,13 @@ void MainWindow::speedtest_current_group(int mode) {
profile->full_test_report = result.full_report().c_str();
profile->Save();
runOnUiThread([=] {
if (!result.error().empty()) {
show_log_impl(tr("[%1] test error: %2").arg(profile->bean->DisplayTypeAndName(), result.error().c_str()));
MW_show_log(tr("[%1] test error: %2").arg(profile->bean->DisplayTypeAndName(), result.error().c_str()));
}
refresh_proxy_list(profile->id);
auto profileId = profile->id;
runOnUiThread([this, profileId] {
refresh_proxy_list(profileId);
});
}
});