diff --git a/QtScrcpy/device/device.cpp b/QtScrcpy/device/device.cpp index 4ddce87..86cb318 100644 --- a/QtScrcpy/device/device.cpp +++ b/QtScrcpy/device/device.cpp @@ -198,7 +198,7 @@ void Device::initSignals() if (m_controlState == GCS_CLIENT) { return; } - QMessageBox::information(m_videoForm, "QtScrcpy", tips, QMessageBox::Ok); + //QMessageBox::information(m_videoForm, "QtScrcpy", tips, QMessageBox::Ok); }); } diff --git a/QtScrcpy/device/filehandler/filehandler.cpp b/QtScrcpy/device/filehandler/filehandler.cpp index a687ee8..c8a8635 100644 --- a/QtScrcpy/device/filehandler/filehandler.cpp +++ b/QtScrcpy/device/filehandler/filehandler.cpp @@ -2,41 +2,46 @@ FileHandler::FileHandler(QObject *parent) : QObject(parent) { - connect(&m_adb, &AdbProcess::adbProcessResult, this, [this](AdbProcess::ADB_EXEC_RESULT processResult) { - switch (processResult) { - case AdbProcess::AER_ERROR_START: - case AdbProcess::AER_ERROR_EXEC: - case AdbProcess::AER_ERROR_MISSING_BINARY: - emit fileHandlerResult(FAR_ERROR_EXEC, m_isApk); - break; - case AdbProcess::AER_SUCCESS_EXEC: - emit fileHandlerResult(FAR_SUCCESS_EXEC, m_isApk); - break; - default: - break; - } - }); } FileHandler::~FileHandler() {} void FileHandler::onPushFileRequest(const QString &serial, const QString &file, const QString &devicePath) { - if (m_adb.isRuning()) { - emit fileHandlerResult(FAR_IS_RUNNING, false); - return; - } + AdbProcess* adb = new AdbProcess; + bool isApk = false; + connect(adb, &AdbProcess::adbProcessResult, this, [this, adb, isApk](AdbProcess::ADB_EXEC_RESULT processResult) { + onAdbProcessResult(adb, isApk, processResult); + }); - m_isApk = false; - m_adb.push(serial, file, devicePath); + adb->push(serial, file, devicePath); } void FileHandler::onInstallApkRequest(const QString &serial, const QString &apkFile) { - if (m_adb.isRuning()) { - emit fileHandlerResult(FAR_IS_RUNNING, true); - return; - } - m_isApk = true; - m_adb.install(serial, apkFile); + AdbProcess* adb = new AdbProcess; + bool isApk = true; + connect(adb, &AdbProcess::adbProcessResult, this, [this, adb, isApk](AdbProcess::ADB_EXEC_RESULT processResult) { + onAdbProcessResult(adb, isApk, processResult); + }); + + adb->install(serial, apkFile); +} + +void FileHandler::onAdbProcessResult(AdbProcess *adb, bool isApk, AdbProcess::ADB_EXEC_RESULT processResult) +{ + switch (processResult) { + case AdbProcess::AER_ERROR_START: + case AdbProcess::AER_ERROR_EXEC: + case AdbProcess::AER_ERROR_MISSING_BINARY: + emit fileHandlerResult(FAR_ERROR_EXEC, isApk); + adb->deleteLater(); + break; + case AdbProcess::AER_SUCCESS_EXEC: + emit fileHandlerResult(FAR_SUCCESS_EXEC, isApk); + adb->deleteLater(); + break; + default: + break; + } } diff --git a/QtScrcpy/device/filehandler/filehandler.h b/QtScrcpy/device/filehandler/filehandler.h index 6dbc9ca..9bd3588 100644 --- a/QtScrcpy/device/filehandler/filehandler.h +++ b/QtScrcpy/device/filehandler/filehandler.h @@ -24,13 +24,11 @@ public slots: void onPushFileRequest(const QString &serial, const QString &file, const QString &devicePath = ""); void onInstallApkRequest(const QString &serial, const QString &apkFile); +protected: + void onAdbProcessResult(AdbProcess* adb, bool isApk, AdbProcess::ADB_EXEC_RESULT processResult); + signals: void fileHandlerResult(FILE_HANDLER_RESULT processResult, bool isApk = false); - -private: - AdbProcess m_adb; - bool m_isApk = false; - QString m_devicePath = ""; }; #endif // FILEHANDLER_H diff --git a/QtScrcpy/device/ui/videoform.cpp b/QtScrcpy/device/ui/videoform.cpp index c0b1bdf..88bc6c3 100644 --- a/QtScrcpy/device/ui/videoform.cpp +++ b/QtScrcpy/device/ui/videoform.cpp @@ -699,17 +699,21 @@ void VideoForm::dropEvent(QDropEvent *event) return; } const QMimeData *qm = event->mimeData(); - QString file = qm->urls()[0].toLocalFile(); - QFileInfo fileInfo(file); + QList urls = qm->urls(); - if (!fileInfo.exists()) { - QMessageBox::warning(this, "QtScrcpy", tr("file does not exist"), QMessageBox::Ok); - return; - } + for (const QUrl& url : urls) { + QString file = url.toLocalFile(); + QFileInfo fileInfo(file); - if (fileInfo.isFile() && fileInfo.suffix() == "apk") { - emit m_device->installApkRequest(file); - return; + if (!fileInfo.exists()) { + QMessageBox::warning(this, "QtScrcpy", tr("file does not exist"), QMessageBox::Ok); + continue; + } + + if (fileInfo.isFile() && fileInfo.suffix() == "apk") { + emit m_device->installApkRequest(file); + continue; + } + emit m_device->pushFileRequest(file, Config::getInstance().getPushFilePath() + fileInfo.fileName()); } - emit m_device->pushFileRequest(file, Config::getInstance().getPushFilePath() + fileInfo.fileName()); }