Merge branch 'dev' into feature/amnezia-wireguard-client-impl
This commit is contained in:
commit
135726f177
52 changed files with 4380 additions and 2197 deletions
|
@ -19,23 +19,8 @@ ConnectionController::ConnectionController(const QSharedPointer<ServersModel> &s
|
|||
Qt::QueuedConnection);
|
||||
connect(this, &ConnectionController::disconnectFromVpn, m_vpnConnection.get(), &VpnConnection::disconnectFromVpn,
|
||||
Qt::QueuedConnection);
|
||||
}
|
||||
|
||||
ConnectionController::~ConnectionController()
|
||||
{
|
||||
// todo use ConnectionController instead of using m_vpnConnection directly
|
||||
#ifdef AMNEZIA_DESKTOP
|
||||
if (m_vpnConnection->connectionState() != Vpn::ConnectionState::Disconnected) {
|
||||
m_vpnConnection->disconnectFromVpn();
|
||||
for (int i = 0; i < 50; i++) {
|
||||
qApp->processEvents(QEventLoop::ExcludeUserInputEvents);
|
||||
QThread::msleep(100);
|
||||
if (m_vpnConnection->isDisconnected()) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
m_state = Vpn::ConnectionState::Disconnected;
|
||||
}
|
||||
|
||||
void ConnectionController::openConnection()
|
||||
|
@ -70,6 +55,8 @@ QString ConnectionController::getLastConnectionError()
|
|||
|
||||
void ConnectionController::onConnectionStateChanged(Vpn::ConnectionState state)
|
||||
{
|
||||
m_state = state;
|
||||
|
||||
m_isConnected = false;
|
||||
m_connectionStateText = tr("Connection...");
|
||||
switch (state) {
|
||||
|
@ -126,6 +113,17 @@ void ConnectionController::onCurrentContainerUpdated()
|
|||
}
|
||||
}
|
||||
|
||||
void ConnectionController::onTranslationsUpdated()
|
||||
{
|
||||
// get translated text of current state
|
||||
onConnectionStateChanged(getCurrentConnectionState());
|
||||
}
|
||||
|
||||
Vpn::ConnectionState ConnectionController::getCurrentConnectionState()
|
||||
{
|
||||
return m_state;
|
||||
}
|
||||
|
||||
QString ConnectionController::connectionStateText() const
|
||||
{
|
||||
return m_connectionStateText;
|
||||
|
|
|
@ -19,7 +19,7 @@ public:
|
|||
const QSharedPointer<ContainersModel> &containersModel,
|
||||
const QSharedPointer<VpnConnection> &vpnConnection, QObject *parent = nullptr);
|
||||
|
||||
~ConnectionController();
|
||||
~ConnectionController() = default;
|
||||
|
||||
bool isConnected() const;
|
||||
bool isConnectionInProgress() const;
|
||||
|
@ -34,6 +34,8 @@ public slots:
|
|||
|
||||
void onCurrentContainerUpdated();
|
||||
|
||||
void onTranslationsUpdated();
|
||||
|
||||
signals:
|
||||
void connectToVpn(int serverIndex, const ServerCredentials &credentials, DockerContainer container,
|
||||
const QJsonObject &containerConfig);
|
||||
|
@ -44,6 +46,8 @@ signals:
|
|||
void reconnectWithUpdatedContainer(const QString &message);
|
||||
|
||||
private:
|
||||
Vpn::ConnectionState getCurrentConnectionState();
|
||||
|
||||
QSharedPointer<ServersModel> m_serversModel;
|
||||
QSharedPointer<ContainersModel> m_containersModel;
|
||||
|
||||
|
@ -52,6 +56,8 @@ private:
|
|||
bool m_isConnected = false;
|
||||
bool m_isConnectionInProgress = false;
|
||||
QString m_connectionStateText = tr("Connect");
|
||||
|
||||
Vpn::ConnectionState m_state;
|
||||
};
|
||||
|
||||
#endif // CONNECTIONCONTROLLER_H
|
||||
|
|
|
@ -61,15 +61,6 @@ ImportController::ImportController(const QSharedPointer<ServersModel> &serversMo
|
|||
{
|
||||
#ifdef Q_OS_ANDROID
|
||||
mInstance = this;
|
||||
// Set security screen for Android app
|
||||
AndroidUtils::runOnAndroidThreadSync([]() {
|
||||
QJniObject activity = AndroidUtils::getActivity();
|
||||
QJniObject window = activity.callObjectMethod("getWindow", "()Landroid/view/Window;");
|
||||
if (window.isValid()) {
|
||||
const int FLAG_SECURE = 8192;
|
||||
window.callMethod<void>("addFlags", "(I)V", FLAG_SECURE);
|
||||
}
|
||||
});
|
||||
|
||||
AndroidUtils::runOnAndroidThreadAsync([]() {
|
||||
JNINativeMethod methods[] {
|
||||
|
|
|
@ -107,14 +107,12 @@ void InstallController::installServer(DockerContainer container, QJsonObject &co
|
|||
if (!installedContainers.contains(container)) {
|
||||
errorCode = serverController.setupContainer(m_currentlyInstalledServerCredentials, container, config);
|
||||
installedContainers.insert(container, config);
|
||||
finishMessage = ContainerProps::containerHumanNames().value(container) + tr(" installed successfully. ");
|
||||
finishMessage = tr("%1 installed successfully. ").arg(ContainerProps::containerHumanNames().value(container));
|
||||
} else {
|
||||
finishMessage =
|
||||
ContainerProps::containerHumanNames().value(container) + tr(" is already installed on the server. ");
|
||||
finishMessage = tr("%1 is already installed on the server. ").arg(ContainerProps::containerHumanNames().value(container));
|
||||
}
|
||||
if (installedContainers.size() > 1) {
|
||||
finishMessage += tr("\nAlready installed containers were found on the server. "
|
||||
"All installed containers have been added to the application");
|
||||
finishMessage += tr("\nAdded containers that were already installed on the server");
|
||||
}
|
||||
|
||||
if (errorCode == ErrorCode::NoError) {
|
||||
|
@ -160,10 +158,9 @@ void InstallController::installContainer(DockerContainer container, QJsonObject
|
|||
if (!installedContainers.contains(container)) {
|
||||
errorCode = serverController.setupContainer(serverCredentials, container, config);
|
||||
installedContainers.insert(container, config);
|
||||
finishMessage = ContainerProps::containerHumanNames().value(container) + tr(" installed successfully. ");
|
||||
finishMessage = tr("%1 installed successfully. ").arg(ContainerProps::containerHumanNames().value(container));
|
||||
} else {
|
||||
finishMessage =
|
||||
ContainerProps::containerHumanNames().value(container) + tr(" is already installed on the server. ");
|
||||
finishMessage = tr("%1 is already installed on the server. ").arg(ContainerProps::containerHumanNames().value(container));
|
||||
}
|
||||
|
||||
bool isInstalledContainerAddedToGui = false;
|
||||
|
@ -278,7 +275,7 @@ void InstallController::removeCurrentlyProcessedServer()
|
|||
QString serverName = m_serversModel->data(serverIndex, ServersModel::Roles::NameRole).toString();
|
||||
|
||||
m_serversModel->removeServer();
|
||||
emit removeCurrentlyProcessedServerFinished(tr("Server '") + serverName + tr("' was removed"));
|
||||
emit removeCurrentlyProcessedServerFinished(tr("Server '%1' was removed").arg(serverName));
|
||||
}
|
||||
|
||||
void InstallController::removeAllContainers()
|
||||
|
@ -288,7 +285,7 @@ void InstallController::removeAllContainers()
|
|||
|
||||
ErrorCode errorCode = m_containersModel->removeAllContainers();
|
||||
if (errorCode == ErrorCode::NoError) {
|
||||
emit removeAllContainersFinished(tr("All containers from server '") + serverName + ("' have been removed"));
|
||||
emit removeAllContainersFinished(tr("All containers from server '%1' have been removed").arg(serverName));
|
||||
return;
|
||||
}
|
||||
emit installationErrorOccurred(errorString(errorCode));
|
||||
|
@ -304,8 +301,8 @@ void InstallController::removeCurrentlyProcessedContainer()
|
|||
|
||||
ErrorCode errorCode = m_containersModel->removeCurrentlyProcessedContainer();
|
||||
if (errorCode == ErrorCode::NoError) {
|
||||
emit removeCurrentlyProcessedContainerFinished(containerName + tr(" has been removed from the server '")
|
||||
+ serverName + "'");
|
||||
|
||||
emit removeCurrentlyProcessedContainerFinished(tr("%1 has been removed from the server '%2'").arg(containerName).arg(serverName));
|
||||
return;
|
||||
}
|
||||
emit installationErrorOccurred(errorString(errorCode));
|
||||
|
|
|
@ -37,6 +37,8 @@ PageController::PageController(const QSharedPointer<ServersModel> &serversModel,
|
|||
connect(this, &PageController::raiseMainWindow, []() { setDockIconVisible(true); });
|
||||
connect(this, &PageController::hideMainWindow, []() { setDockIconVisible(false); });
|
||||
#endif
|
||||
|
||||
m_isTriggeredByConnectButton = false;
|
||||
}
|
||||
|
||||
QString PageController::getInitialPage()
|
||||
|
@ -145,3 +147,13 @@ void PageController::drawerClose()
|
|||
m_drawerLayer = 0;
|
||||
}
|
||||
}
|
||||
|
||||
bool PageController::isTriggeredByConnectButton()
|
||||
{
|
||||
return m_isTriggeredByConnectButton;
|
||||
}
|
||||
|
||||
void PageController::setTriggeredBtConnectButton(bool trigger)
|
||||
{
|
||||
m_isTriggeredByConnectButton = trigger;
|
||||
}
|
||||
|
|
|
@ -85,6 +85,10 @@ public slots:
|
|||
void drawerOpen();
|
||||
void drawerClose();
|
||||
|
||||
|
||||
bool isTriggeredByConnectButton();
|
||||
void setTriggeredBtConnectButton(bool trigger);
|
||||
|
||||
signals:
|
||||
void goToPage(PageLoader::PageEnum page, bool slide = true);
|
||||
void goToStartPage();
|
||||
|
@ -121,6 +125,8 @@ private:
|
|||
|
||||
PageLoader::PageEnum m_currentRootPage;
|
||||
int m_drawerLayer;
|
||||
|
||||
bool m_isTriggeredByConnectButton;
|
||||
};
|
||||
|
||||
#endif // PAGECONTROLLER_H
|
||||
|
|
|
@ -6,6 +6,11 @@
|
|||
#include "systemController.h"
|
||||
#include "ui/qautostart.h"
|
||||
#include "version.h"
|
||||
#ifdef Q_OS_ANDROID
|
||||
#include "../../platforms/android/android_controller.h"
|
||||
#include "../../platforms/android/androidutils.h"
|
||||
#include <QJniObject>
|
||||
#endif
|
||||
|
||||
SettingsController::SettingsController(const QSharedPointer<ServersModel> &serversModel,
|
||||
const QSharedPointer<ContainersModel> &containersModel,
|
||||
|
@ -18,6 +23,20 @@ SettingsController::SettingsController(const QSharedPointer<ServersModel> &serve
|
|||
m_settings(settings)
|
||||
{
|
||||
m_appVersion = QString("%1: %2 (%3)").arg(tr("Software version"), QString(APP_MAJOR_VERSION), __DATE__);
|
||||
|
||||
#ifdef Q_OS_ANDROID
|
||||
if (!m_settings->isScreenshotsEnabled()) {
|
||||
// Set security screen for Android app
|
||||
AndroidUtils::runOnAndroidThreadSync([]() {
|
||||
QJniObject activity = AndroidUtils::getActivity();
|
||||
QJniObject window = activity.callObjectMethod("getWindow", "()Landroid/view/Window;");
|
||||
if (window.isValid()) {
|
||||
const int FLAG_SECURE = 8192;
|
||||
window.callMethod<void>("addFlags", "(I)V", FLAG_SECURE);
|
||||
}
|
||||
});
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void SettingsController::toggleAmneziaDns(bool enable)
|
||||
|
@ -152,3 +171,26 @@ void SettingsController::toggleStartMinimized(bool enable)
|
|||
{
|
||||
m_settings->setStartMinimized(enable);
|
||||
}
|
||||
|
||||
bool SettingsController::isScreenshotsEnabled()
|
||||
{
|
||||
return m_settings->isScreenshotsEnabled();
|
||||
}
|
||||
|
||||
void SettingsController::toggleScreenshotsEnabled(bool enable)
|
||||
{
|
||||
m_settings->setScreenshotsEnabled(enable);
|
||||
#ifdef Q_OS_ANDROID
|
||||
std::string command = enable ? "clearFlags" : "addFlags";
|
||||
|
||||
// Set security screen for Android app
|
||||
AndroidUtils::runOnAndroidThreadSync([&command]() {
|
||||
QJniObject activity = AndroidUtils::getActivity();
|
||||
QJniObject window = activity.callObjectMethod("getWindow", "()Landroid/view/Window;");
|
||||
if (window.isValid()) {
|
||||
const int FLAG_SECURE = 8192;
|
||||
window.callMethod<void>(command.c_str(), "(I)V", FLAG_SECURE);
|
||||
}
|
||||
});
|
||||
#endif
|
||||
}
|
|
@ -54,6 +54,9 @@ public slots:
|
|||
bool isStartMinimizedEnabled();
|
||||
void toggleStartMinimized(bool enable);
|
||||
|
||||
bool isScreenshotsEnabled();
|
||||
void toggleScreenshotsEnabled(bool enable);
|
||||
|
||||
signals:
|
||||
void primaryDnsChanged();
|
||||
void secondaryDnsChanged();
|
||||
|
|
|
@ -64,7 +64,7 @@ void SitesController::addSite(QString hostname)
|
|||
QHostInfo::lookupHost(hostname, this, resolveCallback);
|
||||
}
|
||||
|
||||
emit finished(tr("New site added: ") + hostname);
|
||||
emit finished(tr("New site added: %1").arg(hostname));
|
||||
}
|
||||
|
||||
void SitesController::removeSite(int index)
|
||||
|
@ -77,7 +77,7 @@ void SitesController::removeSite(int index)
|
|||
Q_ARG(QStringList, QStringList() << hostname));
|
||||
QMetaObject::invokeMethod(m_vpnConnection.get(), "flushDns", Qt::QueuedConnection);
|
||||
|
||||
emit finished(tr("Site removed: ") + hostname);
|
||||
emit finished(tr("Site removed: %1").arg(hostname));
|
||||
}
|
||||
|
||||
void SitesController::importSites(const QString &fileName, bool replaceExisting)
|
||||
|
@ -85,19 +85,19 @@ void SitesController::importSites(const QString &fileName, bool replaceExisting)
|
|||
QFile file(fileName);
|
||||
|
||||
if (!file.open(QIODevice::ReadOnly)) {
|
||||
emit errorOccurred(tr("Can't open file: ") + fileName);
|
||||
emit errorOccurred(tr("Can't open file: %1").arg(fileName));
|
||||
return;
|
||||
}
|
||||
|
||||
QByteArray jsonData = file.readAll();
|
||||
QJsonDocument jsonDocument = QJsonDocument::fromJson(jsonData);
|
||||
if (jsonDocument.isNull()) {
|
||||
emit errorOccurred(tr("Failed to parse JSON data from file: ") + fileName);
|
||||
emit errorOccurred(tr("Failed to parse JSON data from file: %1").arg(fileName));
|
||||
return;
|
||||
}
|
||||
|
||||
if (!jsonDocument.isArray()) {
|
||||
emit errorOccurred(tr("The JSON data is not an array in file: ") + fileName);
|
||||
emit errorOccurred(tr("The JSON data is not an array in file: ").arg(fileName));
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue