mirror of
https://github.com/MatsuriDayo/nekoray.git
synced 2025-12-17 20:44:38 +03:00
optimize linux tun capability
This commit is contained in:
@@ -30,6 +30,9 @@
|
||||
#ifdef Q_OS_WIN
|
||||
#include "3rdparty/WinCommander.hpp"
|
||||
#else
|
||||
#ifdef Q_OS_LINUX
|
||||
#include "sys/linux/LinuxCap.h"
|
||||
#endif
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
@@ -691,6 +694,7 @@ void MainWindow::on_menu_exit_triggered() {
|
||||
arguments.removeFirst();
|
||||
arguments.removeAll("-tray");
|
||||
arguments.removeAll("-flag_restart_tun_on");
|
||||
arguments.removeAll("-flag_reorder");
|
||||
}
|
||||
auto isLauncher = qEnvironmentVariable("NKR_FROM_LAUNCHER") == "1";
|
||||
if (isLauncher) arguments.prepend("--");
|
||||
@@ -702,7 +706,6 @@ void MainWindow::on_menu_exit_triggered() {
|
||||
#ifdef Q_OS_WIN
|
||||
WinCommander::runProcessElevated(program, arguments, "", WinCommander::SW_NORMAL, false);
|
||||
#else
|
||||
arguments << "-flag_linux_run_core_as_admin";
|
||||
QProcess::startDetached(program, arguments);
|
||||
#endif
|
||||
} else {
|
||||
@@ -756,19 +759,28 @@ void MainWindow::neko_set_spmode_vpn(bool enable, bool save) {
|
||||
if (enable != NekoGui::dataStore->spmode_vpn) {
|
||||
if (enable) {
|
||||
if (IS_NEKO_BOX_INTERNAL_TUN) {
|
||||
bool requestPermission = !NekoGui::isAdmin();
|
||||
#ifdef Q_OS_LINUX
|
||||
if (requestPermission && QProcess::execute("pkexec", {"--help"}) != 0) {
|
||||
MessageBoxWarning(software_name, "Please install \"pkexec\" first.");
|
||||
neko_set_spmode_FAILED
|
||||
}
|
||||
#endif
|
||||
bool requestPermission = !NekoGui::IsAdmin();
|
||||
if (requestPermission) {
|
||||
#ifdef Q_OS_LINUX
|
||||
if (!Linux_HavePkexec()) {
|
||||
MessageBoxWarning(software_name, "Please install \"pkexec\" first.");
|
||||
neko_set_spmode_FAILED
|
||||
}
|
||||
auto ret = Linux_Pkexec_SetCapString(NekoGui::FindNekoBoxCoreRealPath(), "cap_net_admin=ep");
|
||||
if (ret == 0) {
|
||||
this->exit_reason = 3;
|
||||
on_menu_exit_triggered();
|
||||
} else {
|
||||
MessageBoxWarning(software_name, "Setcap for Tun mode failed.\n\n1. You may canceled the dialog.\n2. You may be using an incompatible environment like AppImage.");
|
||||
}
|
||||
#endif
|
||||
#ifdef Q_OS_WIN
|
||||
auto n = QMessageBox::warning(GetMessageBoxParent(), software_name, tr("Please run NekoBox as admin"), QMessageBox::Yes | QMessageBox::No);
|
||||
if (n == QMessageBox::Yes) {
|
||||
this->exit_reason = 3;
|
||||
on_menu_exit_triggered();
|
||||
}
|
||||
#endif
|
||||
neko_set_spmode_FAILED
|
||||
}
|
||||
} else {
|
||||
@@ -854,7 +866,7 @@ void MainWindow::refresh_status(const QString &traffic_update) {
|
||||
|
||||
auto make_title = [=](bool isTray) {
|
||||
QStringList tt;
|
||||
if (!isTray && NekoGui::isAdmin()) tt << "[Admin]";
|
||||
if (!isTray && NekoGui::IsAdmin()) tt << "[Admin]";
|
||||
if (select_mode) tt << "[" + tr("Select") + "]";
|
||||
if (!title_error.isEmpty()) tt << "[" + title_error + "]";
|
||||
if (NekoGui::dataStore->spmode_vpn) tt << "[VPN]";
|
||||
|
||||
Reference in New Issue
Block a user