optimize vpn

This commit is contained in:
arm64v8a 2023-03-02 09:12:53 +09:00
parent 1f4263acd1
commit bbde5bc0e9
7 changed files with 90 additions and 9 deletions

View File

@ -611,6 +611,25 @@
<source>Proxy Process Name</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Troubleshooting</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>If you have trouble starting VPN, you can force reset nekobox_core process here.
If still not working, see documentation for more information.
https://matsuridayo.github.io/n-configuration/#vpn-tun</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Reset</source>
<translation type="unfinished">بازنشانی</translation>
</message>
<message>
<source>Cancel</source>
<translation type="unfinished">لغو کردن</translation>
</message>
</context>
<context>
<name>EditChain</name>

View File

@ -617,6 +617,28 @@
<source>Whether blacklisted or whitelisted, your traffic will be handled by nekobox_core (sing-tun). This is NOT equal to &quot;process mode&quot; of some software.</source>
<translation> nekobox_core (sing-tun) </translation>
</message>
<message>
<source>Troubleshooting</source>
<translation></translation>
</message>
<message>
<source>If you have trouble starting VPN, you can force reset nekobox_core process here.
If still not working, see documentation for more information.
https://matsuridayo.github.io/n-configuration/#vpn-tun</source>
<translation> VPN nekobox_core
https://matsuridayo.github.io/n-configuration/#vpn-tun</translation>
</message>
<message>
<source>Reset</source>
<translation></translation>
</message>
<message>
<source>Cancel</source>
<translation></translation>
</message>
</context>
<context>
<name>EditChain</name>

View File

@ -3,6 +3,9 @@
#include "main/GuiUtils.hpp"
#include "main/NekoRay.hpp"
#include "ui/mainwindow_interface.h"
#include <QMessageBox>
DialogVPNSettings::DialogVPNSettings(QWidget *parent) : QDialog(parent), ui(new Ui::DialogVPNSettings) {
ui->setupUi(this);
@ -57,3 +60,15 @@ void DialogVPNSettings::accept() {
MW_dialog_message("", "UpdateDataStore,VPNChanged");
QDialog::accept();
}
void DialogVPNSettings::on_troubleshooting_clicked() {
auto r = QMessageBox::information(this, tr("Troubleshooting"),
tr("If you have trouble starting VPN, you can force reset nekobox_core process here.\n\n"
"If still not working, see documentation for more information.\n"
"https://matsuridayo.github.io/n-configuration/#vpn-tun"),
tr("Reset"), tr("Cancel"), "",
1, 1);
if (r == 0) {
GetMainWindow()->StopVPNProcess(true);
}
}

View File

@ -23,6 +23,9 @@ private:
public slots:
void accept() override;
void on_troubleshooting_clicked();
};
#endif // NEKORAY_DIALOG_VPN_SETTINGS_H

View File

@ -157,6 +157,26 @@
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="troubleshooting">
<property name="text">
<string>Troubleshooting</string>
</property>
</widget>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="standardButtons">

View File

@ -1684,8 +1684,8 @@ bool MainWindow::StartVPNProcess() {
return true;
}
bool MainWindow::StopVPNProcess() {
if (vpn_pid != 0) {
bool MainWindow::StopVPNProcess(bool unconditional) {
if (unconditional || vpn_pid != 0) {
bool ok;
core_process->processId();
#ifdef Q_OS_WIN
@ -1699,15 +1699,17 @@ bool MainWindow::StopVPNProcess() {
p.start("osascript", {"-e", QString("do shell script \"%1\" with administrator privileges")
.arg("pkill -2 -U 0 nekobox_core")});
#else
p.start("pkexec", {"pkill", "-2", "-P", Int2String(vpn_pid)});
if (unconditional) {
p.start("pkexec", {"killall", "nekobox_core"});
} else {
p.start("pkexec", {"pkill", "-2", "-P", Int2String(vpn_pid)});
}
#endif
p.waitForFinished();
ok = p.exitCode() == 0;
#endif
if (ok) {
vpn_pid = 0;
} else {
MessageBoxWarning(tr("Error"), tr("Failed to stop VPN process"));
if (!unconditional) {
ok ? vpn_pid = 0 : MessageBoxWarning(tr("Error"), tr("Failed to stop VPN process"));
}
return ok;
}

View File

@ -61,6 +61,8 @@ public:
void RegisterHotkey(bool unregister);
bool StopVPNProcess(bool unconditional = false);
signals:
void profile_selected(int id);
@ -173,8 +175,6 @@ private:
bool StartVPNProcess();
bool StopVPNProcess();
// grpc and ...
void setup_grpc();