mirror of
https://invent.kde.org/marcoa/shift-shell.git
synced 2026-07-30 08:14:45 +00:00
waydroid: Refactor with QCoro
This commit is contained in:
parent
1e2ba92a5a
commit
5c93d1e77a
8 changed files with 63 additions and 38 deletions
|
|
@ -87,7 +87,7 @@ find_package(KPipeWire ${PROJECT_DEP_VERSION} REQUIRED)
|
||||||
|
|
||||||
find_package(PkgConfig REQUIRED)
|
find_package(PkgConfig REQUIRED)
|
||||||
|
|
||||||
find_package(QCoro6 REQUIRED COMPONENTS DBus)
|
find_package(QCoro6 REQUIRED COMPONENTS DBus Qml)
|
||||||
qcoro_enable_coroutines()
|
qcoro_enable_coroutines()
|
||||||
kde_enable_exceptions()
|
kde_enable_exceptions()
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,8 @@ target_link_libraries(waydroidintegrationplugin PRIVATE
|
||||||
Qt::Quick
|
Qt::Quick
|
||||||
KF6::AuthCore
|
KF6::AuthCore
|
||||||
KF6::I18n
|
KF6::I18n
|
||||||
|
QCoro::Core
|
||||||
|
QCoro::Qml
|
||||||
)
|
)
|
||||||
|
|
||||||
ecm_finalize_qml_module(waydroidintegrationplugin)
|
ecm_finalize_qml_module(waydroidintegrationplugin)
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@
|
||||||
#include "waydroidshared.h"
|
#include "waydroidshared.h"
|
||||||
|
|
||||||
#include <QClipboard>
|
#include <QClipboard>
|
||||||
|
#include <QCoroProcess>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
#include <QGuiApplication>
|
#include <QGuiApplication>
|
||||||
|
|
@ -175,10 +176,15 @@ void WaydroidState::resetError()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void WaydroidState::initialize(const SystemType systemType, const RomType romType, const bool forced)
|
QCoro::QmlTask WaydroidState::initializeQml(const SystemType systemType, const RomType romType, const bool forced)
|
||||||
|
{
|
||||||
|
return initialize(systemType, romType, forced);
|
||||||
|
}
|
||||||
|
|
||||||
|
QCoro::Task<void> WaydroidState::initialize(const SystemType systemType, const RomType romType, const bool forced)
|
||||||
{
|
{
|
||||||
if (m_status == Initializing) {
|
if (m_status == Initializing) {
|
||||||
return;
|
co_return;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_status = Initializing;
|
m_status = Initializing;
|
||||||
|
|
@ -230,7 +236,8 @@ void WaydroidState::initialize(const SystemType systemType, const RomType romTyp
|
||||||
Q_EMIT downloadStatusChanged(downloaded, total, speed);
|
Q_EMIT downloadStatusChanged(downloaded, total, speed);
|
||||||
});
|
});
|
||||||
|
|
||||||
connect(job, &KAuth::ExecuteJob::finished, this, [this](KJob *job, auto) {
|
co_await qCoro(job, &KAuth::ExecuteJob::finished);
|
||||||
|
|
||||||
if (job->error() == 0) {
|
if (job->error() == 0) {
|
||||||
m_status = Initialized;
|
m_status = Initialized;
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -244,13 +251,17 @@ void WaydroidState::initialize(const SystemType systemType, const RomType romTyp
|
||||||
}
|
}
|
||||||
|
|
||||||
Q_EMIT statusChanged();
|
Q_EMIT statusChanged();
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void WaydroidState::startSession()
|
QCoro::QmlTask WaydroidState::startSessionQml()
|
||||||
|
{
|
||||||
|
return startSession();
|
||||||
|
}
|
||||||
|
|
||||||
|
QCoro::Task<void> WaydroidState::startSession()
|
||||||
{
|
{
|
||||||
if (m_sessionStatus == SessionStarting || m_sessionStatus == SessionRunning) {
|
if (m_sessionStatus == SessionStarting || m_sessionStatus == SessionRunning) {
|
||||||
return;
|
co_return;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_sessionStatus = SessionStarting;
|
m_sessionStatus = SessionStarting;
|
||||||
|
|
@ -258,11 +269,11 @@ void WaydroidState::startSession()
|
||||||
|
|
||||||
const QStringList arguments{u"session"_s, u"start"_s};
|
const QStringList arguments{u"session"_s, u"start"_s};
|
||||||
|
|
||||||
// Don't wait for result because the command is blocking
|
QProcess *basicProcess = new QProcess(this);
|
||||||
QProcess *process = new QProcess(this);
|
auto process = qCoro(basicProcess);
|
||||||
process->start(WAYDROID_COMMAND, arguments);
|
co_await process.start(WAYDROID_COMMAND, arguments);
|
||||||
|
|
||||||
connect(process, &QProcess::finished, this, [this, process](int exitCode, QProcess::ExitStatus exitStatus) {
|
connect(basicProcess, &QProcess::finished, this, [this, basicProcess](int exitCode, QProcess::ExitStatus exitStatus) {
|
||||||
Q_UNUSED(exitStatus);
|
Q_UNUSED(exitStatus);
|
||||||
|
|
||||||
if (exitCode == 0) {
|
if (exitCode == 0) {
|
||||||
|
|
@ -272,7 +283,7 @@ void WaydroidState::startSession()
|
||||||
m_sessionStatus = SessionStopped;
|
m_sessionStatus = SessionStopped;
|
||||||
Q_EMIT sessionStatusChanged();
|
Q_EMIT sessionStatusChanged();
|
||||||
|
|
||||||
QByteArray errorData = process->readAllStandardError();
|
QByteArray errorData = basicProcess->readAllStandardError();
|
||||||
QString errorString = QString::fromUtf8(errorData);
|
QString errorString = QString::fromUtf8(errorData);
|
||||||
|
|
||||||
m_errorTitle = i18n("Failed to start the Waydroid session.");
|
m_errorTitle = i18n("Failed to start the Waydroid session.");
|
||||||
|
|
@ -286,23 +297,29 @@ void WaydroidState::startSession()
|
||||||
checkSessionStarting(10);
|
checkSessionStarting(10);
|
||||||
}
|
}
|
||||||
|
|
||||||
void WaydroidState::stopSession()
|
QCoro::QmlTask WaydroidState::stopSessionQml()
|
||||||
|
{
|
||||||
|
return stopSession();
|
||||||
|
}
|
||||||
|
|
||||||
|
QCoro::Task<void> WaydroidState::stopSession()
|
||||||
{
|
{
|
||||||
if (m_sessionStatus == SessionStopped) {
|
if (m_sessionStatus == SessionStopped) {
|
||||||
return;
|
co_return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const QStringList arguments{u"session"_s, u"stop"_s};
|
const QStringList arguments{u"session"_s, u"stop"_s};
|
||||||
|
|
||||||
QProcess *process = new QProcess(this);
|
QProcess basicProcess = QProcess(this);
|
||||||
process->start(WAYDROID_COMMAND, arguments);
|
auto process = qCoro(basicProcess);
|
||||||
process->waitForFinished();
|
co_await process.start(WAYDROID_COMMAND, arguments);
|
||||||
|
co_await process.waitForFinished();
|
||||||
|
|
||||||
if (process->exitCode() == 0) {
|
if (basicProcess.exitCode() == 0) {
|
||||||
m_sessionStatus = SessionStopped;
|
m_sessionStatus = SessionStopped;
|
||||||
Q_EMIT sessionStatusChanged();
|
Q_EMIT sessionStatusChanged();
|
||||||
} else {
|
} else {
|
||||||
qCWarning(WAYDROIDINTEGRATIONPLUGIN) << "Failed to stop the Waydroid session: " << process->readAllStandardError();
|
qCWarning(WAYDROIDINTEGRATIONPLUGIN) << "Failed to stop the Waydroid session: " << basicProcess.readAllStandardError();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,8 @@
|
||||||
|
|
||||||
#include "waydroidapplicationlistmodel.h"
|
#include "waydroidapplicationlistmodel.h"
|
||||||
|
|
||||||
|
#include <QCoroCore>
|
||||||
|
#include <QCoroQmlTask>
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
|
|
||||||
#include <qqmlregistration.h>
|
#include <qqmlregistration.h>
|
||||||
|
|
@ -95,9 +97,13 @@ public:
|
||||||
Q_INVOKABLE void refreshAndroidId();
|
Q_INVOKABLE void refreshAndroidId();
|
||||||
Q_INVOKABLE void refreshPropsInfo();
|
Q_INVOKABLE void refreshPropsInfo();
|
||||||
Q_INVOKABLE void resetError();
|
Q_INVOKABLE void resetError();
|
||||||
Q_INVOKABLE void initialize(const SystemType systemType, const RomType romType, const bool forced = false);
|
Q_INVOKABLE QCoro::QmlTask initializeQml(const SystemType systemType, const RomType romType, const bool forced = false);
|
||||||
Q_INVOKABLE void startSession();
|
QCoro::Task<void> initialize(const SystemType systemType, const RomType romType, const bool forced = false);
|
||||||
Q_INVOKABLE void stopSession();
|
Q_INVOKABLE QCoro::QmlTask startSessionQml();
|
||||||
|
QCoro::Task<void> startSession();
|
||||||
|
Q_INVOKABLE QCoro::QmlTask stopSessionQml();
|
||||||
|
QCoro::Task<void> stopSession();
|
||||||
|
|
||||||
Q_INVOKABLE void copyToClipboard(const QString text);
|
Q_INVOKABLE void copyToClipboard(const QString text);
|
||||||
|
|
||||||
Status status() const;
|
Status status() const;
|
||||||
|
|
|
||||||
|
|
@ -37,7 +37,7 @@ ColumnLayout {
|
||||||
|
|
||||||
trailing: PC3.Button {
|
trailing: PC3.Button {
|
||||||
text: i18n("Stop session")
|
text: i18n("Stop session")
|
||||||
onClicked: AIP.WaydroidState.stopSession()
|
onClicked: AIP.WaydroidState.stopSessionQml()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -36,6 +36,6 @@ ColumnLayout {
|
||||||
Layout.alignment: Qt.AlignHCenter
|
Layout.alignment: Qt.AlignHCenter
|
||||||
enabled: systemType.currentValue !== undefined
|
enabled: systemType.currentValue !== undefined
|
||||||
|
|
||||||
onClicked: AIP.WaydroidState.initialize(systemType.currentValue, AIP.WaydroidState.Lineage)
|
onClicked: AIP.WaydroidState.initializeQml(systemType.currentValue, AIP.WaydroidState.Lineage)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -76,7 +76,7 @@ KCM.SimpleKCM {
|
||||||
PC3.Button {
|
PC3.Button {
|
||||||
text: i18n("Start the session")
|
text: i18n("Start the session")
|
||||||
Layout.alignment: Qt.AlignHCenter
|
Layout.alignment: Qt.AlignHCenter
|
||||||
onClicked: AIP.WaydroidState.startSession()
|
onClicked: AIP.WaydroidState.startSessionQml()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -18,9 +18,9 @@ QS.QuickSetting {
|
||||||
|
|
||||||
function toggle(): void {
|
function toggle(): void {
|
||||||
if (AIP.WaydroidState.sessionStatus === AIP.WaydroidState.SessionRunning) {
|
if (AIP.WaydroidState.sessionStatus === AIP.WaydroidState.SessionRunning) {
|
||||||
AIP.WaydroidState.stopSession()
|
AIP.WaydroidState.stopSessionQml()
|
||||||
} else {
|
} else {
|
||||||
AIP.WaydroidState.startSession()
|
AIP.WaydroidState.startSessionQml()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue