Skip to content

Commit

Permalink
merge latencyNotification_dev
Browse files Browse the repository at this point in the history
  • Loading branch information
khonoka committed Jan 17, 2022
2 parents 412f317 + 0207e54 commit 6a25328
Show file tree
Hide file tree
Showing 24 changed files with 481 additions and 111 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ set(PROJECT_HEADERS
src/view_models/nodelist.h
src/view_models/nodemodel.h
src/view_models/nodeformmodel.h
src/view_models/notificationmodel.h
src/view_models/buildinfo.h.in
src/view_models/systemtray.h
src/view_models/imageprovider.h
Expand Down Expand Up @@ -122,6 +123,7 @@ set(PROJECT_SOURCES
src/view_models/nodelist.cpp
src/view_models/nodemodel.cpp
src/view_models/nodeformmodel.cpp
src/view_models/notificationmodel.cpp
src/view_models/systemtray.cpp
src/view_models/imageprovider.cpp
src/view_models/jsonhighlighter.cpp
Expand Down
45 changes: 28 additions & 17 deletions i18n/across_zh_CN.ts
Original file line number Diff line number Diff line change
Expand Up @@ -614,7 +614,7 @@
<translation>编辑</translation>
</message>
<message>
<location filename="../src/views/home/GroupItemPopMenu.qml" line="30"/>
<location filename="../src/views/home/GroupItemPopMenu.qml" line="32"/>
<source>Copy URL</source>
<translation>复制链接</translation>
</message>
Expand All @@ -623,32 +623,32 @@
<translation type="vanished">ICMP Ping</translation>
</message>
<message>
<location filename="../src/views/home/GroupItemPopMenu.qml" line="37"/>
<location filename="../src/views/home/GroupItemPopMenu.qml" line="40"/>
<source>Copy Nodes</source>
<translation>复制节点</translation>
</message>
<message>
<location filename="../src/views/home/GroupItemPopMenu.qml" line="44"/>
<location filename="../src/views/home/GroupItemPopMenu.qml" line="48"/>
<source>TCP Ping</source>
<translation>TCP Ping</translation>
</message>
<message>
<location filename="../src/views/home/GroupItemPopMenu.qml" line="62"/>
<location filename="../src/views/home/GroupItemPopMenu.qml" line="74"/>
<source>Update</source>
<translation>更新</translation>
</message>
<message>
<location filename="../src/views/home/GroupItemPopMenu.qml" line="65"/>
<location filename="../src/views/home/GroupItemPopMenu.qml" line="77"/>
<source>[%1] Updating...</source>
<translation>[%1] 更新中...</translation>
</message>
<message>
<location filename="../src/views/home/GroupItemPopMenu.qml" line="65"/>
<location filename="../src/views/home/GroupItemPopMenu.qml" line="78"/>
<source>Updated: %1</source>
<translation>更新于: %1</translation>
</message>
<message>
<location filename="../src/views/home/GroupItemPopMenu.qml" line="70"/>
<location filename="../src/views/home/GroupItemPopMenu.qml" line="87"/>
<source>Delete</source>
<translation>删除</translation>
</message>
Expand Down Expand Up @@ -1225,18 +1225,29 @@
<context>
<name>across::GroupList</name>
<message>
<location filename="../src/view_models/grouplist.cpp" line="408"/>
<location filename="../src/view_models/grouplist.cpp" line="412"/>
<location filename="../src/view_models/grouplist.cpp" line="429"/>
<location filename="../src/view_models/grouplist.cpp" line="433"/>
<location filename="../src/view_models/grouplist.cpp" line="121"/>
<source>[%1] TCP Pinging...</source>
<translation>[%1] TCP Pinging...</translation>
</message>
<message>
<location filename="../src/view_models/grouplist.cpp" line="122"/>
<location filename="../src/view_models/grouplist.cpp" line="147"/>
<source>Testing: %1/%2</source>
<translation>測試中:%1/%2</translation>
</message>
<message>
<location filename="../src/view_models/grouplist.cpp" line="452"/>
<location filename="../src/view_models/grouplist.cpp" line="456"/>
<location filename="../src/view_models/grouplist.cpp" line="473"/>
<location filename="../src/view_models/grouplist.cpp" line="477"/>
<source>Copy [%1] URL to clipboard</source>
<translation>复制 [%1] 链接到剪贴板</translation>
</message>
</context>
<context>
<name>across::NodeFormModel</name>
<message>
<location filename="../src/view_models/nodeformmodel.cpp" line="472"/>
<location filename="../src/view_models/nodeformmodel.cpp" line="471"/>
<source>custom configuration encoding to url is not supported</source>
<translation>未支持自定义配置编码到链接格式</translation>
</message>
Expand Down Expand Up @@ -1295,22 +1306,22 @@
<context>
<name>across::setting::ConfigTools</name>
<message>
<location filename="../src/view_models/configtools.cpp" line="890"/>
<location filename="../src/view_models/configtools.cpp" line="892"/>
<source>Click the application or tray icon to show</source>
<translation>点击应用或托盘图标以显示</translation>
</message>
<message>
<location filename="../src/view_models/configtools.cpp" line="891"/>
<location filename="../src/view_models/configtools.cpp" line="893"/>
<source>Start From Minimize</source>
<translation>最小化启动</translation>
</message>
<message>
<location filename="../src/view_models/configtools.cpp" line="1068"/>
<location filename="../src/view_models/configtools.cpp" line="1070"/>
<source>Failed to parse version</source>
<translation>无法解析版本</translation>
</message>
<message>
<location filename="../src/view_models/configtools.cpp" line="1071"/>
<location filename="../src/view_models/configtools.cpp" line="1073"/>
<source>New Version: v%1</source>
<translation>新版本:v%1</translation>
</message>
Expand All @@ -1319,7 +1330,7 @@
<translation type="vanished">新版本:%1</translation>
</message>
<message>
<location filename="../src/view_models/configtools.cpp" line="1073"/>
<location filename="../src/view_models/configtools.cpp" line="1075"/>
<source>Already the latest version</source>
<translation>已经是最新版本</translation>
</message>
Expand Down
9 changes: 7 additions & 2 deletions src/app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ bool Application::initialize() {
p_nodes = QSharedPointer<NodeList>::create();
p_groups = QSharedPointer<GroupList>::create();
p_tray = QSharedPointer<SystemTray>::create();
p_notifications = QSharedPointer<NotificationModel>::create();
p_image_provider = new ImageProvider; // free by qml engine
p_config->init(p_curl);

Expand Down Expand Up @@ -93,6 +94,8 @@ void Application::setRootContext() {
p_groups.get());
m_engine.rootContext()->setContextProperty(QStringLiteral("acrossTray"),
p_tray.get());
m_engine.rootContext()->setContextProperty(QStringLiteral("acrossNotifications"),
p_notifications.get());
m_engine.rootContext()->setContextProperty(
QStringLiteral("fixedFont"),
QFontDatabase::systemFont(QFontDatabase::FixedFont));
Expand All @@ -109,10 +112,10 @@ void Application::setRootContext() {
p_tray->init(p_config, p_core, p_nodes);
#if !defined(Q_CC_MINGW) && !defined(Q_OS_MACOS)
p_nodes->init(p_config, p_core, p_db);
p_groups->init(p_config, p_db, p_nodes, p_curl);
p_groups->init(p_config, p_db, p_nodes, p_curl, p_notifications);
#else
p_nodes->init(p_config, p_core, p_db, p_tray->getTrayIcon());
p_groups->init(p_config, p_db, p_nodes, p_curl, p_tray->getTrayIcon());
p_groups->init(p_config, p_db, p_nodes, p_curl, p_notifications, p_tray->getTrayIcon());
#endif
}

Expand Down Expand Up @@ -143,6 +146,8 @@ void Application::registerModels() {
"NodeModel");
qmlRegisterType<across::NodeFormModel>(qml_model_name.c_str(), 1, 0,
"NodeFormModel");
qmlRegisterType<across::Notification>(qml_model_name.c_str(), 1, 0,
"Notification");
}

void Application::onMessageReceived(quint32 clientId, const QByteArray &msg) {
Expand Down
2 changes: 2 additions & 0 deletions src/app.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "view_models/configtools.h"
#include "view_models/grouplist.h"
#include "view_models/groupmodel.h"
#include "view_models/notificationmodel.h"
#include "view_models/imageprovider.h"
#include "view_models/logview.h"
#include "view_models/nodeformmodel.h"
Expand Down Expand Up @@ -73,6 +74,7 @@ class Application : public SingleApplication {
QSharedPointer<across::NodeList> p_nodes;
QSharedPointer<across::GroupList> p_groups;
QSharedPointer<across::SystemTray> p_tray;
QSharedPointer<across::NotificationModel> p_notifications;
across::ImageProvider *p_image_provider;

ACrossExitReason exitReason = EXIT_NORMAL;
Expand Down
10 changes: 6 additions & 4 deletions src/view_models/configtools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,8 @@ void ConfigTools::setInboundObject(v2ray::config::V2RayConfig &config) {
http->set_timeout(http_setting.timeout());
http->set_userlevel(http_setting.user_level());

if (const auto& auth_setting = http_setting.auth(); auth_setting.enable()) {
if (const auto &auth_setting = http_setting.auth();
auth_setting.enable()) {
auto auth = http->add_accounts();
auth->set_user(auth_setting.username());
auth->set_pass(auth_setting.password());
Expand All @@ -134,7 +135,8 @@ void ConfigTools::setInboundObject(v2ray::config::V2RayConfig &config) {
auto socks = inbound->mutable_settings()->mutable_socks();
socks->set_userlevel(socks5_setting.user_level());

if (const auto& auth_setting = socks5_setting.auth(); auth_setting.enable()) {
if (const auto &auth_setting = socks5_setting.auth();
auth_setting.enable()) {
auto auth = socks->add_accounts();
auth->set_user(auth_setting.username());
auth->set_pass(auth_setting.password());
Expand Down Expand Up @@ -306,7 +308,7 @@ void ConfigTools::freshInbound() {
emit httpPasswordChanged();
}

void ConfigTools::saveConfig(const QString& config_path) {
void ConfigTools::saveConfig(const QString &config_path) {
auto json_str = SerializeTools::MessageToJson(m_config);

if (!config_path.isEmpty()) {
Expand Down Expand Up @@ -822,7 +824,7 @@ void ConfigTools::setHttpPassword(const QString &val) {
emit configChanged();
}

bool ConfigTools::isFileExist(const QString& file_path) {
bool ConfigTools::isFileExist(const QString &file_path) {
return QFile(file_path).exists();
}

Expand Down
59 changes: 52 additions & 7 deletions src/view_models/grouplist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ void GroupList::init(QSharedPointer<across::setting::ConfigTools> config,
QSharedPointer<across::DBTools> db,
QSharedPointer<across::NodeList> nodes,
QSharedPointer<across::network::CURLTools> curl,
const QSharedPointer<QSystemTrayIcon>& tray) {
QSharedPointer<across::NotificationModel> notifications,
const QSharedPointer<QSystemTrayIcon> &tray ) {
if (auto app_logger = spdlog::get("app"); app_logger != nullptr) {
p_logger = app_logger->clone("groups");
} else {
Expand All @@ -26,6 +27,7 @@ void GroupList::init(QSharedPointer<across::setting::ConfigTools> config,
p_db = std::move(db);
p_curl = std::move(curl);
p_nodes = std::move(nodes);
p_notifications = std::move(notifications);

if (tray != nullptr) {
p_tray = tray;
Expand All @@ -37,6 +39,9 @@ void GroupList::init(QSharedPointer<across::setting::ConfigTools> config,
connect(p_curl.get(), &across::network::CURLTools::downloadFinished, this,
&GroupList::handleDownloaded);

connect(this, &GroupList::nodeLatencyChanged, this,
&GroupList::handleNodeLatencyChanged);

reloadItems();
checkAllUpdate();
}
Expand Down Expand Up @@ -98,18 +103,57 @@ void GroupList::checkUpdate(int index, bool force) {
} while (false);
}

Q_INVOKABLE void GroupList::testTcpPing(int index) {
Q_INVOKABLE int GroupList::testTcpPing(int index) {
if (index >= m_groups.size())
return;
return 1;

if (auto &group = m_groups[index]; group.items != 0) {
if (m_is_tcpPinging.contains(group.id)) {
return 1;
}
m_is_tcpPinging[group.id] = true;

auto nodes = p_db->listAllNodesFromGroupID(group.id);

m_tcpPinging_count[group.id] = 0;
m_group_size[group.id] = nodes.size();
m_tcpPinging_notifications[group.id] = p_notifications->append(
tr("[%1] TCP Pinging...").arg(group.name),
tr("Testing: %1/%2").arg("0").arg(QString::number(m_group_size[group.id])),
0.0,
m_group_size[group.id],
0.0
);

for (int i = 0; i < nodes.size(); ++i) {
auto &node = nodes[i];
p_nodes->testLatency(node, i);
p_nodes->testLatency(node, i, [this, node, i] {
emit nodeLatencyChanged(node.group_id, i, node);
});
}
}
return 0;
}
Q_INVOKABLE int GroupList::testTcpPingLeft(int index) {
auto &group = m_groups[index];
if (m_tcpPinging_count.contains(group.id)) {
return -m_tcpPinging_count[group.id];
}
return 0;
}
void GroupList::handleNodeLatencyChanged(qint64 group_id, int index,
const across::NodeInfo &node) {
m_tcpPinging_count[group_id]++;
m_tcpPinging_notifications[group_id]->setMessage(tr("Testing: %1/%2")
.arg(QString::number(m_tcpPinging_count[group_id]))
.arg(QString::number(m_group_size[group_id])));
m_tcpPinging_notifications[group_id]->setValue(m_tcpPinging_count[group_id]);
if (m_tcpPinging_count[group_id] >= m_group_size[group_id]) {
p_notifications->remove(m_tcpPinging_notifications[group_id]->getIndex());
m_tcpPinging_count.remove(group_id);
m_tcpPinging_notifications.remove(group_id);
m_is_tcpPinging.remove(group_id);
}
}

Q_INVOKABLE int GroupList::getIndexByID(int id) {
Expand Down Expand Up @@ -227,7 +271,7 @@ bool GroupList::insertSIP008(const GroupInfo &group_info,
auto url = SerializeTools::sip002Encode(meta).value();
auto outbound = meta.outbound;
auto shadowsocks = outbound.settings().shadowsocks();
const auto& server = shadowsocks.servers(0);
const auto &server = shadowsocks.servers(0);

std::string json_str;

Expand Down Expand Up @@ -438,8 +482,9 @@ void GroupList::copyNodesToClipboard(int index) {

void GroupList::handleDownloaded(const QVariant &content) {
auto task = content.value<DownloadTask>();
if (task.content.isEmpty()){
if(task.is_updated) m_is_updating.remove(task.id);
if (task.content.isEmpty()) {
if (task.is_updated)
m_is_updating.remove(task.id);
return;
}

Expand Down
Loading

0 comments on commit 6a25328

Please sign in to comment.