mirror of
https://github.com/iDescriptor/iDescriptor.git
synced 2026-06-21 19:35:49 +08:00
feat(livescreen): enhance loading UI and error handling for screenshot capture
This commit is contained in:
+30
-23
@@ -18,19 +18,6 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "livescreenwidget.h"
|
#include "livescreenwidget.h"
|
||||||
#include "appcontext.h"
|
|
||||||
#include "devdiskimagehelper.h"
|
|
||||||
#include "devdiskmanager.h"
|
|
||||||
#include "iDescriptor.h"
|
|
||||||
#include <QDebug>
|
|
||||||
#include <QHBoxLayout>
|
|
||||||
#include <QLabel>
|
|
||||||
#include <QMessageBox>
|
|
||||||
#include <QPushButton>
|
|
||||||
#include <QSpinBox>
|
|
||||||
#include <QTimer>
|
|
||||||
#include <QTransform>
|
|
||||||
#include <QVBoxLayout>
|
|
||||||
|
|
||||||
LiveScreenWidget::LiveScreenWidget(
|
LiveScreenWidget::LiveScreenWidget(
|
||||||
const std::shared_ptr<iDescriptorDevice> device, QWidget *parent)
|
const std::shared_ptr<iDescriptorDevice> device, QWidget *parent)
|
||||||
@@ -47,21 +34,28 @@ LiveScreenWidget::LiveScreenWidget(
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Setup UI
|
|
||||||
QVBoxLayout *mainLayout = new QVBoxLayout(this);
|
QVBoxLayout *mainLayout = new QVBoxLayout(this);
|
||||||
mainLayout->setContentsMargins(10, 10, 10, 10);
|
mainLayout->setContentsMargins(0, 0, 0, 0);
|
||||||
mainLayout->setSpacing(10);
|
|
||||||
|
m_loadingWidget = new ZLoadingWidget(true, this);
|
||||||
|
mainLayout->addWidget(m_loadingWidget);
|
||||||
|
|
||||||
|
// Setup UI
|
||||||
|
QVBoxLayout *contentLayout = new QVBoxLayout(this);
|
||||||
|
contentLayout->setContentsMargins(10, 10, 10, 10);
|
||||||
|
contentLayout->setSpacing(10);
|
||||||
|
m_loadingWidget->setupContentWidget(contentLayout);
|
||||||
|
|
||||||
// Status label
|
// Status label
|
||||||
m_statusLabel = new QLabel("Connecting to screenshot service...");
|
m_statusLabel = new QLabel("Connecting to screenshot service...");
|
||||||
m_statusLabel->setAlignment(Qt::AlignCenter);
|
m_statusLabel->setAlignment(Qt::AlignCenter);
|
||||||
mainLayout->addWidget(m_statusLabel);
|
contentLayout->addWidget(m_statusLabel);
|
||||||
|
|
||||||
// Screenshot display
|
// Screenshot display
|
||||||
m_imageLabel = new QLabel();
|
m_imageLabel = new QLabel();
|
||||||
m_imageLabel->setMinimumSize(300, 600);
|
m_imageLabel->setMinimumSize(300, 600);
|
||||||
m_imageLabel->setAlignment(Qt::AlignCenter);
|
m_imageLabel->setAlignment(Qt::AlignCenter);
|
||||||
mainLayout->addWidget(m_imageLabel, 1);
|
contentLayout->addWidget(m_imageLabel, 1);
|
||||||
|
|
||||||
// Controls (rotate / mirror), initially hidden, shown when capturing starts
|
// Controls (rotate / mirror), initially hidden, shown when capturing starts
|
||||||
m_controlsWidget = new QWidget(this);
|
m_controlsWidget = new QWidget(this);
|
||||||
@@ -79,7 +73,7 @@ LiveScreenWidget::LiveScreenWidget(
|
|||||||
controlsLayout->addStretch(1);
|
controlsLayout->addStretch(1);
|
||||||
|
|
||||||
m_controlsWidget->setVisible(false);
|
m_controlsWidget->setVisible(false);
|
||||||
mainLayout->addWidget(m_controlsWidget);
|
contentLayout->addWidget(m_controlsWidget);
|
||||||
|
|
||||||
// button actions
|
// button actions
|
||||||
connect(m_rotateCwButton, &QPushButton::clicked, this, [this]() {
|
connect(m_rotateCwButton, &QPushButton::clicked, this, [this]() {
|
||||||
@@ -104,14 +98,18 @@ LiveScreenWidget::LiveScreenWidget(
|
|||||||
applyTransformAndDisplay();
|
applyTransformAndDisplay();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
connect(m_loadingWidget, &ZLoadingWidget::retryClicked, this, [this]() {
|
||||||
|
m_loadingWidget->showLoading();
|
||||||
|
QTimer::singleShot(200, this, &LiveScreenWidget::startInitialization);
|
||||||
|
});
|
||||||
connect(m_client, &CXX::ScreenshotBackend::init_failed, this,
|
connect(m_client, &CXX::ScreenshotBackend::init_failed, this,
|
||||||
&LiveScreenWidget::handleFailedInitialization);
|
&LiveScreenWidget::handleFailedInitialization);
|
||||||
QTimer::singleShot(0, this, &LiveScreenWidget::startInitialization);
|
QTimer::singleShot(200, this, &LiveScreenWidget::startInitialization);
|
||||||
}
|
}
|
||||||
|
|
||||||
void LiveScreenWidget::startInitialization()
|
void LiveScreenWidget::startInitialization()
|
||||||
{
|
{
|
||||||
|
m_loadingWidget->stop();
|
||||||
m_client->start_capture();
|
m_client->start_capture();
|
||||||
|
|
||||||
m_statusLabel->setText("Capturing");
|
m_statusLabel->setText("Capturing");
|
||||||
@@ -120,9 +118,15 @@ void LiveScreenWidget::startInitialization()
|
|||||||
|
|
||||||
void LiveScreenWidget::handleFailedInitialization()
|
void LiveScreenWidget::handleFailedInitialization()
|
||||||
{
|
{
|
||||||
|
m_loadingWidget->showLoading();
|
||||||
bool dvt = m_device->ios_version >= 17;
|
bool dvt = m_device->ios_version >= 17;
|
||||||
if (!dvt) {
|
if (!dvt) {
|
||||||
// Start the initialization process - auto-mount mode
|
if (m_tries >= 2) {
|
||||||
|
m_loadingWidget->showError(
|
||||||
|
"Failed to initialize screenshot capture");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
++m_tries;
|
||||||
auto *helper = new DevDiskImageHelper(m_device, this);
|
auto *helper = new DevDiskImageHelper(m_device, this);
|
||||||
|
|
||||||
connect(helper, &DevDiskImageHelper::mountingCompleted, this,
|
connect(helper, &DevDiskImageHelper::mountingCompleted, this,
|
||||||
@@ -139,7 +143,10 @@ void LiveScreenWidget::handleFailedInitialization()
|
|||||||
helper->start();
|
helper->start();
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
// TODO: need a widget here to show how to enable DEV mode on device
|
DevModeWidget(m_device, this).exec();
|
||||||
|
m_loadingWidget->showError(
|
||||||
|
"Failed to initialize screenshot capture. Please ensure the device "
|
||||||
|
"has developer mode enabled.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -20,12 +20,23 @@
|
|||||||
#ifndef LIVESCREEN_H
|
#ifndef LIVESCREEN_H
|
||||||
#define LIVESCREEN_H
|
#define LIVESCREEN_H
|
||||||
|
|
||||||
|
#include "appcontext.h"
|
||||||
|
#include "devdiskimagehelper.h"
|
||||||
|
#include "devdiskmanager.h"
|
||||||
|
#include "devmodewidget.h"
|
||||||
#include "iDescriptor-ui.h"
|
#include "iDescriptor-ui.h"
|
||||||
#include "iDescriptor.h"
|
#include "iDescriptor.h"
|
||||||
|
#include "zloadingwidget.h"
|
||||||
|
#include <QDebug>
|
||||||
|
#include <QHBoxLayout>
|
||||||
#include <QLabel>
|
#include <QLabel>
|
||||||
|
#include <QMessageBox>
|
||||||
#include <QPushButton>
|
#include <QPushButton>
|
||||||
|
#include <QSpinBox>
|
||||||
#include <QThread>
|
#include <QThread>
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
|
#include <QTransform>
|
||||||
|
#include <QVBoxLayout>
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
|
|
||||||
class LiveScreenWidget : public Tool
|
class LiveScreenWidget : public Tool
|
||||||
@@ -46,6 +57,7 @@ private:
|
|||||||
QLabel *m_imageLabel;
|
QLabel *m_imageLabel;
|
||||||
QLabel *m_statusLabel;
|
QLabel *m_statusLabel;
|
||||||
CXX::ScreenshotBackend *m_client;
|
CXX::ScreenshotBackend *m_client;
|
||||||
|
ZLoadingWidget *m_loadingWidget;
|
||||||
|
|
||||||
// controls for rotation / mirroring
|
// controls for rotation / mirroring
|
||||||
QWidget *m_controlsWidget = nullptr;
|
QWidget *m_controlsWidget = nullptr;
|
||||||
@@ -57,6 +69,7 @@ private:
|
|||||||
QPixmap m_lastPixmap;
|
QPixmap m_lastPixmap;
|
||||||
int m_rotationDegrees = 0; // 0, 90, 180, 270
|
int m_rotationDegrees = 0; // 0, 90, 180, 270
|
||||||
bool m_mirrorHorizontal = false;
|
bool m_mirrorHorizontal = false;
|
||||||
|
int m_tries = 0;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void startInitialization();
|
void startInitialization();
|
||||||
|
|||||||
Reference in New Issue
Block a user