diff --git a/desktop/externalreverseproxyrunner.cpp b/desktop/externalreverseproxyrunner.cpp index 54fe221..dc1ea5d 100644 --- a/desktop/externalreverseproxyrunner.cpp +++ b/desktop/externalreverseproxyrunner.cpp @@ -8,7 +8,13 @@ #include "externalreverseproxyrunner.h" -ExternalReverseProxyRunner::ExternalReverseProxyRunner(QObject *parent) {} +ExternalReverseProxyRunner::ExternalReverseProxyRunner(QObject *parent) : m_process(new QProcess) {} + +ExternalReverseProxyRunner::~ExternalReverseProxyRunner() +{ + m_process->terminate(); + delete m_process; +} void ExternalReverseProxyRunner::start() { @@ -32,7 +38,47 @@ void ExternalReverseProxyRunner::restart() start(); } -void ExternalReverseProxyRunner::applySettings(QSettings &settings) {} +void ExternalReverseProxyRunner::applySettings(QSettings &settings) +{ + m_process->setProgram(settings.value("externalReverseProxyPath").toString()); + QStringList args; + bool ok = false; + int state = settings.value("reverseProxyAutoRedirect", 2).toInt(&ok); + if (ok && state == Qt::Checked) + { + args << "--auto-redirect"; + } + state = settings.value("reverseProxyRedirect", 2).toInt(&ok); + if (ok) + { + args << "--redirect"; + } +#if !defined(Q_OS_WIN) + auto networkInterface = settings.value("reverseProxyBindNetworkInterface").toString(); + if (!networkInterface.isEmpty()) + { + args << "-i" << networkInterface; + } +#endif + auto port = settings.value("reverseProxyListenPort", 8090).toInt(&ok); + if (ok) + { + args << "-b" << QStringLiteral("localhost:%1").arg(port); + } + auto proxyType = settings.value("reverseProxyProxyType").toString(); + if (proxyType == QStringLiteral("Http")) + { + auto proxyAddr = settings.value("reverseProxyProxyAddress").toString(); + args << "-t" << proxyAddr; + } + if (proxyType == QStringLiteral("Socks5")) + { + auto proxyAddr = settings.value("reverseProxyProxyAddress").toString(); + args << "-s" << proxyAddr; + } + + m_process->setArguments(args); +} bool ExternalReverseProxyRunner::isRunning() { diff --git a/desktop/externalreverseproxyrunner.h b/desktop/externalreverseproxyrunner.h index 10c3fc3..8a8b4b0 100644 --- a/desktop/externalreverseproxyrunner.h +++ b/desktop/externalreverseproxyrunner.h @@ -10,7 +10,7 @@ class ExternalReverseProxyRunner : public QObject Q_OBJECT public: explicit ExternalReverseProxyRunner(QObject *parent = nullptr); - + ~ExternalReverseProxyRunner(); void start(); void stop(); void restart(); diff --git a/desktop/main.cpp b/desktop/main.cpp index 384d68b..2a34edf 100644 --- a/desktop/main.cpp +++ b/desktop/main.cpp @@ -247,13 +247,12 @@ int main(int argc, char *argv[]) builtinReverseProxyRunner.start(); } QObject::connect(&app, &QCoreApplication::aboutToQuit, [&builtinReverseProxyRunner, &externalReverseProxyRunner]() { - builtinReverseProxyRunner.stop(); - builtinReverseProxyRunner.wait(); - if (externalReverseProxyRunner.isRunning()) { externalReverseProxyRunner.stop(); } + builtinReverseProxyRunner.stop(); + builtinReverseProxyRunner.wait(); }); return QtSingleApplication::exec(); diff --git a/desktop/ui/configurationwindow.cpp b/desktop/ui/configurationwindow.cpp index d1a5a12..d4ce470 100644 --- a/desktop/ui/configurationwindow.cpp +++ b/desktop/ui/configurationwindow.cpp @@ -138,8 +138,6 @@ ConfigurationWindow::ConfigurationWindow(BeastServerRunner &runner, ExternalReve m_trayIcon->show(); connect(m_trayIcon, &QSystemTrayIcon::activated, this, &ConfigurationWindow::onSystemTrayIconActivated); - - m_reverseProxyAddr = QString("localhost:%1").arg(ui->reverseProxyListenPort->value()).toUtf8(); } ConfigurationWindow::~ConfigurationWindow() @@ -341,9 +339,17 @@ void ConfigurationWindow::initNetworkInterfaces() } void ConfigurationWindow::restartReverseProxy() { - m_builtinReverseProxyRunner.stop(); - m_builtinReverseProxyRunner.wait(); - m_builtinReverseProxyRunner.start(); + if (m_settings->value("useExternalReverseProxy", 2).toInt() == Qt::Checked) + { + m_externalReverseProxyRunner.stop(); + m_externalReverseProxyRunner.start(); + } + else + { + m_builtinReverseProxyRunner.stop(); + m_builtinReverseProxyRunner.wait(); + m_builtinReverseProxyRunner.start(); + } } void ConfigurationWindow::onReverseProxyListenPortValueChanged(int port) @@ -351,7 +357,7 @@ void ConfigurationWindow::onReverseProxyListenPortValueChanged(int port) Q_ASSERT(m_settings); m_settings->setValue("reverseProxyListenPort", port); m_settings->sync(); - m_reverseProxyAddr = QString("localhost:%1").arg(ui->reverseProxyListenPort->value()).toUtf8(); + restartReverseProxy(); } @@ -369,7 +375,7 @@ void ConfigurationWindow::onReverseProxyAutoRedirectStateChanged(int state) Q_ASSERT(m_settings); m_settings->setValue("reverseProxyAutoRedirect", state); m_settings->sync(); - + restartReverseProxy(); } @@ -378,7 +384,7 @@ void ConfigurationWindow::onReverseProxyRedirectStateChanged(int state) Q_ASSERT(m_settings); m_settings->setValue("reverseProxyRedirect", state); m_settings->sync(); - + restartReverseProxy(); }