Fix network proxy & add launch interface

pull/21/head
reionwong 4 years ago
parent 903353d10a
commit 811ae676dc

@ -125,6 +125,9 @@ Application::Application(int &argc, char **argv)
qunsetenv("XCURSOR_THEME"); qunsetenv("XCURSOR_THEME");
qunsetenv("XCURSOR_SIZE"); qunsetenv("XCURSOR_SIZE");
qunsetenv("SESSION_MANAGER");
m_networkProxyManager->update();
QTimer::singleShot(100, m_processManager, &ProcessManager::start); QTimer::singleShot(100, m_processManager, &ProcessManager::start);
} }
@ -134,6 +137,15 @@ bool Application::wayland() const
return m_wayland; return m_wayland;
} }
void Application::launch(const QString &exec, const QStringList &args)
{
QProcess process;
process.setProgram(exec);
process.setProcessEnvironment(QProcessEnvironment::systemEnvironment());
process.setArguments(args);
process.startDetached();
}
void Application::initEnvironments() void Application::initEnvironments()
{ {
// Set defaults // Set defaults

@ -62,6 +62,8 @@ public slots:
m_networkProxyManager->update(); m_networkProxyManager->update();
} }
void launch(const QString &exec, const QStringList &args);
private: private:
void initEnvironments(); void initEnvironments();
void initLanguage(); void initLanguage();

@ -19,5 +19,9 @@
<method name="updateNetworkProxy"> <method name="updateNetworkProxy">
<annotation name="org.freedesktop.DBus.Method.NoReply" value="true"/> <annotation name="org.freedesktop.DBus.Method.NoReply" value="true"/>
</method> </method>
<method name="launch">
<arg name="exec" type="s" direction="in"/>
<arg name="args" type="as" direction="in"/>
</method>
</interface> </interface>
</node> </node>

@ -17,22 +17,26 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "networkproxymanager.h" #include "networkproxymanager.h"
#include <QDBusPendingCall> #include <QDBusPendingCall>
#include <QDBusMessage> #include <QDBusMessage>
#include <QProcess>
#include <QDBusConnection> #include <QDBusConnection>
NetworkProxyManager::NetworkProxyManager(QObject *parent) NetworkProxyManager::NetworkProxyManager(QObject *parent)
: QObject(parent) : QObject(parent)
, m_settings("cutefishos", "network") , m_settings(QSettings::UserScope, "cutefishos", "network")
{ {
update();
} }
void NetworkProxyManager::update() void NetworkProxyManager::update()
{ {
qunsetenv("HTTP_PROXY"); qunsetenv("HTTP_PROXY");
qunsetenv("HTTPS_PROXY");
qunsetenv("FTP_PROXY"); qunsetenv("FTP_PROXY");
qunsetenv("ALL_PROXY");
qunsetenv("NO_PROXY");
m_settings.sync(); m_settings.sync();
@ -47,6 +51,7 @@ void NetworkProxyManager::update()
m_socksProxyPort = m_settings.value("SocksProxyPort", "").toString(); m_socksProxyPort = m_settings.value("SocksProxyPort", "").toString();
QMap<QString, QString> dbusActivationEnv; QMap<QString, QString> dbusActivationEnv;
QStringList systemdUpdates;
if (m_flag == 0) { if (m_flag == 0) {
// No proxy // No proxy
@ -56,34 +61,25 @@ void NetworkProxyManager::update()
// Use manually specified proxy configuration // Use manually specified proxy configuration
QString httpProxy = QString("http://%1:%2/").arg(m_httpProxy).arg(m_httpProxyPort); QString httpProxy = QString("http://%1:%2/").arg(m_httpProxy).arg(m_httpProxyPort);
QString ftpProxy = QString("http://%1:%2/").arg(m_ftpProxy).arg(m_ftpProxyPort);
if (m_useSameProxy) {
ftpProxy = httpProxy;
}
if (!m_httpProxy.isEmpty() && !m_httpProxyPort.isEmpty()) { if (!m_httpProxy.isEmpty() && !m_httpProxyPort.isEmpty()) {
qputenv("HTTP_PROXY", httpProxy.toLatin1()); qputenv("HTTP_PROXY", httpProxy.toLatin1());
dbusActivationEnv.insert("HTTP_PROXY", httpProxy); qputenv("HTTPS_PROXY", httpProxy.toLatin1());
} }
if (m_useSameProxy) {
if (!m_ftpProxy.isEmpty() && !m_ftpProxyPort.isEmpty()) { if (!m_ftpProxy.isEmpty() && !m_ftpProxyPort.isEmpty()) {
qputenv("FTP_PROXY", httpProxy.toLatin1()); qputenv("FTP_PROXY", ftpProxy.toLatin1());
dbusActivationEnv.insert("FTP_PROXY", httpProxy);
}
} else {
if (!m_ftpProxy.isEmpty() && !m_ftpProxyPort.isEmpty()) {
qputenv("FTP_PROXY", QString("http://%1:%2/").arg(m_ftpProxy).arg(m_ftpProxyPort).toLatin1());
dbusActivationEnv.insert("FTP_PROXY", QString("http://%1:%2/").arg(m_ftpProxy).arg(m_ftpProxyPort).toLatin1());
}
} }
// if (!m_socksProxy.isEmpty() && !m_socksProxyPort.isEmpty()) { qputenv("NO_PROXY", "localhost,127.0.0.0/8,::1");
// qputenv("ALL_PROXY", QString("socks://%1:%2/").arg(m_socksProxy).arg(m_socksProxyPort).toLatin1());
// }
}
QDBusMessage msg = QDBusMessage::createMethodCall(QStringLiteral("org.freedesktop.DBus"), if (!m_socksProxy.isEmpty() && !m_socksProxyPort.isEmpty()) {
QStringLiteral("/org/freedesktop/DBus"), qputenv("ALL_PROXY", QString("socks://%1:%2/").arg(m_socksProxy).arg(m_socksProxyPort).toLatin1());
QStringLiteral("org.freedesktop.DBus"), }
QStringLiteral("UpdateActivationEnvironment")); }
msg.setArguments({QVariant::fromValue(dbusActivationEnv)});
QDBusPendingCall reply = QDBusConnection::sessionBus().asyncCall(msg);
reply.waitForFinished();
} }

Loading…
Cancel
Save