add test scaner ios

This commit is contained in:
dranik
2026-05-08 22:36:53 +03:00
parent b7e2847393
commit d2d3545961
9 changed files with 969 additions and 9 deletions
@@ -8,8 +8,12 @@
#include <QRegularExpression>
#include <QTimer>
#include <QUuid>
#include <string>
#include "platforms/ios/iosPairingCameraAccess.h"
#if defined(Q_OS_IOS)
#include "platforms/ios/iosPairingQrOverlayWindow.h"
#endif
#if defined(Q_OS_ANDROID)
#include "platforms/android/android_controller.h"
@@ -100,6 +104,15 @@ PairingUiController *g_pairingUiForAndroidQr = nullptr;
}
#endif
bool PairingUiController::iosNativePairingQrOverlayBuild() const
{
#if defined(Q_OS_IOS)
return true;
#else
return false;
#endif
}
PairingUiController::PairingUiController(PairingController *pairingController, ServersController *serversController,
SubscriptionController *subscriptionController,
SecureAppSettingsRepository *appSettingsRepository, QObject *parent)
@@ -123,6 +136,9 @@ PairingUiController::~PairingUiController()
g_pairingUiForAndroidQr = nullptr;
}
#endif
#if defined(Q_OS_IOS)
amneziaIosPairingQrOverlayDismiss();
#endif
}
void PairingUiController::setPendingPhonePairingUuid(const QString &uuid)
@@ -227,15 +243,78 @@ void PairingUiController::syncIosEmbeddedPairingQrNativeBottomExtra(int extraPt)
#endif
}
void PairingUiController::refreshIosEmbeddedPairingQrChrome()
{
#if defined(Q_OS_IOS)
if (!m_embeddedPairingQrCameraActive) {
return;
}
qInfo() << "[PairingUi] refreshIosEmbeddedPairingQrChrome (reapply UIView underlay)";
amneziaIosApplyEmbeddedCameraUnderlayToQtView(true);
#else
// no-op on non-iOS
#endif
}
void PairingUiController::setPairingQrTorchEnabled(bool enabled)
{
#if defined(Q_OS_ANDROID)
AndroidController::instance()->setPairingQrEmbeddedTorch(enabled);
#elif defined(Q_OS_IOS)
amneziaIosPairingQrOverlaySetTorchEnabled(enabled);
#else
Q_UNUSED(enabled);
#endif
}
void PairingUiController::presentIosPairingQrNativeOverlayScanner(const QString &title, const QString &subtitle)
{
#if defined(Q_OS_IOS)
qInfo() << "[PairingUi] presentIosPairingQrNativeOverlayScanner: scheduling native UIWindow overlay";
const std::string titleUtf8 = title.isEmpty() ? std::string() : title.toStdString();
const std::string subtitleUtf8 = subtitle.isEmpty() ? std::string() : subtitle.toStdString();
amneziaIosPairingQrOverlayPresent(
[this](const char *utf8) {
const QString code = QString::fromUtf8(utf8);
QMetaObject::invokeMethod(
this,
[this, code]() {
if (!applyScannedTextAsPairingUuid(code)) {
emit pairingSendQrScanRejectedInvalidPayload();
}
},
Qt::QueuedConnection);
},
[this]() {
QMetaObject::invokeMethod(
this,
[this]() { emit pairingIosNativeQrOverlayBackRequested(); },
Qt::QueuedConnection);
},
titleUtf8, subtitleUtf8);
#else
Q_UNUSED(title);
Q_UNUSED(subtitle);
qInfo() << "[PairingUi] presentIosPairingQrNativeOverlayScanner: no-op (not iOS build)";
#endif
}
void PairingUiController::dismissIosPairingQrNativeOverlayScanner()
{
#if defined(Q_OS_IOS)
qInfo() << "[PairingUi] dismissIosPairingQrNativeOverlayScanner";
amneziaIosPairingQrOverlayDismiss();
#endif
}
void PairingUiController::restartIosPairingQrNativeOverlayCapture()
{
#if defined(Q_OS_IOS)
qInfo() << "[PairingUi] restartIosPairingQrNativeOverlayCapture";
amneziaIosPairingQrOverlayRestartCapture();
#endif
}
bool PairingUiController::applyScannedTextAsPairingUuid(const QString &raw)
{
const QString t = raw.trimmed();
@@ -38,6 +38,8 @@ class PairingUiController : public QObject
/** Full-screen pairing QR camera under QML (mobile); drives translucent main window. */
Q_PROPERTY(bool embeddedPairingQrCameraActive READ embeddedPairingQrCameraActive WRITE setEmbeddedPairingQrCameraActive NOTIFY
embeddedPairingQrCameraActiveChanged)
/** True only on iOS builds: use native UIWindow QR overlay (not Qt.platform.os, which can differ). */
Q_PROPERTY(bool iosNativePairingQrOverlayBuild READ iosNativePairingQrOverlayBuild CONSTANT)
public:
PairingUiController(PairingController *pairingController, ServersController *serversController,
@@ -59,9 +61,25 @@ public:
QString lastSuccessfulPhonePairingDisplayName() const { return m_lastSuccessfulPhonePairingDisplayName; }
int tvPairingUiPhase() const { return m_tvPairingUiPhase; }
bool embeddedPairingQrCameraActive() const { return m_embeddedPairingQrCameraActive; }
bool iosNativePairingQrOverlayBuild() const;
Q_INVOKABLE void setEmbeddedPairingQrCameraActive(bool active);
/** iOS: native dim strip height uses safe bottom + extraPt (see PageSettingsApiQrPairingSend scanDimBleedBottom). No-op elsewhere. */
Q_INVOKABLE void syncIosEmbeddedPairingQrNativeBottomExtra(int extraPt);
/**
* iOS: reapply UIView transparency + safe-area dim strips when embedded pairing is already active.
* Needed after multitask resume: setEmbeddedPairingQrCameraActive(true) is a no-op if the flag stayed true,
* but QUIMetalView / hierarchy may have been rebuilt opaque so the camera only shows in the status bar band.
*/
Q_INVOKABLE void refreshIosEmbeddedPairingQrChrome();
/**
* iOS: UIKit UIWindow QR scanner (see iosPairingQrOverlayWindow). Pass translated title/subtitle for native chrome.
* No-op on other platforms.
*/
Q_INVOKABLE void presentIosPairingQrNativeOverlayScanner(const QString &title = QString(),
const QString &subtitle = QString());
Q_INVOKABLE void dismissIosPairingQrNativeOverlayScanner();
Q_INVOKABLE void restartIosPairingQrNativeOverlayCapture();
#if defined(Q_OS_ANDROID)
static bool tryConsumeAndroidQrScan(const QString &code);
@@ -116,6 +134,10 @@ signals:
/** After requestPairingCameraAccess(): true if OS granted camera access. */
void pairingCameraAccessFinished(bool granted);
void embeddedPairingQrCameraActiveChanged();
/** iOS native overlay scanner: payload was not a pairing session UUID (toast in QML). */
void pairingSendQrScanRejectedInvalidPayload();
/** Native overlay back chevron tapped — dismiss scanner and close page from QML. */
void pairingIosNativeQrOverlayBackRequested();
private:
void setTvBusy(bool busy);