mirror of
https://github.com/amnezia-vpn/amnezia-client.git
synced 2026-05-08 14:33:23 +00:00
Fixed: Bug when saving after canceling the save action
This commit is contained in:
@@ -977,7 +977,9 @@ bool IosController::shareText(const QStringList& filesToSend) {
|
|||||||
}
|
}
|
||||||
#if !MACOS_NE
|
#if !MACOS_NE
|
||||||
UIViewController *qtController = getViewController();
|
UIViewController *qtController = getViewController();
|
||||||
if (!qtController) return;
|
if (!qtController) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
UIActivityViewController *activityController = [[UIActivityViewController alloc] initWithActivityItems:sharingItems applicationActivities:nil];
|
UIActivityViewController *activityController = [[UIActivityViewController alloc] initWithActivityItems:sharingItems applicationActivities:nil];
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
#include "allowedDnsUiController.h"
|
#include "allowedDnsUiController.h"
|
||||||
|
|
||||||
|
#include <QDebug>
|
||||||
#include <QFile>
|
#include <QFile>
|
||||||
#include <QStandardPaths>
|
#include <QStandardPaths>
|
||||||
#include <QJsonDocument>
|
#include <QJsonDocument>
|
||||||
@@ -98,7 +99,10 @@ void AllowedDnsUiController::exportDns(const QString &fileName)
|
|||||||
QJsonDocument jsonDocument(jsonArray);
|
QJsonDocument jsonDocument(jsonArray);
|
||||||
QByteArray jsonData = jsonDocument.toJson();
|
QByteArray jsonData = jsonDocument.toJson();
|
||||||
|
|
||||||
SystemController::saveFile(fileName, jsonData);
|
if (!SystemController::saveFile(fileName, jsonData)) {
|
||||||
|
qInfo() << "AllowedDnsUiController::exportDns: save or share was cancelled or failed";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
emit finished(tr("Export completed"));
|
emit finished(tr("Export completed"));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -89,8 +89,7 @@ bool SubscriptionUiController::exportVpnKey(int serverIndex, const QString &file
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
SystemController::saveFile(fileName, m_vpnKey);
|
return SystemController::saveFile(fileName, m_vpnKey);
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SubscriptionUiController::exportNativeConfig(int serverIndex, const QString &serverCountryCode, const QString &fileName)
|
bool SubscriptionUiController::exportNativeConfig(int serverIndex, const QString &serverCountryCode, const QString &fileName)
|
||||||
@@ -107,8 +106,9 @@ bool SubscriptionUiController::exportNativeConfig(int serverIndex, const QString
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
SystemController::saveFile(fileName, nativeConfig);
|
const bool saved = SystemController::saveFile(fileName, nativeConfig);
|
||||||
return true;
|
getAccountInfo(serverIndex, true);
|
||||||
|
return saved;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SubscriptionUiController::revokeNativeConfig(int serverIndex, const QString &serverCountryCode)
|
bool SubscriptionUiController::revokeNativeConfig(int serverIndex, const QString &serverCountryCode)
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
#include "ipSplitTunnelingUiController.h"
|
#include "ipSplitTunnelingUiController.h"
|
||||||
|
|
||||||
|
#include <QDebug>
|
||||||
|
|
||||||
#include "systemController.h"
|
#include "systemController.h"
|
||||||
#include "core/utils/errorCodes.h"
|
#include "core/utils/errorCodes.h"
|
||||||
#include "core/utils/routeModes.h"
|
#include "core/utils/routeModes.h"
|
||||||
@@ -55,7 +57,10 @@ void IpSplitTunnelingUiController::importSites(const QString &fileName, bool rep
|
|||||||
void IpSplitTunnelingUiController::exportSites(const QString &fileName)
|
void IpSplitTunnelingUiController::exportSites(const QString &fileName)
|
||||||
{
|
{
|
||||||
QByteArray jsonData = m_ipSplitTunnelingController->exportSitesToJson();
|
QByteArray jsonData = m_ipSplitTunnelingController->exportSitesToJson();
|
||||||
SystemController::saveFile(fileName, QString::fromUtf8(jsonData));
|
if (!SystemController::saveFile(fileName, jsonData)) {
|
||||||
|
qInfo() << "IpSplitTunnelingUiController::exportSites: save or share was cancelled or failed";
|
||||||
|
return;
|
||||||
|
}
|
||||||
emit finished(tr("Export completed"));
|
emit finished(tr("Export completed"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
#include "exportUiController.h"
|
#include "exportUiController.h"
|
||||||
|
|
||||||
|
#include <QDebug>
|
||||||
|
|
||||||
#include "../systemController.h"
|
#include "../systemController.h"
|
||||||
|
|
||||||
ExportUiController::ExportUiController(ExportController* exportController, QObject *parent)
|
ExportUiController::ExportUiController(ExportController* exportController, QObject *parent)
|
||||||
@@ -68,7 +70,9 @@ QList<QString> ExportUiController::getQrCodes()
|
|||||||
|
|
||||||
void ExportUiController::exportConfig(const QString &fileName)
|
void ExportUiController::exportConfig(const QString &fileName)
|
||||||
{
|
{
|
||||||
SystemController::saveFile(fileName, m_config);
|
if (!SystemController::saveFile(fileName, m_config)) {
|
||||||
|
qInfo() << "ExportUiController::exportConfig: save or share was cancelled or failed";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ExportUiController::updateClientManagementModel(int serverIndex, int containerIndex)
|
void ExportUiController::updateClientManagementModel(int serverIndex, int containerIndex)
|
||||||
|
|||||||
@@ -107,7 +107,9 @@ void SettingsUiController::exportLogsFile(const QString &fileName)
|
|||||||
#ifdef Q_OS_ANDROID
|
#ifdef Q_OS_ANDROID
|
||||||
AndroidController::instance()->exportLogsFile(fileName);
|
AndroidController::instance()->exportLogsFile(fileName);
|
||||||
#else
|
#else
|
||||||
SystemController::saveFile(fileName, Logger::getLogFile());
|
if (!SystemController::saveFile(fileName, Logger::getLogFile())) {
|
||||||
|
qInfo() << "SettingsUiController::exportLogsFile: save or share was cancelled or failed";
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -116,7 +118,9 @@ void SettingsUiController::exportServiceLogsFile(const QString &fileName)
|
|||||||
#ifdef Q_OS_ANDROID
|
#ifdef Q_OS_ANDROID
|
||||||
AndroidController::instance()->exportLogsFile(fileName);
|
AndroidController::instance()->exportLogsFile(fileName);
|
||||||
#else
|
#else
|
||||||
SystemController::saveFile(fileName, Logger::getServiceLogFile());
|
if (!SystemController::saveFile(fileName, Logger::getServiceLogFile())) {
|
||||||
|
qInfo() << "SettingsUiController::exportServiceLogsFile: save or share was cancelled or failed";
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -132,7 +136,9 @@ void SettingsUiController::clearLogs()
|
|||||||
void SettingsUiController::backupAppConfig(const QString &fileName)
|
void SettingsUiController::backupAppConfig(const QString &fileName)
|
||||||
{
|
{
|
||||||
QByteArray data = m_settingsController->backupAppConfig();
|
QByteArray data = m_settingsController->backupAppConfig();
|
||||||
SystemController::saveFile(fileName, data);
|
if (!SystemController::saveFile(fileName, data)) {
|
||||||
|
qInfo() << "SettingsUiController::backupAppConfig: save or share was cancelled or failed";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SettingsUiController::restoreAppConfig(const QString &fileName)
|
void SettingsUiController::restoreAppConfig(const QString &fileName)
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
#include "systemController.h"
|
#include "systemController.h"
|
||||||
|
|
||||||
|
#include <QDebug>
|
||||||
#include <QDesktopServices>
|
#include <QDesktopServices>
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
#include <QEventLoop>
|
#include <QEventLoop>
|
||||||
@@ -24,11 +25,20 @@ SystemController::SystemController(QObject *parent)
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void SystemController::saveFile(const QString &fileName, const QString &data)
|
bool SystemController::saveFile(const QString &fileName, const QString &data)
|
||||||
{
|
{
|
||||||
#if defined Q_OS_ANDROID
|
#if defined Q_OS_ANDROID
|
||||||
AndroidController::instance()->saveFile(fileName, data);
|
AndroidController::instance()->saveFile(fileName, data);
|
||||||
return;
|
return true;
|
||||||
|
#endif
|
||||||
|
return saveFile(fileName, data.toUtf8());
|
||||||
|
}
|
||||||
|
|
||||||
|
bool SystemController::saveFile(const QString &fileName, const QByteArray &data)
|
||||||
|
{
|
||||||
|
#if defined Q_OS_ANDROID
|
||||||
|
AndroidController::instance()->saveFile(fileName, QString::fromUtf8(data));
|
||||||
|
return true;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef Q_OS_IOS
|
#ifdef Q_OS_IOS
|
||||||
@@ -39,17 +49,20 @@ void SystemController::saveFile(const QString &fileName, const QString &data)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (!file.open(QIODevice::WriteOnly)) {
|
if (!file.open(QIODevice::WriteOnly)) {
|
||||||
return;
|
qWarning() << "SystemController::saveFile: cannot open" << fileName;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (file.write(data) != data.size()) {
|
||||||
|
qWarning() << "SystemController::saveFile: write failed" << fileName;
|
||||||
|
file.close();
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
file.write(data.toUtf8());
|
|
||||||
file.close();
|
file.close();
|
||||||
|
|
||||||
#ifdef Q_OS_IOS
|
#ifdef Q_OS_IOS
|
||||||
QStringList filesToSend;
|
QStringList filesToSend;
|
||||||
filesToSend.append(fileUrl.toString());
|
filesToSend.append(fileUrl.toString());
|
||||||
// todo check if save successful
|
return IosController::Instance()->shareText(filesToSend);
|
||||||
IosController::Instance()->shareText(filesToSend);
|
|
||||||
return;
|
|
||||||
#else
|
#else
|
||||||
QFileInfo fi(fileName);
|
QFileInfo fi(fileName);
|
||||||
|
|
||||||
@@ -62,6 +75,7 @@ void SystemController::saveFile(const QString &fileName, const QString &data)
|
|||||||
#ifndef MACOS_NE
|
#ifndef MACOS_NE
|
||||||
QDesktopServices::openUrl(url);
|
QDesktopServices::openUrl(url);
|
||||||
#endif
|
#endif
|
||||||
|
return true;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
#ifndef SYSTEMCONTROLLER_H
|
#ifndef SYSTEMCONTROLLER_H
|
||||||
#define SYSTEMCONTROLLER_H
|
#define SYSTEMCONTROLLER_H
|
||||||
|
|
||||||
|
#include <QByteArray>
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
|
|
||||||
class SystemController : public QObject
|
class SystemController : public QObject
|
||||||
@@ -9,7 +10,8 @@ class SystemController : public QObject
|
|||||||
public:
|
public:
|
||||||
explicit SystemController(QObject *parent = nullptr);
|
explicit SystemController(QObject *parent = nullptr);
|
||||||
|
|
||||||
static void saveFile(const QString &fileName, const QString &data);
|
static bool saveFile(const QString &fileName, const QString &data);
|
||||||
|
static bool saveFile(const QString &fileName, const QByteArray &data);
|
||||||
static bool readFile(const QString &fileName, QByteArray &data);
|
static bool readFile(const QString &fileName, QByteArray &data);
|
||||||
static bool readFile(const QString &fileName, QString &data);
|
static bool readFile(const QString &fileName, QString &data);
|
||||||
|
|
||||||
|
|||||||
@@ -192,9 +192,6 @@ PageType {
|
|||||||
if (fileName !== "") {
|
if (fileName !== "") {
|
||||||
PageController.showBusyIndicator(true)
|
PageController.showBusyIndicator(true)
|
||||||
let result = SubscriptionUiController.exportNativeConfig(ServersUiController.getProcessedServerIndex(), countryCode, fileName)
|
let result = SubscriptionUiController.exportNativeConfig(ServersUiController.getProcessedServerIndex(), countryCode, fileName)
|
||||||
if (result) {
|
|
||||||
SubscriptionUiController.getAccountInfo(ServersUiController.getProcessedServerIndex(), true)
|
|
||||||
}
|
|
||||||
|
|
||||||
PageController.showBusyIndicator(false)
|
PageController.showBusyIndicator(false)
|
||||||
if (result) {
|
if (result) {
|
||||||
|
|||||||
@@ -119,8 +119,11 @@ PageType {
|
|||||||
|
|
||||||
if (fileName !== "") {
|
if (fileName !== "") {
|
||||||
PageController.showBusyIndicator(true)
|
PageController.showBusyIndicator(true)
|
||||||
SubscriptionUiController.exportVpnKey(ServersUiController.getProcessedServerIndex(), fileName)
|
let ok = SubscriptionUiController.exportVpnKey(ServersUiController.getProcessedServerIndex(), fileName)
|
||||||
PageController.showBusyIndicator(false)
|
PageController.showBusyIndicator(false)
|
||||||
|
if (ok) {
|
||||||
|
PageController.showNotificationMessage(qsTr("Config file saved"))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user