add error 1123 & fix update qr code & fix hide qr code

This commit is contained in:
dranik
2026-05-20 11:46:21 +03:00
parent 9c9e1700af
commit c327d3e3c8
9 changed files with 63 additions and 8 deletions
@@ -78,6 +78,11 @@ ErrorCode applyGatewayOrOpenApiScanError(const QJsonObject &obj)
}
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)) {
return ErrorCode::ApiNotFoundError;
}
+15
View File
@@ -153,6 +153,21 @@ amnezia::ErrorCode apiUtils::checkNetworkReplyErrors(const QList<QSslError> &ssl
if (httpStatusFromBody == httpStatusCodePaymentRequired) {
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;
}
+1
View File
@@ -106,6 +106,7 @@ namespace amnezia
ApiPairingServiceUnavailableError = 1120,
ApiPairingPayloadTooLargeError = 1121,
ApiPairingMissingMetadataError = 1122,
ApiPairingSessionExpiredError = 1123,
// QFile errors
OpenError = 1200,
+1
View File
@@ -90,6 +90,7 @@ QString errorString(ErrorCode code) {
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::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
case(ErrorCode::OpenError): errorMessage = QObject::tr("QFile error: The file could not be opened"); break;
+9
View File
@@ -108,6 +108,15 @@ private slots:
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()
{
QString vpnKey;
@@ -435,12 +435,24 @@ void PairingUiController::startTvQrSession()
if (m_tvPairingBusy) {
return;
}
rotateTvQrSession();
}
void PairingUiController::rotateTvQrSession()
{
if (!m_pairingController || !m_appSettingsRepository) {
return;
}
if (m_tvWatcher) {
m_tvWatcher->disconnect();
m_tvWatcher->deleteLater();
m_tvWatcher.clear();
}
if (m_tvNetworkReply) {
m_tvNetworkReply->abort();
m_tvNetworkReply.clear();
}
++m_tvSessionGeneration;
const quint64 generation = m_tvSessionGeneration;
@@ -505,6 +517,11 @@ void PairingUiController::dispatchTvGenerateQrAttempt(quint64 generation, int re
setTvBusy(false);
if (impErr != ErrorCode::NoError) {
emit errorOccurred(impErr);
if (impErr == ErrorCode::ApiConfigAlreadyAdded) {
emit tvPairingConfigAlreadyAdded();
QTimer::singleShot(0, this, [this]() { rotateTvQrSession(); });
return;
}
resetTvQrDisplay();
return;
}
@@ -526,7 +543,7 @@ void PairingUiController::dispatchTvGenerateQrAttempt(quint64 generation, int re
if (logicalErr == ErrorCode::ApiConfigTimeoutError) {
setTvBusy(false);
QTimer::singleShot(0, this, [this]() { startTvQrSession(); });
QTimer::singleShot(0, this, [this]() { rotateTvQrSession(); });
return;
}
@@ -62,6 +62,8 @@ public:
public slots:
bool canOpenTvQrPairingPage();
void startTvQrSession();
/** New UUID + QR image; aborts in-flight generate_qr without clearing the code first. */
void rotateTvQrSession();
void cancelTvQrSession();
void cancelAllPairingActivity();
@@ -84,6 +86,7 @@ signals:
void lastSuccessfulPhonePairingDisplayNameChanged();
void tvPairingConfigReceived();
void tvPairingConfigAlreadyAdded();
void phonePairingSucceeded();
void pairingUuidFromScan(const QString &uuid);
@@ -109,16 +109,16 @@ PageType {
}
function onPhonePairingSucceeded() {
if (!root.visible) {
return
}
SubscriptionUiController.updateApiDevicesModel()
const label = PairingUiController.lastSuccessfulPhonePairingDisplayName
if (label.length > 0) {
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 {
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
running: root.visible
onTriggered: {
PairingUiController.cancelTvQrSession()
PairingUiController.startTvQrSession()
PairingUiController.rotateTvQrSession()
}
}
@@ -184,5 +183,10 @@ PageType {
PageController.closePage()
})
}
function onTvPairingConfigAlreadyAdded() {
scrollToBottomRetryTimer.stop()
qrRotationTimer.restart()
}
}
}