mirror of
https://github.com/MatsuriDayo/nekoray.git
synced 2025-12-17 12:34:37 +03:00
feat: allow access from LAN (tray action)
This commit is contained in:
@@ -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<void()> &callback, QObject *parent) {
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -151,6 +151,10 @@
|
||||
<source>Connection statistics</source>
|
||||
<translation>连接统计</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Minimize to tray icon on startup</source>
|
||||
<translation>启动时最小化到托盘图标</translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>DialogEditGroup</name>
|
||||
@@ -941,10 +945,6 @@ End: %2</source>
|
||||
<source>Remember last profile</source>
|
||||
<translation>记住最后的配置</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Start minimal</source>
|
||||
<translation>最小化启动</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Move %1 item(s)</source>
|
||||
<translation>移动 %1 个项目</translation>
|
||||
@@ -1081,6 +1081,14 @@ End: %2</source>
|
||||
<source>Copy links of selected (Nekoray)</source>
|
||||
<translation>批量复制选中项目的分享链接 (Nekoray)</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Allow connections from the LAN</source>
|
||||
<translation>允许来自局域网的连接</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Manual addition of profiles is not allowed in subscription groupings.</source>
|
||||
<translation>订阅分组中不允许手动添加配置。</translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>ProxyItem</name>
|
||||
|
||||
@@ -83,6 +83,7 @@ DialogBasicSettings::DialogBasicSettings(QWidget *parent)
|
||||
connect(ui->language, QOverload<int>::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
|
||||
|
||||
|
||||
@@ -384,6 +384,13 @@
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QCheckBox" name="start_minimal">
|
||||
<property name="text">
|
||||
<string>Minimize to tray icon on startup</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QWidget" name="tab_2">
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -482,8 +482,8 @@
|
||||
<addaction name="menu_scan_qr"/>
|
||||
<addaction name="separator"/>
|
||||
<addaction name="actionStart_with_system"/>
|
||||
<addaction name="actionStart_minimal"/>
|
||||
<addaction name="actionRemember_last_proxy"/>
|
||||
<addaction name="actionAllow_LAN"/>
|
||||
<addaction name="menuActive_Server"/>
|
||||
<addaction name="menuActive_Routing"/>
|
||||
<addaction name="menu_spmode"/>
|
||||
@@ -704,6 +704,9 @@
|
||||
<property name="text">
|
||||
<string>Move</string>
|
||||
</property>
|
||||
<property name="shortcut">
|
||||
<string notr="true">Ctrl+M</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionStart_with_system">
|
||||
<property name="checkable">
|
||||
@@ -721,12 +724,12 @@
|
||||
<string>Remember last profile</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionStart_minimal">
|
||||
<action name="actionAllow_LAN">
|
||||
<property name="checkable">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Start minimal</string>
|
||||
<string>Allow connections from the LAN</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="menu_remove_unavailable">
|
||||
|
||||
Reference in New Issue
Block a user