From c874a2af66782ad616307fbf62fef43e988f92dc Mon Sep 17 00:00:00 2001 From: Barry <870709864@qq.com> Date: Tue, 24 May 2022 11:02:32 +0800 Subject: [PATCH] refactor: adjust interface --- QtScrcpy/devicemanage/devicemanage.cpp | 15 --------------- QtScrcpy/devicemanage/devicemanage.h | 2 -- QtScrcpy/include/QtScrcpyCore.h | 5 +---- QtScrcpy/ui/dialog.cpp | 9 ++++++++- 4 files changed, 9 insertions(+), 22 deletions(-) diff --git a/QtScrcpy/devicemanage/devicemanage.cpp b/QtScrcpy/devicemanage/devicemanage.cpp index 0abc803..93b1a7c 100644 --- a/QtScrcpy/devicemanage/devicemanage.cpp +++ b/QtScrcpy/devicemanage/devicemanage.cpp @@ -63,24 +63,9 @@ bool DeviceManage::connectDevice(qsc::DeviceParams params) return false; } m_devices[params.serial] = device; - if (!m_script.isEmpty()) { - device->updateScript(m_script); - } return true; } -void DeviceManage::updateScript(QString script) -{ - m_script = script; - QMapIterator> i(m_devices); - while (i.hasNext()) { - i.next(); - if (i.value()) { - i.value()->updateScript(script); - } - } -} - bool DeviceManage::disconnectDevice(const QString &serial) { bool ret = false; diff --git a/QtScrcpy/devicemanage/devicemanage.h b/QtScrcpy/devicemanage/devicemanage.h index ee9cfa4..d4decb1 100644 --- a/QtScrcpy/devicemanage/devicemanage.h +++ b/QtScrcpy/devicemanage/devicemanage.h @@ -21,8 +21,6 @@ public: bool disconnectDevice(const QString &serial) override; void disconnectAllDevice() override; - void updateScript(QString script) override; - protected slots: void onDeviceConnected(bool success, const QString& serial, const QString& deviceName, const QSize& size); void onDeviceDisconnected(QString serial); diff --git a/QtScrcpy/include/QtScrcpyCore.h b/QtScrcpy/include/QtScrcpyCore.h index 2a68647..cc21e35 100644 --- a/QtScrcpy/include/QtScrcpyCore.h +++ b/QtScrcpy/include/QtScrcpyCore.h @@ -77,13 +77,10 @@ class IDeviceManage : public QObject { Q_OBJECT public: static IDeviceManage& getInstance(); - - virtual QPointer getDevice(const QString& serial) = 0; virtual bool connectDevice(DeviceParams params) = 0; virtual bool disconnectDevice(const QString &serial) = 0; virtual void disconnectAllDevice() = 0; - - virtual void updateScript(QString script) = 0; + virtual QPointer getDevice(const QString& serial) = 0; signals: void deviceConnected(bool success, const QString& serial, const QString& deviceName, const QSize& size); diff --git a/QtScrcpy/ui/dialog.cpp b/QtScrcpy/ui/dialog.cpp index 3d43ca6..ebfe8b4 100644 --- a/QtScrcpy/ui/dialog.cpp +++ b/QtScrcpy/ui/dialog.cpp @@ -283,6 +283,7 @@ void Dialog::on_startServerBtn_clicked() params.recordFileFormat = ui->formatBox->currentText().trimmed(); params.serverLocalPath = getServerPath(); params.serverRemotePath = Config::getInstance().getServerPath(); + params.gameScript = getGameScript(ui->gameBox->currentText()); qsc::IDeviceManage::getInstance().connectDevice(params); } @@ -517,7 +518,13 @@ void Dialog::on_refreshGameScriptBtn_clicked() void Dialog::on_applyScriptBtn_clicked() { - qsc::IDeviceManage::getInstance().updateScript(getGameScript(ui->gameBox->currentText())); + auto curSerial = ui->serialBox->currentText().trimmed(); + auto device = qsc::IDeviceManage::getInstance().getDevice(curSerial); + if (!device) { + return; + } + + device->updateScript(getGameScript(ui->gameBox->currentText())); } void Dialog::on_recordScreenCheck_clicked(bool checked)