From 6bbad2a3b681b25943d1c375e4d8563d495d5aa8 Mon Sep 17 00:00:00 2001 From: uncor3 Date: Wed, 1 Oct 2025 15:10:40 +0000 Subject: [PATCH] WIP: enchance device pairing process - Introduced devicePasswordProtected signal in AppContext to notify when a device is password protected. - Modified DeviceManagerWidget to handle devicePasswordProtected signal and update pending device state accordingly. - Enhanced DevicePendingWidget to display appropriate messages based on device lock status. --- src/appcontext.cpp | 7 +++++-- src/appcontext.h | 1 + src/devicemanagerwidget.cpp | 27 +++++++++++++++++++++++---- src/devicemanagerwidget.h | 2 +- src/devicependingwidget.cpp | 14 +++++++++++--- src/devicependingwidget.h | 8 ++++++-- 6 files changed, 47 insertions(+), 12 deletions(-) diff --git a/src/appcontext.cpp b/src/appcontext.cpp index 9e78da4..95dc99a 100644 --- a/src/appcontext.cpp +++ b/src/appcontext.cpp @@ -83,8 +83,11 @@ void AppContext::addDevice(QString udid, idevice_connection_type conn_type, // because it's less likely that it will be an error typeof // LOCKDOWN_E_PASSWORD_PROTECTED if the device is paired type if (addType == AddType::Regular) { // TODO:IMPLEMENT - // emit devicePasswordProtected(udid); - }; + // FIXME: if a device never gets paired, it will stay in + // this + m_pendingDevices.append(udid); + emit devicePasswordProtected(udid); + } } else if (initResult.error == LOCKDOWN_E_PAIRING_DIALOG_RESPONSE_PENDING) { m_pendingDevices.append(udid); diff --git a/src/appcontext.h b/src/appcontext.h index 23f10b4..dbff59d 100644 --- a/src/appcontext.h +++ b/src/appcontext.h @@ -36,6 +36,7 @@ signals: void deviceAdded(iDescriptorDevice *device); void deviceRemoved(const std::string &udid); void devicePaired(iDescriptorDevice *device); + void devicePasswordProtected(const QString &udid); void recoveryDeviceAdded(RecoveryDeviceInfo *deviceInfo); void recoveryDeviceRemoved(const QString &udid); void devicePairPending(const QString &udid); diff --git a/src/devicemanagerwidget.cpp b/src/devicemanagerwidget.cpp index 6e32da3..9139605 100644 --- a/src/devicemanagerwidget.cpp +++ b/src/devicemanagerwidget.cpp @@ -1,6 +1,7 @@ #include "devicemanagerwidget.h" #include "appcontext.h" #include "devicemenuwidget.h" +#include "devicependingwidget.h" #include DeviceManagerWidget::DeviceManagerWidget(QWidget *parent) @@ -23,7 +24,13 @@ DeviceManagerWidget::DeviceManagerWidget(QWidget *parent) connect(AppContext::sharedInstance(), &AppContext::devicePairPending, this, [this](const QString &udid) { - addPendingDevice(udid); + addPendingDevice(udid, false); + emit updateNoDevicesConnected(); + }); + + connect(AppContext::sharedInstance(), &AppContext::devicePasswordProtected, + this, [this](const QString &udid) { + addPendingDevice(udid, true); emit updateNoDevicesConnected(); }); @@ -99,12 +106,24 @@ void DeviceManagerWidget::addDevice(iDescriptorDevice *device) // } } -void DeviceManagerWidget::addPendingDevice(const QString &udid) +void DeviceManagerWidget::addPendingDevice(const QString &udid, bool locked) { qDebug() << "Adding pending device:" << udid; + if (m_pendingDeviceWidgets.contains(udid.toStdString()) && !locked) { + qDebug() << "Pending device already exists, moving to next state:" + << udid; + m_pendingDeviceWidgets[udid.toStdString()].first->next(); + return; + } else if (m_pendingDeviceWidgets.contains(udid.toStdString()) && locked) { + // Already exists and still locked, do nothing + qDebug() + << "Pending device already exists and is locked, doing nothing:" + << udid; + return; + } - DevicePendingWidget *pendingWidget = new DevicePendingWidget(this); - + qDebug() << "Created pending widget for:" << udid << "Locked:" << locked; + DevicePendingWidget *pendingWidget = new DevicePendingWidget(locked, this); m_stackedWidget->addWidget(pendingWidget); m_pendingDeviceWidgets[udid.toStdString()] = std::pair{pendingWidget, m_sidebar->addPendingToSidebar(udid)}; diff --git a/src/devicemanagerwidget.h b/src/devicemanagerwidget.h index 6dde9e6..5323c77 100644 --- a/src/devicemanagerwidget.h +++ b/src/devicemanagerwidget.h @@ -19,7 +19,7 @@ public: void addDevice(iDescriptorDevice *device); // TODO:udid or uuid ? - void addPendingDevice(const QString &udid); + void addPendingDevice(const QString &udid, bool locked); void addPairedDevice(iDescriptorDevice *device); void removeDevice(const std::string &uuid); diff --git a/src/devicependingwidget.cpp b/src/devicependingwidget.cpp index b186257..0b54387 100644 --- a/src/devicependingwidget.cpp +++ b/src/devicependingwidget.cpp @@ -2,14 +2,22 @@ #include #include -DevicePendingWidget::DevicePendingWidget(QWidget *parent) : QWidget{parent} +DevicePendingWidget::DevicePendingWidget(bool locked, QWidget *parent) + : QWidget{parent}, m_label{nullptr}, m_locked{locked} { QVBoxLayout *layout = new QVBoxLayout(this); layout->setContentsMargins(0, 0, 0, 0); layout->setSpacing(5); - QLabel *label = new QLabel("Please click on trust on the popup", this); + m_label = new QLabel(m_locked ? "Please unlock the screen" + : "Please click on trust on the popup", + this); - layout->addWidget(label); + layout->addWidget(m_label); setLayout(layout); } + +void DevicePendingWidget::next() +{ + m_label->setText("Please click on trust on the popup"); +} \ No newline at end of file diff --git a/src/devicependingwidget.h b/src/devicependingwidget.h index 9cd43e8..4d8e355 100644 --- a/src/devicependingwidget.h +++ b/src/devicependingwidget.h @@ -1,15 +1,19 @@ #ifndef DEVICEPENDINGWIDGET_H #define DEVICEPENDINGWIDGET_H +#include #include class DevicePendingWidget : public QWidget { Q_OBJECT public: - explicit DevicePendingWidget(QWidget *parent = nullptr); - + explicit DevicePendingWidget(bool locked, QWidget *parent); + void next(); signals: +private: + QLabel *m_label; + bool m_locked; }; #endif // DEVICEPENDINGWIDGET_H