feat: vpn hide console

This commit is contained in:
arm64v8a
2022-09-17 12:05:23 +08:00
parent 96d352b19f
commit acab650833
8 changed files with 35 additions and 7 deletions

View File

@@ -44,7 +44,8 @@ Returns the return value of the executed command
*/ */
uint WinCommander::runProcessElevated(const QString &path, uint WinCommander::runProcessElevated(const QString &path,
const QStringList &parameters, const QStringList &parameters,
const QString &workingDir, bool aWait) { const QString &workingDir,
bool hide, bool aWait) {
uint result = 0; uint result = 0;
#ifdef Q_OS_WIN #ifdef Q_OS_WIN
@@ -75,7 +76,7 @@ uint WinCommander::runProcessElevated(const QString &path,
shex.lpParameters = pszParameters; shex.lpParameters = pszParameters;
shex.lpDirectory = pszDirectory; shex.lpDirectory = pszDirectory;
// https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-showwindow // https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-showwindow
shex.nShow = SW_SHOWMINIMIZED; shex.nShow = hide ? SW_HIDE : SW_SHOWMINIMIZED;
ShellExecuteEx(&shex); ShellExecuteEx(&shex);
if (shex.hProcess) if (shex.hProcess)
@@ -109,6 +110,6 @@ execution or wait for the exit of the launched process
Returns the return value of the executed command Returns the return value of the executed command
*/ */
uint WinCommander::runProcessElevated(const QString &path, const QString &parameters, const QString &workingDir, uint WinCommander::runProcessElevated(const QString &path, const QString &parameters, const QString &workingDir,
bool aWait) { bool hide, bool aWait) {
return runProcessElevated(path, QStringList() << parameters, workingDir, aWait); return runProcessElevated(path, QStringList() << parameters, workingDir, hide, aWait);
} }

View File

@@ -31,12 +31,12 @@ public:
static uint runProcessElevated(const QString &path, static uint runProcessElevated(const QString &path,
const QStringList &parameters = QStringList(), const QStringList &parameters = QStringList(),
const QString &workingDir = QString(), const QString &workingDir = QString(),
bool aWait = true); bool hide = false, bool aWait = true);
static uint runProcessElevated(const QString &path, static uint runProcessElevated(const QString &path,
const QString &parameters = QString(), const QString &parameters = QString(),
const QString &workingDir = QString(), const QString &workingDir = QString(),
bool aWait = true); bool hide = false, bool aWait = true);
}; };
#endif // WINCOMMANDER_H #endif // WINCOMMANDER_H

View File

@@ -53,6 +53,7 @@ namespace NekoRay {
_add(new configItem("vpn_impl", &vpn_implementation, itemType::integer)); _add(new configItem("vpn_impl", &vpn_implementation, itemType::integer));
_add(new configItem("vpn_mtu", &vpn_mtu, itemType::integer)); _add(new configItem("vpn_mtu", &vpn_mtu, itemType::integer));
_add(new configItem("vpn_ipv6", &vpn_ipv6, itemType::boolean)); _add(new configItem("vpn_ipv6", &vpn_ipv6, itemType::boolean));
_add(new configItem("vpn_hide_console", &vpn_hide_consloe, itemType::boolean));
_add(new configItem("check_include_pre", &check_include_pre, itemType::boolean)); _add(new configItem("check_include_pre", &check_include_pre, itemType::boolean));
} }

View File

@@ -106,6 +106,7 @@ namespace NekoRay {
int vpn_implementation = 0; int vpn_implementation = 0;
int vpn_mtu = 9000; int vpn_mtu = 9000;
bool vpn_ipv6 = false; bool vpn_ipv6 = false;
bool vpn_hide_consloe = false;
// Hotkey // Hotkey
QString hotkey_mainwindow = ""; QString hotkey_mainwindow = "";

View File

@@ -482,6 +482,10 @@
<source>VPN Enable IPv6</source> <source>VPN Enable IPv6</source>
<translation> VPN IPv6</translation> <translation> VPN IPv6</translation>
</message> </message>
<message>
<source>Hide Console</source>
<translation></translation>
</message>
</context> </context>
<context> <context>
<name>EditChain</name> <name>EditChain</name>

View File

@@ -44,6 +44,10 @@ DialogManageRoutes::DialogManageRoutes(QWidget *parent) :
ui->vpn_implementation->setCurrentIndex(NekoRay::dataStore->vpn_implementation); ui->vpn_implementation->setCurrentIndex(NekoRay::dataStore->vpn_implementation);
ui->vpn_mtu->setCurrentText(Int2String(NekoRay::dataStore->vpn_mtu)); ui->vpn_mtu->setCurrentText(Int2String(NekoRay::dataStore->vpn_mtu));
ui->vpn_ipv6->setChecked(NekoRay::dataStore->vpn_ipv6); ui->vpn_ipv6->setChecked(NekoRay::dataStore->vpn_ipv6);
ui->hide_console->setChecked(NekoRay::dataStore->vpn_hide_consloe);
#ifndef Q_OS_WIN
ui->hide_console->setVisible(false);
#endif
// //
#ifdef Q_OS_WIN #ifdef Q_OS_WIN
ui->vpn_implementation->setItemText(0, Preset::SingBox::VpnImplementation[0]); ui->vpn_implementation->setItemText(0, Preset::SingBox::VpnImplementation[0]);
@@ -122,6 +126,7 @@ void DialogManageRoutes::accept() {
NekoRay::dataStore->fake_dns = fakedns; NekoRay::dataStore->fake_dns = fakedns;
NekoRay::dataStore->vpn_mtu = mtu; NekoRay::dataStore->vpn_mtu = mtu;
NekoRay::dataStore->vpn_ipv6 = ipv6; NekoRay::dataStore->vpn_ipv6 = ipv6;
NekoRay::dataStore->vpn_hide_consloe = ui->hide_console->isChecked();
// //
bool routeChanged = false; bool routeChanged = false;
if (NekoRay::dataStore->active_routing != active_routing) routeChanged = true; if (NekoRay::dataStore->active_routing != active_routing) routeChanged = true;

View File

@@ -175,6 +175,19 @@
</item> </item>
</widget> </widget>
</item> </item>
<item>
<widget class="QCheckBox" name="hide_console">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Hide Console</string>
</property>
</widget>
</item>
<item> <item>
<widget class="QCheckBox" name="vpn_ipv6"> <widget class="QCheckBox" name="vpn_ipv6">
<property name="sizePolicy"> <property name="sizePolicy">

View File

@@ -1405,7 +1405,10 @@ bool MainWindow::StartVPNProcess() {
runOnNewThread([=] { runOnNewThread([=] {
vpn_pid = 1; //TODO get pid? vpn_pid = 1; //TODO get pid?
WinCommander::runProcessElevated(QApplication::applicationDirPath() + "/sing-box.exe", WinCommander::runProcessElevated(QApplication::applicationDirPath() + "/sing-box.exe",
{"--disable-color", "run", "-c", configPath}); // blocking {"--disable-color", "run", "-c", configPath},
"",
NekoRay::dataStore->vpn_hide_consloe
); // blocking
vpn_pid = 0; vpn_pid = 0;
runOnUiThread([=] { runOnUiThread([=] {
neko_set_spmode(NekoRay::SystemProxyMode::DISABLE); neko_set_spmode(NekoRay::SystemProxyMode::DISABLE);