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
|
||||
UIViewController *qtController = getViewController();
|
||||
if (!qtController) return;
|
||||
if (!qtController) {
|
||||
return false;
|
||||
}
|
||||
|
||||
UIActivityViewController *activityController = [[UIActivityViewController alloc] initWithActivityItems:sharingItems applicationActivities:nil];
|
||||
#endif
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#include "allowedDnsUiController.h"
|
||||
|
||||
#include <QDebug>
|
||||
#include <QFile>
|
||||
#include <QStandardPaths>
|
||||
#include <QJsonDocument>
|
||||
@@ -98,7 +99,10 @@ void AllowedDnsUiController::exportDns(const QString &fileName)
|
||||
QJsonDocument jsonDocument(jsonArray);
|
||||
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"));
|
||||
}
|
||||
|
||||
@@ -89,8 +89,7 @@ bool SubscriptionUiController::exportVpnKey(int serverIndex, const QString &file
|
||||
return false;
|
||||
}
|
||||
|
||||
SystemController::saveFile(fileName, m_vpnKey);
|
||||
return true;
|
||||
return SystemController::saveFile(fileName, m_vpnKey);
|
||||
}
|
||||
|
||||
bool SubscriptionUiController::exportNativeConfig(int serverIndex, const QString &serverCountryCode, const QString &fileName)
|
||||
@@ -107,8 +106,9 @@ bool SubscriptionUiController::exportNativeConfig(int serverIndex, const QString
|
||||
return false;
|
||||
}
|
||||
|
||||
SystemController::saveFile(fileName, nativeConfig);
|
||||
return true;
|
||||
const bool saved = SystemController::saveFile(fileName, nativeConfig);
|
||||
getAccountInfo(serverIndex, true);
|
||||
return saved;
|
||||
}
|
||||
|
||||
bool SubscriptionUiController::revokeNativeConfig(int serverIndex, const QString &serverCountryCode)
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
#include "ipSplitTunnelingUiController.h"
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
#include "systemController.h"
|
||||
#include "core/utils/errorCodes.h"
|
||||
#include "core/utils/routeModes.h"
|
||||
@@ -55,7 +57,10 @@ void IpSplitTunnelingUiController::importSites(const QString &fileName, bool rep
|
||||
void IpSplitTunnelingUiController::exportSites(const QString &fileName)
|
||||
{
|
||||
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"));
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
#include "exportUiController.h"
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
#include "../systemController.h"
|
||||
|
||||
ExportUiController::ExportUiController(ExportController* exportController, QObject *parent)
|
||||
@@ -68,7 +70,9 @@ QList<QString> ExportUiController::getQrCodes()
|
||||
|
||||
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)
|
||||
|
||||
@@ -107,7 +107,9 @@ void SettingsUiController::exportLogsFile(const QString &fileName)
|
||||
#ifdef Q_OS_ANDROID
|
||||
AndroidController::instance()->exportLogsFile(fileName);
|
||||
#else
|
||||
SystemController::saveFile(fileName, Logger::getLogFile());
|
||||
if (!SystemController::saveFile(fileName, Logger::getLogFile())) {
|
||||
qInfo() << "SettingsUiController::exportLogsFile: save or share was cancelled or failed";
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -116,7 +118,9 @@ void SettingsUiController::exportServiceLogsFile(const QString &fileName)
|
||||
#ifdef Q_OS_ANDROID
|
||||
AndroidController::instance()->exportLogsFile(fileName);
|
||||
#else
|
||||
SystemController::saveFile(fileName, Logger::getServiceLogFile());
|
||||
if (!SystemController::saveFile(fileName, Logger::getServiceLogFile())) {
|
||||
qInfo() << "SettingsUiController::exportServiceLogsFile: save or share was cancelled or failed";
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -132,7 +136,9 @@ void SettingsUiController::clearLogs()
|
||||
void SettingsUiController::backupAppConfig(const QString &fileName)
|
||||
{
|
||||
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)
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#include "systemController.h"
|
||||
|
||||
#include <QDebug>
|
||||
#include <QDesktopServices>
|
||||
#include <QDir>
|
||||
#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
|
||||
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
|
||||
|
||||
#ifdef Q_OS_IOS
|
||||
@@ -39,17 +49,20 @@ void SystemController::saveFile(const QString &fileName, const QString &data)
|
||||
#endif
|
||||
|
||||
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();
|
||||
|
||||
#ifdef Q_OS_IOS
|
||||
QStringList filesToSend;
|
||||
filesToSend.append(fileUrl.toString());
|
||||
// todo check if save successful
|
||||
IosController::Instance()->shareText(filesToSend);
|
||||
return;
|
||||
return IosController::Instance()->shareText(filesToSend);
|
||||
#else
|
||||
QFileInfo fi(fileName);
|
||||
|
||||
@@ -62,6 +75,7 @@ void SystemController::saveFile(const QString &fileName, const QString &data)
|
||||
#ifndef MACOS_NE
|
||||
QDesktopServices::openUrl(url);
|
||||
#endif
|
||||
return true;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#ifndef SYSTEMCONTROLLER_H
|
||||
#define SYSTEMCONTROLLER_H
|
||||
|
||||
#include <QByteArray>
|
||||
#include <QObject>
|
||||
|
||||
class SystemController : public QObject
|
||||
@@ -9,7 +10,8 @@ class SystemController : public QObject
|
||||
public:
|
||||
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, QString &data);
|
||||
|
||||
|
||||
@@ -192,9 +192,6 @@ PageType {
|
||||
if (fileName !== "") {
|
||||
PageController.showBusyIndicator(true)
|
||||
let result = SubscriptionUiController.exportNativeConfig(ServersUiController.getProcessedServerIndex(), countryCode, fileName)
|
||||
if (result) {
|
||||
SubscriptionUiController.getAccountInfo(ServersUiController.getProcessedServerIndex(), true)
|
||||
}
|
||||
|
||||
PageController.showBusyIndicator(false)
|
||||
if (result) {
|
||||
|
||||
@@ -119,8 +119,11 @@ PageType {
|
||||
|
||||
if (fileName !== "") {
|
||||
PageController.showBusyIndicator(true)
|
||||
SubscriptionUiController.exportVpnKey(ServersUiController.getProcessedServerIndex(), fileName)
|
||||
let ok = SubscriptionUiController.exportVpnKey(ServersUiController.getProcessedServerIndex(), fileName)
|
||||
PageController.showBusyIndicator(false)
|
||||
if (ok) {
|
||||
PageController.showNotificationMessage(qsTr("Config file saved"))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user