added changelog drawer

This commit is contained in:
vladimir.kuznetsov 2024-05-25 10:04:41 +02:00
parent 53746f2f66
commit 871037f887
13 changed files with 384 additions and 51 deletions

View file

@ -406,4 +406,12 @@ void AmneziaApplication::initControllers()
m_systemController.reset(new SystemController(m_settings));
m_engine->rootContext()->setContextProperty("SystemController", m_systemController.get());
m_updateController.reset(new UpdateController(m_settings));
m_engine->rootContext()->setContextProperty("UpdateController", m_updateController.get());
m_updateController->checkForUpdates();
connect(m_updateController.get(), &UpdateController::updateFound, this, [this]() {
QTimer::singleShot(1000, this, [this]() { m_pageController->showChangelogDrawer(); });
});
}

View file

@ -24,6 +24,7 @@
#include "ui/controllers/sitesController.h"
#include "ui/controllers/systemController.h"
#include "ui/controllers/appSplitTunnelingController.h"
#include "ui/controllers/updateController.h"
#include "ui/models/containers_model.h"
#include "ui/models/languageModel.h"
#include "ui/models/protocols/cloakConfigModel.h"
@ -130,6 +131,7 @@ private:
QScopedPointer<SitesController> m_sitesController;
QScopedPointer<SystemController> m_systemController;
QScopedPointer<AppSplitTunnelingController> m_appSplitTunnelingController;
QScopedPointer<UpdateController> m_updateController;
QNetworkAccessManager *m_nam;
};

View file

@ -99,7 +99,7 @@ void ApiController::updateServerConfigFromApi(const QString &installationUuid, c
QByteArray requestBody = QJsonDocument(apiPayload).toJson();
QNetworkReply *reply = amnApp->manager()->post(request, requestBody); // ??
QNetworkReply *reply = amnApp->manager()->post(request, requestBody);
QObject::connect(reply, &QNetworkReply::finished, [this, reply, protocol, apiPayloadData, serverIndex, serverConfig]() mutable {
if (reply->error() == QNetworkReply::NoError) {

View file

@ -239,5 +239,6 @@
<file>images/controls/alert-circle.svg</file>
<file>images/controls/file-check-2.svg</file>
<file>ui/qml/Controls2/WarningType.qml</file>
<file>ui/qml/Components/ChangelogDrawer.qml</file>
</qresource>
</RCC>

View file

@ -126,6 +126,8 @@ signals:
void forceTabBarActiveFocus();
void forceStackActiveFocus();
void showChangelogDrawer();
private:
QSharedPointer<ServersModel> m_serversModel;

View file

@ -9,7 +9,7 @@ class SystemController : public QObject
{
Q_OBJECT
public:
explicit SystemController(const std::shared_ptr<Settings> &setting, QObject *parent = nullptr);
explicit SystemController(const std::shared_ptr<Settings> &settings, QObject *parent = nullptr);
static void saveFile(QString fileName, const QString &data);

View file

@ -0,0 +1,149 @@
#include "updateController.h"
#include <QNetworkAccessManager>
#include <QNetworkReply>
#include <QVersionNumber>
#include <QtConcurrent>
#include "amnezia_application.h"
#include "core/errorstrings.h"
#include "version.h"
namespace {
#ifdef Q_OS_MACOS
const QString installerPath = QStandardPaths::writableLocation(QStandardPaths::TempLocation) + "/AmneziaVPN.dmg";
#elif defined Q_OS_WINDOWS
const QString installerPath = QStandardPaths::writableLocation(QStandardPaths::TempLocation) + "/AmneziaVPN.exe";
#elif defined(Q_OS_LINUX) && !defined(Q_OS_ANDROID)
const QString installerPath = QStandardPaths::writableLocation(QStandardPaths::TempLocation) + "/AmneziaVPN.tar.zip";
#endif
}
UpdateController::UpdateController(const std::shared_ptr<Settings> &settings, QObject *parent) : QObject(parent), m_settings(settings)
{
}
QString UpdateController::getHeaderText()
{
return tr("New version released: %1 (%2)").arg(m_version, m_releaseDate);
}
QString UpdateController::getChangelogText()
{
return m_changelogText;
}
void UpdateController::checkForUpdates()
{
QNetworkRequest request;
request.setTransferTimeout(7000);
QString endpoint = "https://api.github.com/repos/amnezia-vpn/amnezia-client/releases/latest";
request.setUrl(endpoint);
QNetworkReply *reply = amnApp->manager()->get(request);
QObject::connect(reply, &QNetworkReply::finished, [this, reply]() {
if (reply->error() == QNetworkReply::NoError) {
QString contents = QString::fromUtf8(reply->readAll());
QJsonObject data = QJsonDocument::fromJson(contents.toUtf8()).object();
m_version = data.value("tag_name").toString();
auto currentVersion = QVersionNumber::fromString(QString(APP_VERSION));
qDebug() << currentVersion;
auto newVersion = QVersionNumber::fromString(m_version);
if (newVersion > currentVersion) {
m_changelogText = data.value("body").toString();
QString dateString = data.value("published_at").toString();
QDateTime dateTime = QDateTime::fromString(dateString, "yyyy-MM-ddTHH:mm:ssZ");
m_releaseDate = dateTime.toString("MMM dd yyyy");
QJsonArray assets = data.value("assets").toArray();
for (auto asset : assets) {
QJsonObject assetObject = asset.toObject();
if (assetObject.value("name").toString().contains(".dmg")) {
m_downloadUrl = assetObject.value("browser_download_url").toString();
}
}
emit updateFound();
}
} else {
if (reply->error() == QNetworkReply::NetworkError::OperationCanceledError
|| reply->error() == QNetworkReply::NetworkError::TimeoutError) {
qDebug() << errorString(ErrorCode::ApiConfigTimeoutError);
} else {
QString err = reply->errorString();
qDebug() << QString::fromUtf8(reply->readAll());
qDebug() << reply->error();
qDebug() << err;
qDebug() << reply->attribute(QNetworkRequest::HttpStatusCodeAttribute);
qDebug() << errorString(ErrorCode::ApiConfigDownloadError);
}
}
reply->deleteLater();
});
QObject::connect(reply, &QNetworkReply::errorOccurred,
[this, reply](QNetworkReply::NetworkError error) { qDebug() << reply->errorString() << error; });
connect(reply, &QNetworkReply::sslErrors, [this, reply](const QList<QSslError> &errors) {
qDebug().noquote() << errors;
qDebug() << errorString(ErrorCode::ApiConfigSslError);
});
}
void UpdateController::runInstaller()
{
QNetworkRequest request;
request.setTransferTimeout(7000);
request.setUrl(m_downloadUrl);
QNetworkReply *reply = amnApp->manager()->get(request);
QObject::connect(reply, &QNetworkReply::finished, [this, reply]() {
if (reply->error() == QNetworkReply::NoError) {
QFile file(installerPath);
if (file.open(QIODevice::WriteOnly)) {
file.write(reply->readAll());
file.close();
QFutureWatcher<int> watcher;
QFuture<int> future = QtConcurrent::run([this]() {
QString t = installerPath;
QRemoteObjectPendingReply<int> ipcReply = IpcClient::Interface()->mountDmg(t, true);
ipcReply.waitForFinished();
QProcess::execute("/Volumes/AmneziaVPN/AmneziaVPN.app/Contents/MacOS/AmneziaVPN");
ipcReply = IpcClient::Interface()->mountDmg(t, false);
ipcReply.waitForFinished();
return ipcReply.returnValue();
});
QEventLoop wait;
connect(&watcher, &QFutureWatcher<ErrorCode>::finished, &wait, &QEventLoop::quit);
watcher.setFuture(future);
wait.exec();
qDebug() << future.result();
// emit errorOccured("");
}
} else {
if (reply->error() == QNetworkReply::NetworkError::OperationCanceledError
|| reply->error() == QNetworkReply::NetworkError::TimeoutError) {
qDebug() << errorString(ErrorCode::ApiConfigTimeoutError);
} else {
QString err = reply->errorString();
qDebug() << QString::fromUtf8(reply->readAll());
qDebug() << reply->error();
qDebug() << err;
qDebug() << reply->attribute(QNetworkRequest::HttpStatusCodeAttribute);
qDebug() << errorString(ErrorCode::ApiConfigDownloadError);
}
}
reply->deleteLater();
});
}

View file

@ -0,0 +1,34 @@
#ifndef UPDATECONTROLLER_H
#define UPDATECONTROLLER_H
#include <QObject>
#include "settings.h"
class UpdateController : public QObject
{
Q_OBJECT
public:
explicit UpdateController(const std::shared_ptr<Settings> &settings, QObject *parent = nullptr);
Q_PROPERTY(QString changelogText READ getChangelogText NOTIFY updateFound)
Q_PROPERTY(QString headerText READ getHeaderText NOTIFY updateFound)
public slots:
QString getHeaderText();
QString getChangelogText();
void checkForUpdates();
void runInstaller();
signals:
void updateFound();
void errorOccured(const QString &errorMessage);
private:
std::shared_ptr<Settings> m_settings;
QString m_changelogText;
QString m_version;
QString m_releaseDate;
QString m_downloadUrl;
};
#endif // UPDATECONTROLLER_H

View file

@ -0,0 +1,119 @@
import QtQuick
import QtQuick.Controls
import QtQuick.Layouts
import "../Controls2"
import "../Controls2/TextTypes"
import "../Config"
DrawerType2 {
id: root
anchors.fill: parent
expandedHeight: parent.height * 0.9
expandedContent: Item {
implicitHeight: root.expandedHeight
Connections {
target: root
enabled: !GC.isMobile()
function onOpened() {
focusItem.forceActiveFocus()
}
}
Header2TextType {
id: header
anchors.top: parent.top
anchors.left: parent.left
anchors.right: parent.right
anchors.topMargin: 16
anchors.rightMargin: 16
anchors.leftMargin: 16
text: UpdateController.headerText
}
FlickableType {
anchors.top: header.bottom
anchors.bottom: updateButton.top
contentHeight: changelog.height + 32
ParagraphTextType {
id: changelog
anchors.top: parent.top
anchors.left: parent.left
anchors.right: parent.right
anchors.topMargin: 48
anchors.rightMargin: 16
anchors.leftMargin: 16
HoverHandler {
enabled: parent.hoveredLink
cursorShape: Qt.PointingHandCursor
}
onLinkActivated: function(link) {
Qt.openUrlExternally(link)
}
text: UpdateController.changelogText
textFormat: Text.MarkdownText
}
}
Item {
id: focusItem
KeyNavigation.tab: updateButton
}
BasicButtonType {
id: updateButton
anchors.bottom: skipButton.top
anchors.left: parent.left
anchors.right: parent.right
anchors.topMargin: 16
anchors.bottomMargin: 8
anchors.rightMargin: 16
anchors.leftMargin: 16
text: qsTr("Update")
clickedFunc: function() {
PageController.showBusyIndicator(true)
UpdateController.runInstaller()
PageController.showBusyIndicator(false)
root.close()
}
KeyNavigation.tab: skipButton
}
BasicButtonType {
id: skipButton
anchors.bottom: parent.bottom
anchors.left: parent.left
anchors.right: parent.right
anchors.bottomMargin: 16
anchors.rightMargin: 16
anchors.leftMargin: 16
defaultColor: "transparent"
hoveredColor: Qt.rgba(1, 1, 1, 0.08)
pressedColor: Qt.rgba(1, 1, 1, 0.12)
disabledColor: "#878B91"
textColor: "#D7D8DB"
borderWidth: 1
text: qsTr("Skip this version")
clickedFunc: function() {
root.close()
}
KeyNavigation.tab: focusItem
}
}
}

View file

@ -92,6 +92,10 @@ Window {
busyIndicator.visible = visible
PageController.disableControls(visible)
}
function onShowChangelogDrawer() {
changelogDrawer.open()
}
}
Connections {
@ -264,4 +268,14 @@ Window {
onAccepted: SystemController.fileDialogClosed(true)
onRejected: SystemController.fileDialogClosed(false)
}
Item {
anchors.fill: parent
ChangelogDrawer {
id: changelogDrawer
anchors.fill: parent
}
}
}

View file

@ -32,5 +32,7 @@ class IpcInterface
SLOT( bool enablePeerTraffic( const QJsonObject &configStr) );
SLOT( bool enableKillSwitch( const QJsonObject &excludeAddr, int vpnAdapterIndex) );
SLOT( bool updateResolvers(const QString& ifname, const QList<QHostAddress>& resolvers) );
SLOT( int mountDmg(const QString &path, bool mount) );
};

View file

@ -1,32 +1,33 @@
#include "ipcserver.h"
#include <QObject>
#include <QDateTime>
#include <QLocalSocket>
#include <QFileInfo>
#include <QLocalSocket>
#include <QObject>
#include <QProcess>
#include "router.h"
#include "logger.h"
#include "router.h"
#include "../client/protocols/protocols_defs.h"
#ifdef Q_OS_WIN
#include "tapcontroller_win.h"
#include "../client/platforms/windows/daemon/windowsfirewall.h"
#include "../client/platforms/windows/daemon/windowsdaemon.h"
#include "../client/platforms/windows/daemon/windowsdaemon.h"
#include "../client/platforms/windows/daemon/windowsfirewall.h"
#include "tapcontroller_win.h"
#endif
#ifdef Q_OS_LINUX
#include "../client/platforms/linux/daemon/linuxfirewall.h"
#include "../client/platforms/linux/daemon/linuxfirewall.h"
#endif
#ifdef Q_OS_MACOS
#include "../client/platforms/macos/daemon/macosfirewall.h"
#include "../client/platforms/macos/daemon/macosfirewall.h"
#endif
IpcServer::IpcServer(QObject *parent):
IpcInterfaceSource(parent)
IpcServer::IpcServer(QObject *parent) : IpcInterfaceSource(parent)
{}
{
}
int IpcServer::createPrivilegedProcess()
{
@ -58,23 +59,20 @@ int IpcServer::createPrivilegedProcess()
}
});
QObject::connect(pd.serverNode.data(), &QRemoteObjectHost::error, this, [pd](QRemoteObjectNode::ErrorCode errorCode) {
qDebug() << "QRemoteObjectHost::error" << errorCode;
});
QObject::connect(pd.serverNode.data(), &QRemoteObjectHost::error, this,
[pd](QRemoteObjectNode::ErrorCode errorCode) { qDebug() << "QRemoteObjectHost::error" << errorCode; });
QObject::connect(pd.serverNode.data(), &QRemoteObjectHost::destroyed, this, [pd]() {
qDebug() << "QRemoteObjectHost::destroyed";
});
QObject::connect(pd.serverNode.data(), &QRemoteObjectHost::destroyed, this, [pd]() { qDebug() << "QRemoteObjectHost::destroyed"; });
// connect(pd.ipcProcess.data(), &IpcServerProcess::finished, this, [this, pid=m_localpid](int exitCode, QProcess::ExitStatus exitStatus){
// qDebug() << "IpcServerProcess finished" << exitCode << exitStatus;
//// if (m_processes.contains(pid)) {
//// m_processes[pid].ipcProcess.reset();
//// m_processes[pid].serverNode.reset();
//// m_processes[pid].localServer.reset();
//// m_processes.remove(pid);
//// }
// });
// connect(pd.ipcProcess.data(), &IpcServerProcess::finished, this, [this, pid=m_localpid](int exitCode, QProcess::ExitStatus exitStatus){
// qDebug() << "IpcServerProcess finished" << exitCode << exitStatus;
//// if (m_processes.contains(pid)) {
//// m_processes[pid].ipcProcess.reset();
//// m_processes[pid].serverNode.reset();
//// m_processes[pid].localServer.reset();
//// m_processes.remove(pid);
//// }
// });
m_processes.insert(m_localpid, pd);
@ -105,7 +103,7 @@ bool IpcServer::routeDeleteList(const QString &gw, const QStringList &ips)
qDebug() << "IpcServer::routeDeleteList";
#endif
return Router::routeDeleteList(gw ,ips);
return Router::routeDeleteList(gw, ips);
}
void IpcServer::flushDns()
@ -172,7 +170,7 @@ bool IpcServer::deleteTun(const QString &dev)
return Router::deleteTun(dev);
}
bool IpcServer::updateResolvers(const QString& ifname, const QList<QHostAddress>& resolvers)
bool IpcServer::updateResolvers(const QString &ifname, const QList<QHostAddress> &resolvers)
{
return Router::updateResolvers(ifname, resolvers);
}
@ -194,13 +192,11 @@ void IpcServer::setLogsEnabled(bool enabled)
if (enabled) {
Logger::init();
}
else {
} else {
Logger::deinit();
}
}
bool IpcServer::enableKillSwitch(const QJsonObject &configStr, int vpnAdapterIndex)
{
#ifdef Q_OS_WIN
@ -216,13 +212,11 @@ bool IpcServer::enableKillSwitch(const QJsonObject &configStr, int vpnAdapterInd
QStringList allownets;
QStringList blocknets;
if (splitTunnelType == 0)
{
if (splitTunnelType == 0) {
blockAll = true;
allowNets = true;
allownets.append(configStr.value(amnezia::config_key::hostName).toString());
} else if (splitTunnelType == 1)
{
} else if (splitTunnelType == 1) {
blockNets = true;
for (auto v : splitTunnelSites) {
blocknets.append(v.toString());
@ -264,18 +258,17 @@ bool IpcServer::enableKillSwitch(const QJsonObject &configStr, int vpnAdapterInd
// double-check + ensure our firewall is installed and enabled. This is necessary as
// other software may disable pfctl before re-enabling with their own rules (e.g other VPNs)
if (!MacOSFirewall::isInstalled()) MacOSFirewall::install();
if (!MacOSFirewall::isInstalled())
MacOSFirewall::install();
MacOSFirewall::ensureRootAnchorPriority();
MacOSFirewall::setAnchorEnabled(QStringLiteral("000.allowLoopback"), true);
MacOSFirewall::setAnchorEnabled(QStringLiteral("100.blockAll"), blockAll);
MacOSFirewall::setAnchorEnabled(QStringLiteral("110.allowNets"), allowNets);
MacOSFirewall::setAnchorTable(QStringLiteral("110.allowNets"), allowNets,
QStringLiteral("allownets"), allownets);
MacOSFirewall::setAnchorTable(QStringLiteral("110.allowNets"), allowNets, QStringLiteral("allownets"), allownets);
MacOSFirewall::setAnchorEnabled(QStringLiteral("120.blockNets"), blockNets);
MacOSFirewall::setAnchorTable(QStringLiteral("120.blockNets"), blockNets,
QStringLiteral("blocknets"), blocknets);
MacOSFirewall::setAnchorTable(QStringLiteral("120.blockNets"), blockNets, QStringLiteral("blocknets"), blocknets);
MacOSFirewall::setAnchorEnabled(QStringLiteral("200.allowVPN"), true);
MacOSFirewall::setAnchorEnabled(QStringLiteral("250.blockIPv6"), true);
MacOSFirewall::setAnchorEnabled(QStringLiteral("290.allowDHCP"), true);
@ -326,10 +319,8 @@ bool IpcServer::enablePeerTraffic(const QJsonObject &configStr)
// Use APP split tunnel
if (splitTunnelType == 0 || splitTunnelType == 2) {
config.m_allowedIPAddressRanges.append(
IPAddress(QHostAddress("0.0.0.0"), 0));
config.m_allowedIPAddressRanges.append(
IPAddress(QHostAddress("::"), 0));
config.m_allowedIPAddressRanges.append(IPAddress(QHostAddress("0.0.0.0"), 0));
config.m_allowedIPAddressRanges.append(IPAddress(QHostAddress("::"), 0));
}
if (splitTunnelType == 1) {
@ -337,10 +328,9 @@ bool IpcServer::enablePeerTraffic(const QJsonObject &configStr)
QString ipRange = v.toString();
if (ipRange.split('/').size() > 1) {
config.m_allowedIPAddressRanges.append(
IPAddress(QHostAddress(ipRange.split('/')[0]), atoi(ipRange.split('/')[1].toLocal8Bit())));
IPAddress(QHostAddress(ipRange.split('/')[0]), atoi(ipRange.split('/')[1].toLocal8Bit())));
} else {
config.m_allowedIPAddressRanges.append(
IPAddress(QHostAddress(ipRange), 32));
config.m_allowedIPAddressRanges.append(IPAddress(QHostAddress(ipRange), 32));
}
}
}
@ -353,7 +343,7 @@ bool IpcServer::enablePeerTraffic(const QJsonObject &configStr)
}
}
for (const QJsonValue& i : configStr.value(amnezia::config_key::splitTunnelApps).toArray()) {
for (const QJsonValue &i : configStr.value(amnezia::config_key::splitTunnelApps).toArray()) {
if (!i.isString()) {
break;
}
@ -371,3 +361,14 @@ bool IpcServer::enablePeerTraffic(const QJsonObject &configStr)
#endif
return true;
}
int IpcServer::mountDmg(const QString &path, bool mount)
{
#ifdef Q_OS_MACOS
qDebug() << path;
auto res = QProcess::execute(QString("sudo hdiutil %1 %2").arg(mount ? "attach" : "unmount", path));
qDebug() << res;
return res;
#endif
return 0;
}

View file

@ -35,6 +35,7 @@ public:
virtual bool enableKillSwitch(const QJsonObject &excludeAddr, int vpnAdapterIndex) override;
virtual bool disableKillSwitch() override;
virtual bool updateResolvers(const QString& ifname, const QList<QHostAddress>& resolvers) override;
virtual int mountDmg(const QString &path, bool mount) override;
private:
int m_localpid = 0;