Skip to content

Commit

Permalink
misc change
Browse files Browse the repository at this point in the history
  • Loading branch information
arm64v8a committed Dec 12, 2024
1 parent 6e4c180 commit 399b171
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 18 deletions.
48 changes: 33 additions & 15 deletions db/ConfigBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,23 +29,41 @@ namespace NekoGui {
return tun_name;
}

void MergeJson(const QJsonObject &custom, QJsonObject &outbound) {
void MergeJson(QJsonObject &dst, const QJsonObject &src) {
// 合并
if (custom.isEmpty()) return;
for (const auto &key: custom.keys()) {
if (outbound.contains(key)) {
auto v = custom[key];
auto v_orig = outbound[key];
if (v.isObject() && v_orig.isObject()) { // isObject 则合并?
auto vo = v.toObject();
QJsonObject vo_orig = v_orig.toObject();
MergeJson(vo, vo_orig);
outbound[key] = vo_orig;
if (src.isEmpty()) return;
for (const auto &key: src.keys()) {
auto v_src = src[key];
if (dst.contains(key)) {
auto v_dst = dst[key];
if (v_src.isObject() && v_dst.isObject()) { // isObject 则合并?
auto v_src_obj = v_src.toObject();
auto v_dst_obj = v_dst.toObject();
MergeJson(v_dst_obj, v_src_obj);
dst[key] = v_dst_obj;
} else {
outbound[key] = v;
dst[key] = v_src;
}
} else if (v_src.isArray()) {
if (key.startsWith("+")) {
auto key2 = SubStrAfter(key, "+");
auto v_dst = dst[key2];
auto v_src_arr = v_src.toArray();
auto v_dst_arr = v_dst.toArray();
QJSONARRAY_ADD(v_src_arr, v_dst_arr)
dst[key2] = v_src_arr;
} else if (key.endsWith("+")) {
auto key2 = SubStrBefore(key, "+");
auto v_dst = dst[key2];
auto v_src_arr = v_src.toArray();
auto v_dst_arr = v_dst.toArray();
QJSONARRAY_ADD(v_dst_arr, v_src_arr)
dst[key2] = v_dst_arr;
} else {
dst[key] = v_src;
}
} else {
outbound[key] = custom[key];
dst[key] = v_src;
}
}
}
Expand All @@ -68,7 +86,7 @@ namespace NekoGui {
}

// apply custom config
MergeJson(QString2QJsonObject(ent->bean->custom_config), result->coreConfig);
MergeJson(result->coreConfig, QString2QJsonObject(ent->bean->custom_config));

return result;
}
Expand Down Expand Up @@ -342,7 +360,7 @@ namespace NekoGui {
}

// apply custom outbound settings
MergeJson(QString2QJsonObject(ent->bean->custom_outbound), outbound);
MergeJson(outbound, QString2QJsonObject(ent->bean->custom_outbound));

// Bypass Lookup for the first profile
auto serverAddress = ent->bean->serverAddress;
Expand Down
6 changes: 3 additions & 3 deletions ui/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi
ui->toolButton_server->setMenu(ui->menu_server);
ui->menubar->setVisible(false);
connect(ui->toolButton_document, &QToolButton::clicked, this, [=] { QDesktopServices::openUrl(QUrl("https://matsuridayo.github.io/")); });
connect(ui->toolButton_ads, &QToolButton::clicked, this, [=] { QDesktopServices::openUrl(QUrl("https://matsuricom.pages.dev/")); });
connect(ui->toolButton_ads, &QToolButton::clicked, this, [=] { QDesktopServices::openUrl(QUrl("https://neko-box.pages.dev/")); });
connect(ui->toolButton_update, &QToolButton::clicked, this, [=] { runOnNewThread([=] { CheckUpdate(); }); });
connect(ui->toolButton_url_test, &QToolButton::clicked, this, [=] { speedtest_current_group(1, true); });

Expand Down Expand Up @@ -1208,10 +1208,10 @@ void MainWindow::on_menu_export_config_triggered() {
if (ent->bean->DisplayCoreType() != software_core_name) return;

auto result = BuildConfig(ent, false, true);
QString config_core = QJsonObject2QString(result->coreConfig, true);
QString config_core = QJsonObject2QString(result->coreConfig, false);
QApplication::clipboard()->setText(config_core);

QMessageBox msg(QMessageBox::Information, tr("Config copied"), config_core);
QMessageBox msg(QMessageBox::Information, tr("Config copied"), tr("Config copied"));
msg.addButton("Copy core config", QMessageBox::YesRole);
msg.addButton("Copy test config", QMessageBox::NoRole);
msg.addButton(QMessageBox::Ok);
Expand Down
1 change: 1 addition & 0 deletions ui/mainwindow_grpc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ void MainWindow::speedtest_current_group(int mode, bool test_group) {
lock_return.lock();
lock_return.unlock();
speedtesting = false;
MW_show_log(QObject::tr("Speedtest finished."));
});
#endif
}
Expand Down

0 comments on commit 399b171

Please sign in to comment.