diff --git a/main/NekoRay_Utils.cpp b/main/NekoRay_Utils.cpp index 841ea08..9d74437 100644 --- a/main/NekoRay_Utils.cpp +++ b/main/NekoRay_Utils.cpp @@ -77,12 +77,18 @@ bool IsIpAddressV6(const QString &str) { return false; } +QWidget *GetMessageBoxParent() { + if (mainwindow == nullptr) return nullptr; + if (mainwindow->isVisible()) return mainwindow; + return nullptr; +} + int MessageBoxWarning(const QString &title, const QString &text) { - return QMessageBox::warning(nullptr, title, text); + return QMessageBox::warning(GetMessageBoxParent(), title, text); } int MessageBoxInfo(const QString &title, const QString &text) { - return QMessageBox::information(nullptr, title, text); + return QMessageBox::information(GetMessageBoxParent(), title, text); } void runOnUiThread(const std::function &callback, QObject *parent) { diff --git a/main/NekoRay_Utils.hpp b/main/NekoRay_Utils.hpp index 72c139c..bc35418 100644 --- a/main/NekoRay_Utils.hpp +++ b/main/NekoRay_Utils.hpp @@ -159,6 +159,8 @@ inline QString ReadableSize(const qint64 &size) { // UI +QWidget *GetMessageBoxParent(); + int MessageBoxWarning(const QString &title, const QString &text); int MessageBoxInfo(const QString &title, const QString &text); diff --git a/translations/zh_CN.ts b/translations/zh_CN.ts index 07bcd0f..6e3a56d 100644 --- a/translations/zh_CN.ts +++ b/translations/zh_CN.ts @@ -151,6 +151,10 @@ Connection statistics 连接统计 + + Minimize to tray icon on startup + 启动时最小化到托盘图标 + DialogEditGroup @@ -941,10 +945,6 @@ End: %2 Remember last profile 记住最后的配置 - - Start minimal - 最小化启动 - Move %1 item(s) 移动 %1 个项目 @@ -1081,6 +1081,14 @@ End: %2 Copy links of selected (Nekoray) 批量复制选中项目的分享链接 (Nekoray) + + Allow connections from the LAN + 允许来自局域网的连接 + + + Manual addition of profiles is not allowed in subscription groupings. + 订阅分组中不允许手动添加配置。 + ProxyItem diff --git a/ui/dialog_basic_settings.cpp b/ui/dialog_basic_settings.cpp index 2f44068..10cc672 100644 --- a/ui/dialog_basic_settings.cpp +++ b/ui/dialog_basic_settings.cpp @@ -83,6 +83,7 @@ DialogBasicSettings::DialogBasicSettings(QWidget *parent) connect(ui->language, QOverload::of(&QComboBox::currentIndexChanged), this, [=](int index) { CACHE.needRestart = true; }); + ui->start_minimal->setChecked(NekoRay::dataStore->start_minimal); int built_in_len = ui->theme->count(); ui->theme->addItems(QStyleFactory::keys()); @@ -200,6 +201,7 @@ void DialogBasicSettings::accept() { // Style NekoRay::dataStore->language = ui->language->currentIndex(); + NekoRay::dataStore->start_minimal = ui->start_minimal->isChecked(); // Subscription diff --git a/ui/dialog_basic_settings.ui b/ui/dialog_basic_settings.ui index 660d015..25ee2f6 100644 --- a/ui/dialog_basic_settings.ui +++ b/ui/dialog_basic_settings.ui @@ -384,6 +384,13 @@ + + + + Minimize to tray icon on startup + + + diff --git a/ui/mainwindow.cpp b/ui/mainwindow.cpp index 2e7af3d..3563ef9 100644 --- a/ui/mainwindow.cpp +++ b/ui/mainwindow.cpp @@ -262,7 +262,7 @@ MainWindow::MainWindow(QWidget *parent) connect(ui->menu_program, &QMenu::aboutToShow, this, [=]() { ui->actionRemember_last_proxy->setChecked(NekoRay::dataStore->remember_enable); ui->actionStart_with_system->setChecked(GetProcessAutoRunSelf()); - ui->actionStart_minimal->setChecked(NekoRay::dataStore->start_minimal); + ui->actionAllow_LAN->setChecked(NekoRay::dataStore->inbound_address == "0.0.0.0"); // active server for (const auto &old: ui->menuActive_Server->actions()) { ui->menuActive_Server->removeAction(old); @@ -304,7 +304,7 @@ MainWindow::MainWindow(QWidget *parent) r.load_control_force = true; r.fn = "routes/" + fn; if (r.Load()) { - auto btn = QMessageBox::question(nullptr, "NekoRay", + auto btn = QMessageBox::question(GetMessageBoxParent(), "NekoRay", tr("Load routing and apply: %1").arg(fn) + "\n" + r.toString()); if (btn == QMessageBox::Yes) { NekoRay::Routing::SetToActive(fn); @@ -324,9 +324,9 @@ MainWindow::MainWindow(QWidget *parent) connect(ui->actionStart_with_system, &QAction::triggered, this, [=](bool checked) { SetProcessAutoRunSelf(checked); }); - connect(ui->actionStart_minimal, &QAction::triggered, this, [=](bool checked) { - NekoRay::dataStore->start_minimal = checked; - NekoRay::dataStore->Save(); + connect(ui->actionAllow_LAN, &QAction::triggered, this, [=](bool checked) { + NekoRay::dataStore->inbound_address = checked ? "0.0.0.0" : "127.0.0.1"; + dialog_message(Dialog_DialogManageRoutes, "UpdateDataStore,RouteChanged"); }); // connect(ui->checkBox_VPN, &QCheckBox::clicked, this, [=](bool checked) { @@ -489,8 +489,8 @@ void MainWindow::dialog_message_impl(const QString &sender, const QString &info) if (info.contains("VPNChanged") && title_spmode == NekoRay::SystemProxyMode::VPN) { MessageBoxWarning(tr("VPN settings changed"), tr("Restart VPN to take effect.")); } else if (changed && NekoRay::dataStore->started_id >= 0 && - QMessageBox::question(this, tr("Confirmation"), tr("Settings changed, restart proxy?") - ) == QMessageBox::StandardButton::Yes) { + QMessageBox::question(GetMessageBoxParent(), tr("Confirmation"), + tr("Settings changed, restart proxy?")) == QMessageBox::StandardButton::Yes) { neko_start(NekoRay::dataStore->started_id); } refresh_status(); @@ -507,8 +507,7 @@ void MainWindow::dialog_message_impl(const QString &sender, const QString &info) // 订阅完毕 refresh_proxy_list(); if (!info.contains("dingyue")) { - QMessageBox::information(this, "NekoRay", - tr("Imported %1 profile(s)").arg(NekoRay::dataStore->imported_count)); + MessageBoxInfo("NekoRay", tr("Imported %1 profile(s)").arg(NekoRay::dataStore->imported_count)); } } else if (sender == "ExternalProcess") { if (info == "Crashed") { @@ -880,14 +879,20 @@ void MainWindow::on_proxyListTable_itemDoubleClicked(QTableWidgetItem *item) { connect(dialog, &QDialog::finished, dialog, &QDialog::deleteLater); } +#define NO_ADD_TO_SUBSCRIPTION_GROUP \ +if (!NekoRay::profileManager->CurrentGroup()->url.isEmpty()) { \ +MessageBoxWarning("NekoRay", MainWindow::tr("Manual addition of profiles is not allowed in subscription groupings.")); \ +return; \ +} + void MainWindow::on_menu_add_from_input_triggered() { - if (!NekoRay::profileManager->CurrentGroup()->url.isEmpty()) return; + NO_ADD_TO_SUBSCRIPTION_GROUP auto dialog = new DialogEditProfile("socks", NekoRay::dataStore->current_group, this); connect(dialog, &QDialog::finished, dialog, &QDialog::deleteLater); } void MainWindow::on_menu_add_from_clipboard_triggered() { - if (!NekoRay::profileManager->CurrentGroup()->url.isEmpty()) return; + NO_ADD_TO_SUBSCRIPTION_GROUP auto clipboard = QApplication::clipboard()->text(); NekoRay::sub::groupUpdater->AsyncUpdate(clipboard); } @@ -896,9 +901,7 @@ void MainWindow::on_menu_clone_triggered() { auto ents = get_now_selected(); if (ents.isEmpty()) return; - auto btn = QMessageBox::question(nullptr, - tr("Clone"), - tr("Clone %1 item(s)").arg(ents.count())); + auto btn = QMessageBox::question(this, tr("Clone"), tr("Clone %1 item(s)").arg(ents.count())); if (btn != QMessageBox::Yes) return; QStringList sls; @@ -961,7 +964,7 @@ void MainWindow::on_menu_reset_traffic_triggered() { void MainWindow::on_menu_profile_debug_info_triggered() { auto ents = get_now_selected(); if (ents.count() != 1) return; - auto btn = QMessageBox::information(nullptr, "NekoRay", ents.first()->ToJsonBytes(), "OK", "Edit", "Reload", 0, 0); + auto btn = QMessageBox::information(this, "NekoRay", ents.first()->ToJsonBytes(), "OK", "Edit", "Reload", 0, 0); if (btn == 1) { QDesktopServices::openUrl(QUrl::fromLocalFile( QFileInfo(QString("profiles/%1.json").arg(ents.first()->id)).absoluteFilePath() @@ -1068,7 +1071,7 @@ void MainWindow::display_qr_link(bool nkrFormat) { } void MainWindow::on_menu_scan_qr_triggered() { - if (!NekoRay::profileManager->CurrentGroup()->url.isEmpty()) return; + NO_ADD_TO_SUBSCRIPTION_GROUP #ifndef NKR_NO_EXTERNAL using namespace ZXingQt; diff --git a/ui/mainwindow.ui b/ui/mainwindow.ui index bc7b6c7..64f8a62 100644 --- a/ui/mainwindow.ui +++ b/ui/mainwindow.ui @@ -482,8 +482,8 @@ - + @@ -704,6 +704,9 @@ Move + + Ctrl+M + @@ -721,12 +724,12 @@ Remember last profile - + true - Start minimal + Allow connections from the LAN