diff --git a/QtScrcpy/adb/adbprocess.cpp b/QtScrcpy/adb/adbprocess.cpp index f060a81..91035fa 100644 --- a/QtScrcpy/adb/adbprocess.cpp +++ b/QtScrcpy/adb/adbprocess.cpp @@ -146,6 +146,20 @@ QString AdbProcess::getDeviceIPFromStdOut() return ip; } +QString AdbProcess::getDeviceIPByIpFromStdOut() +{ + QString ip = ""; + + QString strIPExp = "wlan0 inet [\\d.]*"; + QRegExp ipRegExp(strIPExp,Qt::CaseInsensitive); + if (ipRegExp.indexIn(m_standardOutput) != -1) { + ip = ipRegExp.cap(0); + ip = ip.right(ip.size() - 14); + } + qDebug() << "get ip: " << ip; + return ip; +} + QString AdbProcess::getStdOut() { return m_standardOutput; diff --git a/QtScrcpy/adb/adbprocess.h b/QtScrcpy/adb/adbprocess.h index aeb1b82..9fd15f1 100644 --- a/QtScrcpy/adb/adbprocess.h +++ b/QtScrcpy/adb/adbprocess.h @@ -31,6 +31,7 @@ public: void setShowTouchesEnabled(const QString& serial, bool enabled); QStringList getDevicesSerialFromStdOut(); QString getDeviceIPFromStdOut(); + QString getDeviceIPByIpFromStdOut(); QString getStdOut(); QString getErrorOut(); diff --git a/QtScrcpy/dialog.cpp b/QtScrcpy/dialog.cpp index 3aa54bb..01b73c6 100644 --- a/QtScrcpy/dialog.cpp +++ b/QtScrcpy/dialog.cpp @@ -22,6 +22,7 @@ Dialog::Dialog(QWidget *parent) : connect(&m_adb, &AdbProcess::adbProcessResult, this, [this](AdbProcess::ADB_EXEC_RESULT processResult){ QString log = ""; bool newLine = true; + QStringList args = m_adb.arguments(); switch (processResult) { case AdbProcess::AER_ERROR_START: @@ -32,13 +33,15 @@ Dialog::Dialog(QWidget *parent) : break; case AdbProcess::AER_ERROR_EXEC: //log = m_adb.getErrorOut(); + if (args.contains("ifconfig") && args.contains("wlan0")){ + getIPbyIp(); + } break; case AdbProcess::AER_ERROR_MISSING_BINARY: log = "adb not find"; break; case AdbProcess::AER_SUCCESS_EXEC: //log = m_adb.getStdOut(); - QStringList args = m_adb.arguments(); if (args.contains("devices")) { QStringList devices = m_adb.getDevicesSerialFromStdOut(); ui->serialBox->clear(); @@ -59,6 +62,13 @@ Dialog::Dialog(QWidget *parent) : break; } ui->deviceIpEdt->setText(ip); + } else if (args.contains("ip -o a")) { + QString ip = m_adb.getDeviceIPByIpFromStdOut(); + if (ip.isEmpty()) { + log = "ip not find, connect to wifi?"; + break; + } + ui->deviceIpEdt->setText(ip); } break; } @@ -285,6 +295,20 @@ void Dialog::on_getIPBtn_clicked() m_adb.execute(ui->serialBox->currentText().trimmed(), adbArgs); } +void Dialog::getIPbyIp() +{ + if (checkAdbRun()) { + return; + } + + + QStringList adbArgs; + adbArgs << "shell"; + adbArgs << "ip -o a"; + + m_adb.execute(ui->serialBox->currentText().trimmed(), adbArgs); +} + void Dialog::on_wirelessDisConnectBtn_clicked() { if (checkAdbRun()) { diff --git a/QtScrcpy/dialog.h b/QtScrcpy/dialog.h index 2b871a3..8101752 100644 --- a/QtScrcpy/dialog.h +++ b/QtScrcpy/dialog.h @@ -22,6 +22,7 @@ public: void outLog(const QString& log, bool newLine = true); bool filterLog(const QString & log); + void getIPbyIp(); private slots: void on_updateDevice_clicked(); diff --git a/QtScrcpy/uibase/keepradiowidget.cpp b/QtScrcpy/uibase/keepradiowidget.cpp index cd86516..09a5077 100644 --- a/QtScrcpy/uibase/keepradiowidget.cpp +++ b/QtScrcpy/uibase/keepradiowidget.cpp @@ -25,7 +25,7 @@ void KeepRadioWidget::setWidget(QWidget *w) void KeepRadioWidget::setWidthHeightRadio(float widthHeightRadio) { - if (abs(m_widthHeightRadio - widthHeightRadio) < 0.000001f) { + if (fabs(m_widthHeightRadio - widthHeightRadio) < 0.000001f) { return; } m_widthHeightRadio = widthHeightRadio;