mirror of
https://github.com/barry-ran/QtScrcpy.git
synced 2025-08-03 06:08:39 +00:00
增加更新设备列表功能
This commit is contained in:
parent
4c66f5679a
commit
3b2007df1d
5 changed files with 30 additions and 18 deletions
|
@ -65,17 +65,8 @@ void AdbProcess::initSignals()
|
||||||
|
|
||||||
connect(this, &QProcess::readyReadStandardOutput, this,
|
connect(this, &QProcess::readyReadStandardOutput, this,
|
||||||
[this](){
|
[this](){
|
||||||
QString stdOut = QString::fromLocal8Bit(readAllStandardOutput());
|
m_standardOutput = QString::fromLocal8Bit(readAllStandardOutput());
|
||||||
|
qDebug() << m_standardOutput;
|
||||||
// get devices serial by adb devices
|
|
||||||
QStringList serials;
|
|
||||||
QStringList devicesInfoList = stdOut.split(QRegExp("\r\n|\n"), QString::SkipEmptyParts);
|
|
||||||
for(QString deviceInfo : devicesInfoList) {
|
|
||||||
QStringList deviceInfos = deviceInfo.split(QRegExp("\t"), QString::SkipEmptyParts);
|
|
||||||
if (2 == deviceInfos.count() && 0 == deviceInfos[1].compare("device")) {
|
|
||||||
serials << deviceInfos[0];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
connect(this, &QProcess::started, this,
|
connect(this, &QProcess::started, this,
|
||||||
|
@ -86,6 +77,7 @@ void AdbProcess::initSignals()
|
||||||
|
|
||||||
void AdbProcess::execute(const QString& serial, const QStringList& args)
|
void AdbProcess::execute(const QString& serial, const QStringList& args)
|
||||||
{
|
{
|
||||||
|
m_standardOutput = "";
|
||||||
QStringList adbArgs;
|
QStringList adbArgs;
|
||||||
if (!serial.isEmpty()) {
|
if (!serial.isEmpty()) {
|
||||||
adbArgs << "-s" << serial;
|
adbArgs << "-s" << serial;
|
||||||
|
@ -112,6 +104,20 @@ void AdbProcess::setShowTouchesEnabled(const QString &serial, bool enabled)
|
||||||
execute(serial, adbArgs);
|
execute(serial, adbArgs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QStringList AdbProcess::getDevicesSerialFromStdOut()
|
||||||
|
{
|
||||||
|
// get devices serial by adb devices
|
||||||
|
QStringList serials;
|
||||||
|
QStringList devicesInfoList = m_standardOutput.split(QRegExp("\r\n|\n"), QString::SkipEmptyParts);
|
||||||
|
for(QString deviceInfo : devicesInfoList) {
|
||||||
|
QStringList deviceInfos = deviceInfo.split(QRegExp("\t"), QString::SkipEmptyParts);
|
||||||
|
if (2 == deviceInfos.count() && 0 == deviceInfos[1].compare("device")) {
|
||||||
|
serials << deviceInfos[0];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return serials;
|
||||||
|
}
|
||||||
|
|
||||||
void AdbProcess::forward(const QString& serial, quint16 localPort, const QString& deviceSocketName)
|
void AdbProcess::forward(const QString& serial, quint16 localPort, const QString& deviceSocketName)
|
||||||
{
|
{
|
||||||
QStringList adbArgs;
|
QStringList adbArgs;
|
||||||
|
|
|
@ -29,6 +29,7 @@ public:
|
||||||
void removePath(const QString& serial, const QString& path);
|
void removePath(const QString& serial, const QString& path);
|
||||||
bool isRuning();
|
bool isRuning();
|
||||||
void setShowTouchesEnabled(const QString& serial, bool enabled);
|
void setShowTouchesEnabled(const QString& serial, bool enabled);
|
||||||
|
QStringList getDevicesSerialFromStdOut();
|
||||||
|
|
||||||
static const QString& getAdbPath();
|
static const QString& getAdbPath();
|
||||||
|
|
||||||
|
@ -38,6 +39,8 @@ signals:
|
||||||
private:
|
private:
|
||||||
void initSignals();
|
void initSignals();
|
||||||
|
|
||||||
|
private:
|
||||||
|
QString m_standardOutput = "";
|
||||||
static QString s_adbPath;
|
static QString s_adbPath;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -21,10 +21,13 @@ Dialog::~Dialog()
|
||||||
delete ui;
|
delete ui;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Dialog::on_adbProcess_clicked()
|
void Dialog::on_updateDevice_clicked()
|
||||||
{
|
{
|
||||||
AdbProcess* adb = new AdbProcess();
|
AdbProcess* adb = new AdbProcess();
|
||||||
connect(adb, &AdbProcess::adbProcessResult, this, [this](AdbProcess::ADB_EXEC_RESULT processResult){
|
connect(adb, &AdbProcess::adbProcessResult, this, [this, adb](AdbProcess::ADB_EXEC_RESULT processResult){
|
||||||
|
if (AdbProcess::AER_SUCCESS_EXEC == processResult) {
|
||||||
|
qDebug() << adb->getDevicesSerialFromStdOut().join("*");
|
||||||
|
}
|
||||||
if (AdbProcess::AER_SUCCESS_START != processResult) {
|
if (AdbProcess::AER_SUCCESS_START != processResult) {
|
||||||
sender()->deleteLater();
|
sender()->deleteLater();
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,7 +20,7 @@ public:
|
||||||
~Dialog();
|
~Dialog();
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void on_adbProcess_clicked();
|
void on_updateDevice_clicked();
|
||||||
|
|
||||||
void on_startServerBtn_clicked();
|
void on_startServerBtn_clicked();
|
||||||
|
|
||||||
|
|
|
@ -30,23 +30,23 @@
|
||||||
</property>
|
</property>
|
||||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||||
<item>
|
<item>
|
||||||
<widget class="QPushButton" name="adbProcess">
|
<widget class="QPushButton" name="updateDevice">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>adbProcess</string>
|
<string>update device</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QPushButton" name="startServerBtn">
|
<widget class="QPushButton" name="startServerBtn">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>startServer</string>
|
<string>start server</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QPushButton" name="stopServerBtn">
|
<widget class="QPushButton" name="stopServerBtn">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>stopServer</string>
|
<string>stop server</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue