diff --git a/db/TrafficLooper.cpp b/db/TrafficLooper.cpp index 04b709f..0051739 100644 --- a/db/TrafficLooper.cpp +++ b/db/TrafficLooper.cpp @@ -1,7 +1,7 @@ #include "TrafficLooper.hpp" #include "rpc/gRPC.h" -#include "ui/mainwindow.h" +#include "ui/mainwindow_interface.h" #include diff --git a/fmt/AbstractBean.hpp b/fmt/AbstractBean.hpp index 6dbf60f..e40172f 100644 --- a/fmt/AbstractBean.hpp +++ b/fmt/AbstractBean.hpp @@ -59,7 +59,8 @@ namespace NekoRay::fmt { virtual QString InsecureHint() { return {}; }; + QString DisplayInsecureHint(); + }; - QString DisplayInsecureHint(const QSharedPointer &); } diff --git a/fmt/InsecureHint.cpp b/fmt/InsecureHint.cpp index 631c6e1..c072f3e 100644 --- a/fmt/InsecureHint.cpp +++ b/fmt/InsecureHint.cpp @@ -5,10 +5,10 @@ #include "SocksHttpBean.hpp" namespace NekoRay::fmt { - QString DisplayInsecureHint(const QSharedPointer &bean) { + QString AbstractBean::DisplayInsecureHint() { if (!dataStore->insecure_hint) return {}; - auto insecure_hint = bean->InsecureHint(); - auto stream = GetStreamSettings(bean.data()); + auto insecure_hint = InsecureHint(); + auto stream = GetStreamSettings(this); if (stream != nullptr) insecure_hint += "\n" + stream->InsecureHint(); return insecure_hint.trimmed(); } diff --git a/fmt/V2RayStreamSettings.hpp b/fmt/V2RayStreamSettings.hpp index 9deaca0..23e5e2c 100644 --- a/fmt/V2RayStreamSettings.hpp +++ b/fmt/V2RayStreamSettings.hpp @@ -6,8 +6,8 @@ namespace NekoRay::fmt { class V2rayStreamSettings : public JsonStore { public: QString network = "tcp"; - QString security = "none"; - QString packet_encoding = ""; // sing-box only vmess + QString security = ""; + QString packet_encoding = ""; // ws/h2/grpc/tcp-http QString path = ""; QString host = ""; diff --git a/main/GuiUtils.hpp b/main/GuiUtils.hpp index 166aea4..f860625 100644 --- a/main/GuiUtils.hpp +++ b/main/GuiUtils.hpp @@ -1,12 +1,9 @@ #pragma once -#include #include // Dialogs -inline QWidget *mainwindow; - #define Dialog_DialogBasicSettings "DialogBasicSettings" #define Dialog_DialogEditProfile "DialogEditProfile" #define Dialog_DialogManageGroups "DialogManageGroups" @@ -14,37 +11,6 @@ inline QWidget *mainwindow; // Utils -inline QList -CreateActions(QWidget *parent, const QList &texts, const std::function &slot) { - QList acts; - - for (const auto &text: texts) { - acts.push_back(new QAction(text, parent)); //按顺序来 - } - - for (int i = 0; i < acts.size(); i++) { - if (acts[i]->text() == "[Separator]") { - acts[i]->setSeparator(true); - acts[i]->setText(""); - acts[i]->setDisabled(true); - acts[i]->setData(-1); - } else { - acts[i]->setData(i); - QObject::connect(acts[i], &QAction::triggered, parent, [=] { - slot(acts[i]); - }); - } - } - - return acts; -} - -inline QMenu *CreateMenu(QWidget *parent, const QList &texts, const std::function &slot) { - auto menu = new QMenu(parent); - menu->addActions(CreateActions(parent, texts, slot)); - return menu; -} - #define QRegExpValidator_Number new QRegularExpressionValidator(QRegularExpression("^[0-9]+$") // NekoRay Save&Load diff --git a/main/NekoRay.cpp b/main/NekoRay.cpp index 22980f9..ec783f5 100644 --- a/main/NekoRay.cpp +++ b/main/NekoRay.cpp @@ -170,7 +170,10 @@ namespace NekoRay { auto item = _item.get(); switch (item->type) { case itemType::string: - object.insert(item->name, *(QString *) item->ptr); + // Allow Empty + if (!((QString *) item->ptr)->isEmpty()) { + object.insert(item->name, *(QString *) item->ptr); + } break; case itemType::integer: object.insert(item->name, *(int *) item->ptr); diff --git a/main/NekoRay_Utils.cpp b/main/NekoRay_Utils.cpp index 05ec689..0fe9d7a 100644 --- a/main/NekoRay_Utils.cpp +++ b/main/NekoRay_Utils.cpp @@ -1,7 +1,6 @@ #include "NekoRay_Utils.hpp" #include "3rdparty/QThreadCreateThread.hpp" -#include "main/GuiUtils.hpp" #include @@ -25,7 +24,7 @@ QString GetRandomString(int randomStringLength) { const QString possibleCharacters("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"); - std::uniform_int_distribution dist(0, possibleCharacters.count() - 1); + std::uniform_int_distribution dist(0, possibleCharacters.length() - 1); QString randomString; for (int i = 0; i < randomStringLength; ++i) { diff --git a/main/NekoRay_Utils.hpp b/main/NekoRay_Utils.hpp index 0ecada8..e34d25b 100644 --- a/main/NekoRay_Utils.hpp +++ b/main/NekoRay_Utils.hpp @@ -10,14 +10,17 @@ inline QString software_name = "NekoRay"; inline QString software_core_name = "V2Ray"; -inline std::function release_runguard; +// Main Functions -// Dialogs +inline std::function MF_release_runguard; -inline std::function showLog; -inline std::function showLog_ext; -inline std::function showLog_ext_vt100; -inline std::function dialog_message; +// MainWindow functions + +inline QWidget *mainwindow; +inline std::function MW_show_log; +inline std::function MW_show_log_ext; +inline std::function MW_show_log_ext_vt100; +inline std::function MW_dialog_message; // Utils diff --git a/main/main.cpp b/main/main.cpp index baac9e2..30d1d4c 100644 --- a/main/main.cpp +++ b/main/main.cpp @@ -74,7 +74,7 @@ int main(int argc, char *argv[]) { return 0; } } - release_runguard = [&] { guard.release(); }; + MF_release_runguard = [&] { guard.release(); }; // icons QIcon::setFallbackSearchPaths(QStringList{ diff --git a/rpc/gRPC.cpp b/rpc/gRPC.cpp index f0a655b..fd60c39 100644 --- a/rpc/gRPC.cpp +++ b/rpc/gRPC.cpp @@ -75,7 +75,7 @@ namespace QtGrpc { QStringList errstr; errstr << "grpc-status error code:" << Int2String(errCode) << ", error msg:" << QLatin1String(networkReply->rawHeader(GrpcStatusMessage)); - showLog(errstr.join(" ")); + MW_show_log(errstr.join(" ")); statusCode = QNetworkReply::NetworkError::ProtocolUnknownError; return {}; } diff --git a/sub/GroupUpdater.cpp b/sub/GroupUpdater.cpp index b73540c..02a7b17 100644 --- a/sub/GroupUpdater.cpp +++ b/sub/GroupUpdater.cpp @@ -57,7 +57,7 @@ namespace NekoRay::sub { auto j = DecodeB64IfValid(link.fragment().toUtf8(), QByteArray::Base64UrlEncoding); if (j.isEmpty()) return; ent->bean->FromJsonBytes(j.toUtf8()); - showLog("nekoray format: " + ent->bean->DisplayTypeAndName()); + MW_show_log("nekoray format: " + ent->bean->DisplayTypeAndName()); } // SOCKS @@ -138,6 +138,8 @@ namespace NekoRay::sub { bean->config_simple = QJsonObject2QString(result, false); } + if (ent == nullptr) return; + // Fix auto stream = fmt::GetStreamSettings(ent->bean.get()); if (needFix && stream != nullptr) { @@ -155,7 +157,6 @@ namespace NekoRay::sub { } // End - if (ent == nullptr) return; profileManager->AddProfile(ent, gid_add_to); update_counter++; } @@ -351,11 +352,11 @@ namespace NekoRay::sub { // 网络请求 if (asURL) { auto groupName = group == nullptr ? content : group->name; - showLog(">>>>>>>> " + QObject::tr("Requesting subscription: %1").arg(groupName)); + MW_show_log(">>>>>>>> " + QObject::tr("Requesting subscription: %1").arg(groupName)); auto resp = NetworkRequestHelper::HttpGet(content); if (!resp.error.isEmpty()) { - showLog("<<<<<<<< " + QObject::tr("Requesting subscription %1 error: %2") + MW_show_log("<<<<<<<< " + QObject::tr("Requesting subscription %1 error: %2") .arg(groupName, resp.error + "\n" + resp.data)); return; } @@ -380,7 +381,7 @@ namespace NekoRay::sub { group->Save(); // if (dataStore->sub_clear) { - showLog(QObject::tr("Clearing servers...")); + MW_show_log(QObject::tr("Clearing servers...")); for (const auto &profile: in) { profileManager->DeleteProfile(profile->id); } @@ -413,19 +414,15 @@ namespace NekoRay::sub { notice_deleted += ent->bean->DisplayTypeAndName() + "\n"; } - runOnUiThread([=] { - auto change = "\n" + QObject::tr("Added %1 profiles:\n%2\nDeleted %3 Profiles:\n%4") - .arg(only_out.length()).arg(notice_added) - .arg(only_in.length()).arg(notice_deleted); - if (only_out.length() + only_in.length() == 0) change = QObject::tr("Nothing"); - showLog("<<<<<<<< " + QObject::tr("Change of %1:").arg(group->name) + " " + change); - dialog_message("SubUpdater", "finish-dingyue"); - }); + auto change = "\n" + QObject::tr("Added %1 profiles:\n%2\nDeleted %3 Profiles:\n%4") + .arg(only_out.length()).arg(notice_added) + .arg(only_in.length()).arg(notice_deleted); + if (only_out.length() + only_in.length() == 0) change = QObject::tr("Nothing"); + MW_show_log("<<<<<<<< " + QObject::tr("Change of %1:").arg(group->name) + " " + change); + MW_dialog_message("SubUpdater", "finish-dingyue"); } else { NekoRay::dataStore->imported_count = rawUpdater->update_counter; - runOnUiThread([=] { - dialog_message("SubUpdater", "finish"); - }); + MW_dialog_message("SubUpdater", "finish"); } } } diff --git a/sys/ExternalProcess.cpp b/sys/ExternalProcess.cpp index fff8baf..a365ce3 100644 --- a/sys/ExternalProcess.cpp +++ b/sys/ExternalProcess.cpp @@ -14,10 +14,10 @@ namespace NekoRay::sys { if (show_log) { connect(this, &QProcess::readyReadStandardOutput, this, [&]() { - showLog_ext_vt100(readAllStandardOutput().trimmed()); + MW_show_log_ext_vt100(readAllStandardOutput().trimmed()); }); connect(this, &QProcess::readyReadStandardError, this, [&]() { - showLog_ext_vt100(readAllStandardError().trimmed()); + MW_show_log_ext_vt100(readAllStandardError().trimmed()); }); } @@ -25,23 +25,23 @@ namespace NekoRay::sys { connect(this, &QProcess::errorOccurred, this, [&](QProcess::ProcessError error) { if (!killed) { crashed = true; - showLog_ext(tag, "errorOccurred:" + errorString()); - dialog_message("ExternalProcess", "Crashed"); + MW_show_log_ext(tag, "errorOccurred:" + errorString()); + MW_dialog_message("ExternalProcess", "Crashed"); } }); connect(this, &QProcess::stateChanged, this, [&](QProcess::ProcessState state) { if (state == QProcess::NotRunning) { if (killed) { // 用户命令退出 - showLog_ext(tag, "Stopped"); + MW_show_log_ext(tag, "Stopped"); } else if (!crashed) { // 异常退出 crashed = true; - showLog_ext(tag, "[Error] Program exited accidentally: " + errorString()); + MW_show_log_ext(tag, "[Error] Program exited accidentally: " + errorString()); Kill(); - dialog_message("ExternalProcess", "Crashed"); + MW_dialog_message("ExternalProcess", "Crashed"); } } }); - showLog_ext(tag, "[Starting] " + env.join(" ") + " " + program + " " + arguments.join(" ")); + MW_show_log_ext(tag, "[Starting] " + env.join(" ") + " " + program + " " + arguments.join(" ")); } QProcess::setEnvironment(env); @@ -66,12 +66,12 @@ namespace NekoRay::sys { ExternalProcess::arguments = args; connect(this, &QProcess::readyReadStandardOutput, this, [&]() { - showLog(readAllStandardOutput().trimmed()); + MW_show_log(readAllStandardOutput().trimmed()); }); connect(this, &QProcess::readyReadStandardError, this, [&]() { auto log = readAllStandardError().trimmed(); if (show_stderr) { - showLog(log); + MW_show_log(log); return; } if (log.contains("token is set")) { @@ -81,7 +81,7 @@ namespace NekoRay::sys { connect(this, &QProcess::errorOccurred, this, [&](QProcess::ProcessError error) { if (error == QProcess::ProcessError::FailedToStart) { failed_to_start = true; - showLog("start core error occurred: " + errorString() + "\n"); + MW_show_log("start core error occurred: " + errorString() + "\n"); } }); connect(this, &QProcess::stateChanged, this, [&](QProcess::ProcessState state) { @@ -91,8 +91,8 @@ namespace NekoRay::sys { if (failed_to_start) return; // no retry restart_id = NekoRay::dataStore->started_id; - dialog_message("ExternalProcess", "Crashed"); - showLog("[Error] core exited, restarting.\n"); + MW_dialog_message("ExternalProcess", "Crashed"); + MW_show_log("[Error] core exited, restarting.\n"); // Restart setTimeout([=] { @@ -103,7 +103,7 @@ namespace NekoRay::sys { } else if (state == QProcess::Running && restart_id >= 0) { // Restart profile setTimeout([=] { - dialog_message("ExternalProcess", "CoreRestarted," + Int2String(restart_id)); + MW_dialog_message("ExternalProcess", "CoreRestarted," + Int2String(restart_id)); restart_id = -1; }, this, 1000); } diff --git a/translations/zh_CN.ts b/translations/zh_CN.ts index 9e5b438..e9860a8 100644 --- a/translations/zh_CN.ts +++ b/translations/zh_CN.ts @@ -1146,7 +1146,7 @@ End: %2 克隆 - Update subscripton + Update subscription 更新订阅 @@ -1158,8 +1158,8 @@ End: %2 批量复制选中项目的分享链接 (Nekoray) - Allow connections from the LAN - 允许来自局域网的连接 + Allow other devices to connect + 允许其他设备连接 Manual addition of profiles is not allowed in subscription groupings. @@ -1189,6 +1189,10 @@ End: %2 Restart Program 重启程序 + + Not Running + 未启动 + ProxyItem diff --git a/ui/dialog_basic_settings.cpp b/ui/dialog_basic_settings.cpp index d5c3817..af672f9 100644 --- a/ui/dialog_basic_settings.cpp +++ b/ui/dialog_basic_settings.cpp @@ -220,7 +220,7 @@ DialogBasicSettings::DialogBasicSettings(QWidget *parent) file.open(QIODevice::ReadWrite | QIODevice::Truncate); file.write(Int2String(neko_core_new).toUtf8()); file.close(); - dialog_message("", "RestartProgram"); + MW_dialog_message("", "RestartProgram"); } }; connect(ui->switch_core_v2ray, &QRadioButton::clicked, this, switch_core_on_click); @@ -281,7 +281,7 @@ void DialogBasicSettings::accept() { D_SAVE_BOOL(insecure_hint) D_SAVE_BOOL(skip_cert) - dialog_message(Dialog_DialogBasicSettings, "UpdateDataStore"); + MW_dialog_message(Dialog_DialogBasicSettings, "UpdateDataStore"); QDialog::accept(); } @@ -304,5 +304,5 @@ void DialogBasicSettings::on_set_custom_icon_clicked() { } else { return; } - dialog_message(Dialog_DialogBasicSettings, "UpdateIcon"); + MW_dialog_message(Dialog_DialogBasicSettings, "UpdateIcon"); } diff --git a/ui/dialog_hotkey.cpp b/ui/dialog_hotkey.cpp index ea3e31e..33ac3cd 100644 --- a/ui/dialog_hotkey.cpp +++ b/ui/dialog_hotkey.cpp @@ -1,7 +1,7 @@ #include "dialog_hotkey.h" #include "ui_dialog_hotkey.h" -#include "ui/mainwindow.h" +#include "ui/mainwindow_interface.h" DialogHotkey::DialogHotkey(QWidget *parent) : QDialog(parent), ui(new Ui::DialogHotkey) { diff --git a/ui/dialog_manage_groups.cpp b/ui/dialog_manage_groups.cpp index 70ad30d..a6e8b1a 100644 --- a/ui/dialog_manage_groups.cpp +++ b/ui/dialog_manage_groups.cpp @@ -48,7 +48,7 @@ void DialogManageGroups::on_add_clicked() { if (ret == QDialog::Accepted) { NekoRay::profileManager->AddGroup(ent); AddGroupToListIfExist(ent->id) - dialog_message(Dialog_DialogManageGroups, "refresh-1"); + MW_dialog_message(Dialog_DialogManageGroups, "refresh-1"); } } diff --git a/ui/dialog_manage_routes.cpp b/ui/dialog_manage_routes.cpp index 5657f80..8530fdd 100644 --- a/ui/dialog_manage_routes.cpp +++ b/ui/dialog_manage_routes.cpp @@ -67,7 +67,6 @@ DialogManageRoutes::DialogManageRoutes(QWidget *parent) : blockDomainTxt = new AutoCompleteTextEdit("geosite", sourceStringsDomain, this); // const auto sourceStringsIP = Qv2ray::components::GeositeReader::ReadGeoSiteFromFile(geositeFn); - qDebug() << sourceStringsIP; directIPTxt = new AutoCompleteTextEdit("geoip", sourceStringsIP, this); proxyIPTxt = new AutoCompleteTextEdit("geoip", sourceStringsIP, this); blockIPTxt = new AutoCompleteTextEdit("geoip", sourceStringsIP, this); @@ -106,7 +105,7 @@ void DialogManageRoutes::accept() { // QString info = "UpdateDataStore"; if (routeChanged) info += "RouteChanged"; - dialog_message(Dialog_DialogManageRoutes, info); + MW_dialog_message(Dialog_DialogManageRoutes, info); QDialog::accept(); } diff --git a/ui/dialog_vpn_settings.cpp b/ui/dialog_vpn_settings.cpp index 1f95eef..62697f9 100644 --- a/ui/dialog_vpn_settings.cpp +++ b/ui/dialog_vpn_settings.cpp @@ -40,6 +40,6 @@ void DialogVPNSettings::accept() { D_SAVE_STRING_QTEXTEDIT(vpn_bypass_cidr) D_SAVE_STRING_QTEXTEDIT(vpn_bypass_process) // - dialog_message("", "UpdateDataStore,VPNChanged"); + MW_dialog_message("", "UpdateDataStore,VPNChanged"); QDialog::accept(); } diff --git a/ui/edit/dialog_edit_profile.cpp b/ui/edit/dialog_edit_profile.cpp index 04a9dae..f77b807 100644 --- a/ui/edit/dialog_edit_profile.cpp +++ b/ui/edit/dialog_edit_profile.cpp @@ -329,7 +329,7 @@ void DialogEditProfile::accept() { ent->Save(); } - dialog_message(Dialog_DialogEditProfile, "accept"); + MW_dialog_message(Dialog_DialogEditProfile, "accept"); QDialog::accept(); } diff --git a/ui/edit/edit_chain.cpp b/ui/edit/edit_chain.cpp index 04c93cc..1a83e15 100644 --- a/ui/edit/edit_chain.cpp +++ b/ui/edit/edit_chain.cpp @@ -1,7 +1,7 @@ #include "edit_chain.h" #include "ui_edit_chain.h" -#include "ui/mainwindow.h" +#include "ui/mainwindow_interface.h" #include "ui/widget/ProxyItem.h" #include "db/Database.hpp" diff --git a/ui/mainwindow.cpp b/ui/mainwindow.cpp index 5acf8f7..b97ee60 100644 --- a/ui/mainwindow.cpp +++ b/ui/mainwindow.cpp @@ -54,7 +54,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { mainwindow = this; - dialog_message = [=](const QString &a, const QString &b) { + MW_dialog_message = [=](const QString &a, const QString &b) { runOnUiThread([=] { dialog_message_impl(a, b); }); @@ -137,17 +137,17 @@ MainWindow::MainWindow(QWidget *parent) auto bar = ui->masterLogBrowser->verticalScrollBar(); bar->setValue(bar->maximum()); }); - showLog = [=](const QString &log) { + MW_show_log = [=](const QString &log) { runOnUiThread([=] { show_log_impl(log); }); }; - showLog_ext = [=](const QString &tag, const QString &log) { + MW_show_log_ext = [=](const QString &tag, const QString &log) { runOnUiThread([=] { show_log_impl("[" + tag + "] " + log); }); }; - showLog_ext_vt100 = [=](const QString &log) { + MW_show_log_ext_vt100 = [=](const QString &log) { runOnUiThread([=] { show_log_impl(cleanVT100String(log)); }); @@ -257,7 +257,7 @@ MainWindow::MainWindow(QWidget *parent) // ui->menu_program_preference->addActions(ui->menu_preferences->actions()); connect(ui->menu_add_from_clipboard2, &QAction::triggered, ui->menu_add_from_clipboard, &QAction::trigger); - connect(ui->actionRestart_Program, &QAction::triggered, this, [=] { dialog_message("", "RestartProgram"); }); + connect(ui->actionRestart_Program, &QAction::triggered, this, [=] { MW_dialog_message("", "RestartProgram"); }); // connect(ui->menu_program, &QMenu::aboutToShow, this, [=]() { ui->actionRemember_last_proxy->setChecked(NekoRay::dataStore->remember_enable); @@ -328,7 +328,7 @@ MainWindow::MainWindow(QWidget *parent) }); connect(ui->actionAllow_LAN, &QAction::triggered, this, [=](bool checked) { NekoRay::dataStore->inbound_address = checked ? "::" : "127.0.0.1"; - dialog_message("", "UpdateDataStore"); + MW_dialog_message("", "UpdateDataStore"); }); // connect(ui->checkBox_VPN, &QCheckBox::clicked, this, [=](bool checked) { @@ -491,7 +491,7 @@ void MainWindow::dialog_message_impl(const QString &sender, const QString &info) // 订阅完毕 refresh_proxy_list(); if (!info.contains("dingyue")) { - showLog(tr("Imported %1 profile(s)").arg(NekoRay::dataStore->imported_count)); + show_log_impl(tr("Imported %1 profile(s)").arg(NekoRay::dataStore->imported_count)); } } else if (sender == "ExternalProcess") { if (info == "Crashed") { @@ -563,7 +563,7 @@ void MainWindow::on_menu_exit_triggered() { hide(); ExitNekorayCore(); // - release_runguard(); + MF_release_runguard(); if (exit_reason == 1) { QDir::setCurrent(QApplication::applicationDirPath()); QProcess::startDetached("./updater", QStringList{}); @@ -640,9 +640,9 @@ void MainWindow::refresh_status(const QString &traffic_update) { // From UI if (last_test_time.addSecs(2) < QTime::currentTime()) { - ui->label_running->setText(tr("Running: %1").arg(running.isNull() - ? tr("None") - : running->bean->DisplayName().left(50))); + auto txt = running == nullptr ? tr("Not Running") + : tr("Running: %1").arg(running->bean->DisplayName().left(50)); + ui->label_running->setText(txt); } // auto display_http = tr("None"); @@ -737,6 +737,9 @@ void MainWindow::refresh_groups() { NekoRay::dataStore->refreshing_group_list = false; } +void MainWindow::refresh_proxy_list(const int &id) { + refresh_proxy_list_impl(id, {}); +} void MainWindow::refresh_proxy_list_impl(const int &id, NekoRay::GroupSortAction groupSortAction) { if (id < 0) { @@ -761,9 +764,6 @@ void MainWindow::refresh_proxy_list_impl(const int &id, NekoRay::GroupSortAction } auto f0 = std::make_unique(); -// auto font = f0->font(); -// font.setPointSize(9); -// f0->setFont(font); f0->setData(114514, profile->id); // C0: is Running @@ -779,7 +779,7 @@ void MainWindow::refresh_proxy_list_impl(const int &id, NekoRay::GroupSortAction // C1: Type f = f0->clone(); f->setText(profile->bean->DisplayType()); - auto insecure_hint = DisplayInsecureHint(profile->bean); + auto insecure_hint = profile->bean->DisplayInsecureHint(); if (!insecure_hint.isEmpty()) { f->setBackground(Qt::red); f->setToolTip(insecure_hint); @@ -1006,7 +1006,7 @@ void MainWindow::on_menu_copy_links_triggered() { } if (links.length() == 0) return; QApplication::clipboard()->setText(links.join("\n")); - showLog(tr("Copied %1 item(s)").arg(links.length())); + show_log_impl(tr("Copied %1 item(s)").arg(links.length())); } void MainWindow::on_menu_copy_links_nkr_triggered() { @@ -1017,7 +1017,7 @@ void MainWindow::on_menu_copy_links_nkr_triggered() { } if (links.length() == 0) return; QApplication::clipboard()->setText(links.join("\n")); - showLog(tr("Copied %1 item(s)").arg(links.length())); + show_log_impl(tr("Copied %1 item(s)").arg(links.length())); } void MainWindow::on_menu_export_config_triggered() { @@ -1175,7 +1175,7 @@ void MainWindow::on_menu_delete_repeat_triggered() { bool mw_sub_updating = false; -void MainWindow::on_menu_update_subscripton_triggered() { +void MainWindow::on_menu_update_subscription_triggered() { auto group = NekoRay::profileManager->CurrentGroup(); if (group->url.isEmpty()) return; if (mw_sub_updating) return; diff --git a/ui/mainwindow.h b/ui/mainwindow.h index 3a23092..de03c23 100644 --- a/ui/mainwindow.h +++ b/ui/mainwindow.h @@ -1,6 +1,11 @@ #pragma once #include + +#include "main/NekoRay.hpp" + +#ifndef MW_INTERFACE + #include #include #include @@ -11,9 +16,10 @@ #include "GroupSort.hpp" #include "db/ProxyEntity.hpp" -#include "db/Group.hpp" #include "main/GuiUtils.hpp" +#endif + namespace NekoRay::sys { class CoreProcess; } QT_BEGIN_NAMESPACE @@ -26,11 +32,11 @@ class MainWindow : public QMainWindow { Q_OBJECT public: - MainWindow(QWidget *parent = nullptr); + explicit MainWindow(QWidget *parent = nullptr); - ~MainWindow(); + ~MainWindow() override; - void refresh_proxy_list(const int &id = -1) { refresh_proxy_list_impl(id, {}); }; + void refresh_proxy_list(const int &id = -1); void show_group(int gid); @@ -62,6 +68,8 @@ public slots: void on_menu_exit_triggered(); +#ifndef MW_INTERFACE + private slots: void on_masterLogBrowser_customContextMenuRequested(const QPoint &pos); @@ -108,7 +116,7 @@ private slots: void on_menu_remove_unavailable_triggered(); - void on_menu_update_subscripton_triggered(); + void on_menu_update_subscription_triggered(); void on_menu_resolve_domain_triggered(); @@ -174,6 +182,8 @@ private: protected: bool eventFilter(QObject *obj, QEvent *event) override; + +#endif // MW_INTERFACE }; inline MainWindow *GetMainWindow() { diff --git a/ui/mainwindow.ui b/ui/mainwindow.ui index 8a697dd..8591673 100644 --- a/ui/mainwindow.ui +++ b/ui/mainwindow.ui @@ -540,7 +540,7 @@ - + @@ -745,7 +745,7 @@ true - Allow connections from the LAN + Allow other devices to connect @@ -822,9 +822,9 @@ Ctrl+D - + - Update subscripton + Update subscription Ctrl+U diff --git a/ui/mainwindow_grpc.cpp b/ui/mainwindow_grpc.cpp index 0804b53..1497804 100644 --- a/ui/mainwindow_grpc.cpp +++ b/ui/mainwindow_grpc.cpp @@ -21,7 +21,7 @@ void MainWindow::setup_grpc() { #ifndef NKR_NO_GRPC // Setup Connection defaultClient = new Client([=](const QString &errStr) { - showLog("[Error] gRPC: " + errStr); + MW_show_log("[Error] gRPC: " + errStr); }, "127.0.0.1:" + Int2String(NekoRay::dataStore->core_port), NekoRay::dataStore->core_token); auto t = new QTimer(); connect(t, &QTimer::timeout, this, [=]() { @@ -228,7 +228,7 @@ void MainWindow::neko_start(int _id) { if (NekoRay::dataStore->started_id >= 0) neko_stop(); show_log_impl(">>>>>>>> " + tr("Starting profile %1").arg(ent->bean->DisplayTypeAndName())); - auto insecure_hint = DisplayInsecureHint(ent->bean); + auto insecure_hint = ent->bean->DisplayInsecureHint(); if (!insecure_hint.isEmpty()) show_log_impl(">>>>>>>> " + tr("Profile is insecure: %1").arg(insecure_hint)); #ifndef NKR_NO_GRPC diff --git a/ui/mainwindow_interface.h b/ui/mainwindow_interface.h new file mode 100644 index 0000000..27157de --- /dev/null +++ b/ui/mainwindow_interface.h @@ -0,0 +1,5 @@ +#pragma once + +#define MW_INTERFACE + +#include "mainwindow.h" diff --git a/ui/widget/GroupItem.cpp b/ui/widget/GroupItem.cpp index e7670b2..ab50893 100644 --- a/ui/widget/GroupItem.cpp +++ b/ui/widget/GroupItem.cpp @@ -109,7 +109,7 @@ void GroupItem::on_edit_clicked() { if (ret == QDialog::Accepted) { ent->Save(); refresh_data(); - dialog_message(Dialog_DialogManageGroups, "refresh" + Int2String(ent->id)); + MW_dialog_message(Dialog_DialogManageGroups, "refresh" + Int2String(ent->id)); } } @@ -118,7 +118,7 @@ void GroupItem::on_remove_clicked() { if (QMessageBox::question(this, tr("Confirmation"), tr("Remove %1?").arg(ent->name)) == QMessageBox::StandardButton::Yes) { NekoRay::profileManager->DeleteGroup(ent->id); - dialog_message(Dialog_DialogManageGroups, "refresh-1"); + MW_dialog_message(Dialog_DialogManageGroups, "refresh-1"); delete item; } }