Skip to content

Commit

Permalink
feat: support drop mutil apk install
Browse files Browse the repository at this point in the history
Change-Id: I65d090409208b89e770c11a3ea1fa2867560d214
  • Loading branch information
rankun committed Jul 8, 2020
1 parent ebea93d commit 303b017
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 41 deletions.
2 changes: 1 addition & 1 deletion QtScrcpy/device/device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
}

Expand Down
55 changes: 30 additions & 25 deletions QtScrcpy/device/filehandler/filehandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
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;
}
m_isApk = true;
m_adb.install(serial, apkFile);
}
8 changes: 3 additions & 5 deletions QtScrcpy/device/filehandler/filehandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
24 changes: 14 additions & 10 deletions QtScrcpy/device/ui/videoform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<QUrl> 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());
}

0 comments on commit 303b017

Please sign in to comment.