mirror of
https://github.com/amnezia-vpn/amnezia-client.git
synced 2026-06-24 02:00:24 +07:00
add error 1123 & fix update qr code & fix hide qr code
This commit is contained in:
@@ -78,6 +78,11 @@ ErrorCode applyGatewayOrOpenApiScanError(const QJsonObject &obj)
|
|||||||
}
|
}
|
||||||
|
|
||||||
const QString msg = obj.value(QStringLiteral("message")).toString();
|
const QString msg = obj.value(QStringLiteral("message")).toString();
|
||||||
|
if (msg.contains(QStringLiteral("QR session"), Qt::CaseInsensitive)
|
||||||
|
&& (msg.contains(QStringLiteral("not found"), Qt::CaseInsensitive)
|
||||||
|
|| msg.contains(QStringLiteral("expired"), Qt::CaseInsensitive))) {
|
||||||
|
return ErrorCode::ApiPairingSessionExpiredError;
|
||||||
|
}
|
||||||
if (msg.contains(QStringLiteral("not found"), Qt::CaseInsensitive) || msg.contains(QStringLiteral("expired"), Qt::CaseInsensitive)) {
|
if (msg.contains(QStringLiteral("not found"), Qt::CaseInsensitive) || msg.contains(QStringLiteral("expired"), Qt::CaseInsensitive)) {
|
||||||
return ErrorCode::ApiNotFoundError;
|
return ErrorCode::ApiNotFoundError;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -153,6 +153,21 @@ amnezia::ErrorCode apiUtils::checkNetworkReplyErrors(const QList<QSslError> &ssl
|
|||||||
if (httpStatusFromBody == httpStatusCodePaymentRequired) {
|
if (httpStatusFromBody == httpStatusCodePaymentRequired) {
|
||||||
return amnezia::ErrorCode::ApiSubscriptionNotActiveError;
|
return amnezia::ErrorCode::ApiSubscriptionNotActiveError;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const QString msg = apiErrorMessageFromJson(jsonObj);
|
||||||
|
if (msg.contains(QStringLiteral("QR session"), Qt::CaseInsensitive)
|
||||||
|
&& (msg.contains(QStringLiteral("not found"), Qt::CaseInsensitive)
|
||||||
|
|| msg.contains(QStringLiteral("expired"), Qt::CaseInsensitive))) {
|
||||||
|
return amnezia::ErrorCode::ApiPairingSessionExpiredError;
|
||||||
|
}
|
||||||
|
if (msg.contains(QStringLiteral("not found"), Qt::CaseInsensitive)
|
||||||
|
|| msg.contains(QStringLiteral("expired"), Qt::CaseInsensitive)) {
|
||||||
|
return amnezia::ErrorCode::ApiNotFoundError;
|
||||||
|
}
|
||||||
|
if (httpStatusCode == httpStatusCodeNotFound) {
|
||||||
|
return amnezia::ErrorCode::ApiNotFoundError;
|
||||||
|
}
|
||||||
|
|
||||||
return amnezia::ErrorCode::ApiConfigDownloadError;
|
return amnezia::ErrorCode::ApiConfigDownloadError;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -106,6 +106,7 @@ namespace amnezia
|
|||||||
ApiPairingServiceUnavailableError = 1120,
|
ApiPairingServiceUnavailableError = 1120,
|
||||||
ApiPairingPayloadTooLargeError = 1121,
|
ApiPairingPayloadTooLargeError = 1121,
|
||||||
ApiPairingMissingMetadataError = 1122,
|
ApiPairingMissingMetadataError = 1122,
|
||||||
|
ApiPairingSessionExpiredError = 1123,
|
||||||
|
|
||||||
// QFile errors
|
// QFile errors
|
||||||
OpenError = 1200,
|
OpenError = 1200,
|
||||||
|
|||||||
@@ -90,6 +90,7 @@ QString errorString(ErrorCode code) {
|
|||||||
case (ErrorCode::ApiPairingServiceUnavailableError): errorMessage = QObject::tr("Service temporarily unavailable. Please try again later"); break;
|
case (ErrorCode::ApiPairingServiceUnavailableError): errorMessage = QObject::tr("Service temporarily unavailable. Please try again later"); break;
|
||||||
case (ErrorCode::ApiPairingPayloadTooLargeError): errorMessage = QObject::tr("QR pairing data is too large to send"); break;
|
case (ErrorCode::ApiPairingPayloadTooLargeError): errorMessage = QObject::tr("QR pairing data is too large to send"); break;
|
||||||
case (ErrorCode::ApiPairingMissingMetadataError): errorMessage = QObject::tr("This subscription is missing data required to transfer via QR (service type or country). Refresh the subscription or pick another server."); break;
|
case (ErrorCode::ApiPairingMissingMetadataError): errorMessage = QObject::tr("This subscription is missing data required to transfer via QR (service type or country). Refresh the subscription or pick another server."); break;
|
||||||
|
case (ErrorCode::ApiPairingSessionExpiredError): errorMessage = QObject::tr("The QR code session has ended. Show a new QR code on the other device and scan again."); break;
|
||||||
|
|
||||||
// QFile errors
|
// QFile errors
|
||||||
case(ErrorCode::OpenError): errorMessage = QObject::tr("QFile error: The file could not be opened"); break;
|
case(ErrorCode::OpenError): errorMessage = QObject::tr("QFile error: The file could not be opened"); break;
|
||||||
|
|||||||
@@ -108,6 +108,15 @@ private slots:
|
|||||||
QCOMPARE(PairingController::parseScanQrResponseBody(body), ErrorCode::ApiNotFoundError);
|
QCOMPARE(PairingController::parseScanQrResponseBody(body), ErrorCode::ApiNotFoundError);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void scanQr_qrSessionExpiredMessage()
|
||||||
|
{
|
||||||
|
QJsonObject o;
|
||||||
|
o[QStringLiteral("message")] = QStringLiteral("QR session not found or expired");
|
||||||
|
const QByteArray body = QJsonDocument(o).toJson();
|
||||||
|
|
||||||
|
QCOMPARE(PairingController::parseScanQrResponseBody(body), ErrorCode::ApiPairingSessionExpiredError);
|
||||||
|
}
|
||||||
|
|
||||||
void validateScanFields_oversizedVpnKey()
|
void validateScanFields_oversizedVpnKey()
|
||||||
{
|
{
|
||||||
QString vpnKey;
|
QString vpnKey;
|
||||||
|
|||||||
@@ -435,12 +435,24 @@ void PairingUiController::startTvQrSession()
|
|||||||
if (m_tvPairingBusy) {
|
if (m_tvPairingBusy) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
rotateTvQrSession();
|
||||||
|
}
|
||||||
|
|
||||||
|
void PairingUiController::rotateTvQrSession()
|
||||||
|
{
|
||||||
|
if (!m_pairingController || !m_appSettingsRepository) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (m_tvWatcher) {
|
if (m_tvWatcher) {
|
||||||
m_tvWatcher->disconnect();
|
m_tvWatcher->disconnect();
|
||||||
m_tvWatcher->deleteLater();
|
m_tvWatcher->deleteLater();
|
||||||
m_tvWatcher.clear();
|
m_tvWatcher.clear();
|
||||||
}
|
}
|
||||||
|
if (m_tvNetworkReply) {
|
||||||
|
m_tvNetworkReply->abort();
|
||||||
|
m_tvNetworkReply.clear();
|
||||||
|
}
|
||||||
|
|
||||||
++m_tvSessionGeneration;
|
++m_tvSessionGeneration;
|
||||||
const quint64 generation = m_tvSessionGeneration;
|
const quint64 generation = m_tvSessionGeneration;
|
||||||
@@ -505,6 +517,11 @@ void PairingUiController::dispatchTvGenerateQrAttempt(quint64 generation, int re
|
|||||||
setTvBusy(false);
|
setTvBusy(false);
|
||||||
if (impErr != ErrorCode::NoError) {
|
if (impErr != ErrorCode::NoError) {
|
||||||
emit errorOccurred(impErr);
|
emit errorOccurred(impErr);
|
||||||
|
if (impErr == ErrorCode::ApiConfigAlreadyAdded) {
|
||||||
|
emit tvPairingConfigAlreadyAdded();
|
||||||
|
QTimer::singleShot(0, this, [this]() { rotateTvQrSession(); });
|
||||||
|
return;
|
||||||
|
}
|
||||||
resetTvQrDisplay();
|
resetTvQrDisplay();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -526,7 +543,7 @@ void PairingUiController::dispatchTvGenerateQrAttempt(quint64 generation, int re
|
|||||||
|
|
||||||
if (logicalErr == ErrorCode::ApiConfigTimeoutError) {
|
if (logicalErr == ErrorCode::ApiConfigTimeoutError) {
|
||||||
setTvBusy(false);
|
setTvBusy(false);
|
||||||
QTimer::singleShot(0, this, [this]() { startTvQrSession(); });
|
QTimer::singleShot(0, this, [this]() { rotateTvQrSession(); });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -62,6 +62,8 @@ public:
|
|||||||
public slots:
|
public slots:
|
||||||
bool canOpenTvQrPairingPage();
|
bool canOpenTvQrPairingPage();
|
||||||
void startTvQrSession();
|
void startTvQrSession();
|
||||||
|
/** New UUID + QR image; aborts in-flight generate_qr without clearing the code first. */
|
||||||
|
void rotateTvQrSession();
|
||||||
void cancelTvQrSession();
|
void cancelTvQrSession();
|
||||||
void cancelAllPairingActivity();
|
void cancelAllPairingActivity();
|
||||||
|
|
||||||
@@ -84,6 +86,7 @@ signals:
|
|||||||
void lastSuccessfulPhonePairingDisplayNameChanged();
|
void lastSuccessfulPhonePairingDisplayNameChanged();
|
||||||
|
|
||||||
void tvPairingConfigReceived();
|
void tvPairingConfigReceived();
|
||||||
|
void tvPairingConfigAlreadyAdded();
|
||||||
void phonePairingSucceeded();
|
void phonePairingSucceeded();
|
||||||
|
|
||||||
void pairingUuidFromScan(const QString &uuid);
|
void pairingUuidFromScan(const QString &uuid);
|
||||||
|
|||||||
@@ -109,16 +109,16 @@ PageType {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function onPhonePairingSucceeded() {
|
function onPhonePairingSucceeded() {
|
||||||
if (!root.visible) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
SubscriptionUiController.updateApiDevicesModel()
|
SubscriptionUiController.updateApiDevicesModel()
|
||||||
const label = PairingUiController.lastSuccessfulPhonePairingDisplayName
|
const label = PairingUiController.lastSuccessfulPhonePairingDisplayName
|
||||||
if (label.length > 0) {
|
if (label.length > 0) {
|
||||||
PageController.showNotificationMessage(
|
PageController.showNotificationMessage(
|
||||||
qsTr("%1 has been added to your subscription").arg(label))
|
qsTr("Configuration was sent (%1). Finish setup on the device that displayed the QR code — "
|
||||||
|
+ "if it already has this config, that device will show a message.").arg(label))
|
||||||
} else {
|
} else {
|
||||||
PageController.showNotificationMessage(qsTr("New device has been added to your subscription"))
|
PageController.showNotificationMessage(
|
||||||
|
qsTr("Configuration was sent to the device that displayed the QR code. "
|
||||||
|
+ "If it already has this config, that device will show a message."))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -48,8 +48,7 @@ PageType {
|
|||||||
repeat: true
|
repeat: true
|
||||||
running: root.visible
|
running: root.visible
|
||||||
onTriggered: {
|
onTriggered: {
|
||||||
PairingUiController.cancelTvQrSession()
|
PairingUiController.rotateTvQrSession()
|
||||||
PairingUiController.startTvQrSession()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -184,5 +183,10 @@ PageType {
|
|||||||
PageController.closePage()
|
PageController.closePage()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function onTvPairingConfigAlreadyAdded() {
|
||||||
|
scrollToBottomRetryTimer.stop()
|
||||||
|
qrRotationTimer.restart()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user