moved the platform-specific android code for the new ui
This commit is contained in:
parent
5b8a0881b7
commit
0a1359ed16
31 changed files with 854 additions and 764 deletions
|
@ -11,9 +11,12 @@
|
|||
|
||||
#include "configurators/openvpn_configurator.h"
|
||||
#include "configurators/wireguard_configurator.h"
|
||||
#include "qrcodegen.hpp"
|
||||
|
||||
#include "core/errorstrings.h"
|
||||
#ifdef Q_OS_ANDROID
|
||||
#include "platforms/android/android_controller.h"
|
||||
#include "platforms/android/androidutils.h"
|
||||
#endif
|
||||
#include "qrcodegen.hpp"
|
||||
|
||||
ExportController::ExportController(const QSharedPointer<ServersModel> &serversModel,
|
||||
const QSharedPointer<ContainersModel> &containersModel,
|
||||
|
@ -25,6 +28,14 @@ ExportController::ExportController(const QSharedPointer<ServersModel> &serversMo
|
|||
m_settings(settings),
|
||||
m_configurator(configurator)
|
||||
{
|
||||
#ifdef Q_OS_ANDROID
|
||||
m_authResultNotifier.reset(new AuthResultNotifier);
|
||||
m_authResultReceiver.reset(new AuthResultReceiver(m_authResultNotifier));
|
||||
connect(m_authResultNotifier.get(), &AuthResultNotifier::authFailed, this,
|
||||
[this]() { emit exportErrorOccurred(tr("Access error!")); });
|
||||
connect(m_authResultNotifier.get(), &AuthResultNotifier::authSuccessful, this,
|
||||
&ExportController::generateFullAccessConfig);
|
||||
#endif
|
||||
}
|
||||
|
||||
void ExportController::generateFullAccessConfig()
|
||||
|
@ -44,6 +55,27 @@ void ExportController::generateFullAccessConfig()
|
|||
emit exportConfigChanged();
|
||||
}
|
||||
|
||||
#if defined(Q_OS_ANDROID)
|
||||
void ExportController::generateFullAccessConfigAndroid()
|
||||
{
|
||||
/* We use builtin keyguard for ssh key export protection on Android */
|
||||
QJniObject activity = AndroidUtils::getActivity();
|
||||
auto appContext = activity.callObjectMethod("getApplicationContext", "()Landroid/content/Context;");
|
||||
if (appContext.isValid()) {
|
||||
auto intent = QJniObject::callStaticObjectMethod("org/amnezia/vpn/AuthHelper", "getAuthIntent",
|
||||
"(Landroid/content/Context;)Landroid/content/Intent;",
|
||||
appContext.object());
|
||||
if (intent.isValid()) {
|
||||
if (intent.object<jobject>() != nullptr) {
|
||||
QtAndroidPrivate::startActivity(intent.object<jobject>(), 1, m_authResultReceiver.get());
|
||||
}
|
||||
} else {
|
||||
generateFullAccessConfig();
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
void ExportController::generateConnectionConfig()
|
||||
{
|
||||
clearPreviousConfig();
|
||||
|
@ -194,6 +226,35 @@ void ExportController::saveFile()
|
|||
QDesktopServices::openUrl(fi.absoluteDir().absolutePath());
|
||||
}
|
||||
|
||||
void ExportController::shareFile()
|
||||
{
|
||||
#if defined Q_OS_IOS
|
||||
ext.replace("*", "");
|
||||
QString fileName = QDir::tempPath() + "/" + suggestedName;
|
||||
|
||||
if (fileName.isEmpty())
|
||||
return;
|
||||
if (!fileName.endsWith(ext))
|
||||
fileName.append(ext);
|
||||
|
||||
QFile::remove(fileName);
|
||||
|
||||
QFile save(fileName);
|
||||
save.open(QIODevice::WriteOnly);
|
||||
save.write(data.toUtf8());
|
||||
save.close();
|
||||
|
||||
QStringList filesToSend;
|
||||
filesToSend.append(fileName);
|
||||
MobileUtils::shareText(filesToSend);
|
||||
return;
|
||||
#endif
|
||||
#if defined Q_OS_ANDROID
|
||||
AndroidController::instance()->shareConfig(m_config, "amnezia_config");
|
||||
return;
|
||||
#endif
|
||||
}
|
||||
|
||||
QList<QString> ExportController::generateQrCodeImageSeries(const QByteArray &data)
|
||||
{
|
||||
double k = 850;
|
||||
|
|
|
@ -6,6 +6,9 @@
|
|||
#include "configurators/vpn_configurator.h"
|
||||
#include "ui/models/containers_model.h"
|
||||
#include "ui/models/servers_model.h"
|
||||
#ifdef Q_OS_ANDROID
|
||||
#include "platforms/android/authResultReceiver.h"
|
||||
#endif
|
||||
|
||||
class ExportController : public QObject
|
||||
{
|
||||
|
@ -22,6 +25,9 @@ public:
|
|||
|
||||
public slots:
|
||||
void generateFullAccessConfig();
|
||||
#if defined(Q_OS_ANDROID)
|
||||
void generateFullAccessConfigAndroid();
|
||||
#endif
|
||||
void generateConnectionConfig();
|
||||
void generateOpenVpnConfig();
|
||||
void generateWireGuardConfig();
|
||||
|
@ -30,6 +36,7 @@ public slots:
|
|||
QList<QString> getQrCodes();
|
||||
|
||||
void saveFile();
|
||||
void shareFile();
|
||||
|
||||
signals:
|
||||
void generateConfig(int type);
|
||||
|
@ -52,6 +59,11 @@ private:
|
|||
|
||||
QString m_config;
|
||||
QList<QString> m_qrCodes;
|
||||
|
||||
#ifdef Q_OS_ANDROID
|
||||
QSharedPointer<AuthResultNotifier> m_authResultNotifier;
|
||||
QSharedPointer<QAndroidActivityResultReceiver> m_authResultReceiver;
|
||||
#endif
|
||||
};
|
||||
|
||||
#endif // EXPORTCONTROLLER_H
|
||||
|
|
|
@ -2,8 +2,15 @@
|
|||
|
||||
#include <QFile>
|
||||
#include <QFileInfo>
|
||||
#include <QStandardPaths>
|
||||
|
||||
#include "core/errorstrings.h"
|
||||
#ifdef Q_OS_ANDROID
|
||||
#include "../../platforms/android/android_controller.h"
|
||||
#include "../../platforms/android/androidutils.h"
|
||||
#include <QJniObject>
|
||||
#endif
|
||||
#include "utilities.h"
|
||||
|
||||
namespace
|
||||
{
|
||||
|
@ -41,33 +48,58 @@ ImportController::ImportController(const QSharedPointer<ServersModel> &serversMo
|
|||
const std::shared_ptr<Settings> &settings, QObject *parent)
|
||||
: QObject(parent), m_serversModel(serversModel), m_containersModel(containersModel), m_settings(settings)
|
||||
{
|
||||
#ifdef Q_OS_ANDROID
|
||||
// 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 ImportController::extractConfigFromFile(const QUrl &fileUrl)
|
||||
void ImportController::extractConfigFromFile()
|
||||
{
|
||||
QFile file(fileUrl.toLocalFile());
|
||||
QString fileName = Utils::getFileName(Q_NULLPTR, tr("Open config file"),
|
||||
QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation),
|
||||
"*.vpn *.ovpn *.conf");
|
||||
QFile file(fileName);
|
||||
if (file.open(QIODevice::ReadOnly)) {
|
||||
QString data = file.readAll();
|
||||
|
||||
auto configFormat = checkConfigFormat(data);
|
||||
if (configFormat == ConfigTypes::OpenVpn) {
|
||||
m_config = extractOpenVpnConfig(data);
|
||||
} else if (configFormat == ConfigTypes::WireGuard) {
|
||||
m_config = extractWireGuardConfig(data);
|
||||
} else {
|
||||
m_config = extractAmneziaConfig(data);
|
||||
}
|
||||
|
||||
extractConfigFromData(data);
|
||||
m_configFileName = QFileInfo(file.fileName()).fileName();
|
||||
}
|
||||
}
|
||||
|
||||
void ImportController::extractConfigFromData(QString &data)
|
||||
{
|
||||
auto configFormat = checkConfigFormat(data);
|
||||
if (configFormat == ConfigTypes::OpenVpn) {
|
||||
m_config = extractOpenVpnConfig(data);
|
||||
} else if (configFormat == ConfigTypes::WireGuard) {
|
||||
m_config = extractWireGuardConfig(data);
|
||||
} else {
|
||||
m_config = extractAmneziaConfig(data);
|
||||
}
|
||||
}
|
||||
|
||||
void ImportController::extractConfigFromCode(QString code)
|
||||
{
|
||||
m_config = extractAmneziaConfig(code);
|
||||
m_configFileName = "";
|
||||
}
|
||||
|
||||
void ImportController::extractConfigFromQr()
|
||||
{
|
||||
#ifdef Q_OS_ANDROID
|
||||
AndroidController::instance()->startQrReaderActivity();
|
||||
#endif
|
||||
}
|
||||
|
||||
QString ImportController::getConfig()
|
||||
{
|
||||
return QJsonDocument(m_config).toJson(QJsonDocument::Indented);
|
||||
|
|
|
@ -3,10 +3,10 @@
|
|||
|
||||
#include <QObject>
|
||||
|
||||
#include "core/defs.h"
|
||||
#include "containers/containers_defs.h"
|
||||
#include "ui/models/servers_model.h"
|
||||
#include "core/defs.h"
|
||||
#include "ui/models/containers_model.h"
|
||||
#include "ui/models/servers_model.h"
|
||||
|
||||
class ImportController : public QObject
|
||||
{
|
||||
|
@ -14,13 +14,14 @@ class ImportController : public QObject
|
|||
public:
|
||||
explicit ImportController(const QSharedPointer<ServersModel> &serversModel,
|
||||
const QSharedPointer<ContainersModel> &containersModel,
|
||||
const std::shared_ptr<Settings> &settings,
|
||||
QObject *parent = nullptr);
|
||||
const std::shared_ptr<Settings> &settings, QObject *parent = nullptr);
|
||||
|
||||
public slots:
|
||||
void importConfig();
|
||||
void extractConfigFromFile(const QUrl &fileUrl);
|
||||
void extractConfigFromFile();
|
||||
void extractConfigFromData(QString &data);
|
||||
void extractConfigFromCode(QString code);
|
||||
void extractConfigFromQr();
|
||||
QString getConfig();
|
||||
QString getConfigFileName();
|
||||
|
||||
|
@ -39,7 +40,6 @@ private:
|
|||
|
||||
QJsonObject m_config;
|
||||
QString m_configFileName;
|
||||
|
||||
};
|
||||
|
||||
#endif // IMPORTCONTROLLER_H
|
||||
|
|
|
@ -8,6 +8,34 @@
|
|||
#include "core/servercontroller.h"
|
||||
#include "utilities.h"
|
||||
|
||||
namespace
|
||||
{
|
||||
#ifdef Q_OS_WINDOWS
|
||||
QString getNextDriverLetter()
|
||||
{
|
||||
QProcess drivesProc;
|
||||
drivesProc.start("wmic logicaldisk get caption");
|
||||
drivesProc.waitForFinished();
|
||||
QString drives = drivesProc.readAll();
|
||||
qDebug() << drives;
|
||||
|
||||
QString letters = "CFGHIJKLMNOPQRSTUVWXYZ";
|
||||
QString letter;
|
||||
for (int i = letters.size() - 1; i > 0; i--) {
|
||||
letter = letters.at(i);
|
||||
if (!drives.contains(letter + ":"))
|
||||
break;
|
||||
}
|
||||
if (letter == "C:") {
|
||||
// set err info
|
||||
qDebug() << "Can't find free drive letter";
|
||||
return "";
|
||||
}
|
||||
return letter;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
InstallController::InstallController(const QSharedPointer<ServersModel> &serversModel,
|
||||
const QSharedPointer<ContainersModel> &containersModel,
|
||||
const std::shared_ptr<Settings> &settings, QObject *parent)
|
||||
|
@ -15,6 +43,17 @@ InstallController::InstallController(const QSharedPointer<ServersModel> &servers
|
|||
{
|
||||
}
|
||||
|
||||
InstallController::~InstallController()
|
||||
{
|
||||
#ifdef Q_OS_WINDOWS
|
||||
for (QSharedPointer<QProcess> process : m_sftpMountProcesses) {
|
||||
Utils::signalCtrl(process->processId(), CTRL_C_EVENT);
|
||||
process->kill();
|
||||
process->waitForFinished();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void InstallController::install(DockerContainer container, int port, TransportProto transportProto)
|
||||
{
|
||||
Proto mainProto = ContainerProps::defaultProtocol(container);
|
||||
|
|
|
@ -16,6 +16,7 @@ public:
|
|||
explicit InstallController(const QSharedPointer<ServersModel> &serversModel,
|
||||
const QSharedPointer<ContainersModel> &containersModel,
|
||||
const std::shared_ptr<Settings> &settings, QObject *parent = nullptr);
|
||||
~InstallController();
|
||||
|
||||
public slots:
|
||||
void install(DockerContainer container, int port, TransportProto transportProto);
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
#include "pageController.h"
|
||||
|
||||
PageController::PageController(const QSharedPointer<ServersModel> &serversModel,
|
||||
QObject *parent) : QObject(parent), m_serversModel(serversModel)
|
||||
#include <QApplication>
|
||||
|
||||
PageController::PageController(const QSharedPointer<ServersModel> &serversModel, QObject *parent)
|
||||
: QObject(parent), m_serversModel(serversModel)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -24,3 +26,24 @@ QString PageController::getPagePath(PageLoader::PageEnum page)
|
|||
QString pageName = metaEnum.valueToKey(static_cast<int>(page));
|
||||
return "qrc:/ui/qml/Pages2/" + pageName + ".qml";
|
||||
}
|
||||
|
||||
void PageController::closeWindow()
|
||||
{
|
||||
#ifdef Q_OS_ANDROID
|
||||
qApp->quit();
|
||||
#else
|
||||
if (m_serversModel->getServersCount() == 0) {
|
||||
qApp->quit();
|
||||
} else {
|
||||
emit hideMainWindow();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void PageController::keyPressEvent(Qt::Key key)
|
||||
{
|
||||
switch (key) {
|
||||
case Qt::Key_Back: emit closePage();
|
||||
default: return;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -41,6 +41,7 @@ namespace PageLoader
|
|||
PageSetupWizardConfigSource,
|
||||
PageSetupWizardTextKey,
|
||||
PageSetupWizardViewConfig,
|
||||
PageSetupWizardQrReader,
|
||||
|
||||
PageProtocolOpenVpnSettings,
|
||||
PageProtocolShadowSocksSettings,
|
||||
|
@ -67,15 +68,25 @@ public slots:
|
|||
QString getInitialPage();
|
||||
QString getPagePath(PageLoader::PageEnum page);
|
||||
|
||||
void closeWindow();
|
||||
void keyPressEvent(Qt::Key key);
|
||||
|
||||
signals:
|
||||
void goToPageHome();
|
||||
void goToPageSettings();
|
||||
void goToPageViewConfig();
|
||||
void closePage();
|
||||
|
||||
void restorePageHomeState(bool isContainerInstalled = false);
|
||||
void replaceStartPage();
|
||||
|
||||
void showErrorMessage(QString errorMessage);
|
||||
void showInfoMessage(QString message);
|
||||
|
||||
void showBusyIndicator(bool visible);
|
||||
void raise();
|
||||
|
||||
void hideMainWindow();
|
||||
void raiseMainWindow();
|
||||
|
||||
private:
|
||||
QSharedPointer<ServersModel> m_serversModel;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue