-
Notifications
You must be signed in to change notification settings - Fork 198
Fix: Prevent UI reset when new device inserted during write (#825) #914
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 3 commits
6d76a24
f8cfe68
6d63fbc
9f5aa75
3169c70
f1972ee
56c55a7
de28ba0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,6 +22,7 @@ | |
|
|
||
| #include <QAbstractListModel> | ||
| #include <QDebug> | ||
| #include <QProcess> | ||
|
|
||
| #include "releasemanager.h" | ||
|
|
||
|
|
@@ -169,6 +170,7 @@ class Drive : public QObject | |
| virtual qreal size() const; | ||
| virtual RestoreStatus restoreStatus(); | ||
| virtual bool delayedWrite() const; | ||
| virtual bool isBusy() const; | ||
|
|
||
| virtual void setDelayedWrite(const bool &o); | ||
|
|
||
|
|
@@ -194,6 +196,7 @@ public slots: | |
| RestoreStatus m_restoreStatus{CLEAN}; | ||
| QString m_error{}; | ||
| bool m_delayedWrite{false}; | ||
| QProcess *m_process{nullptr}; | ||
|
||
| }; | ||
|
|
||
| #endif // DRIVEMANAGER_H | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -76,8 +76,6 @@ private slots: | |
|
|
||
| private: | ||
| QString m_device; | ||
|
|
||
| QProcess *m_process{nullptr}; | ||
| }; | ||
|
|
||
| #endif // LINUXDRIVEMANAGER_H | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -87,19 +87,19 @@ bool MacDrive::write(ReleaseVariant *data) | |
| if (m_image->status() == ReleaseVariant::READY || m_image->status() == ReleaseVariant::FAILED || m_image->status() == ReleaseVariant::FAILED_VERIFICATION || m_image->status() == ReleaseVariant::FINISHED) | ||
| m_image->setStatus(ReleaseVariant::WRITING); | ||
|
|
||
| if (m_child) { | ||
| if (m_process) { | ||
| // TODO some handling of an already present process | ||
| m_child->deleteLater(); | ||
| m_process->deleteLater(); | ||
| } | ||
| m_child = new QProcess(this); | ||
| connect(m_child, static_cast<void (QProcess::*)(int, QProcess::ExitStatus)>(&QProcess::finished), this, &MacDrive::onFinished); | ||
| connect(m_child, &QProcess::readyRead, this, &MacDrive::onReadyRead); | ||
| connect(qApp, &QCoreApplication::aboutToQuit, m_child, &QProcess::terminate); | ||
| m_process = new QProcess(this); | ||
| connect(m_process, static_cast<void (QProcess::*)(int, QProcess::ExitStatus)>(&QProcess::finished), this, &MacDrive::onFinished); | ||
| connect(m_process, &QProcess::readyRead, this, &MacDrive::onReadyRead); | ||
| connect(qApp, &QCoreApplication::aboutToQuit, m_process, &QProcess::terminate); | ||
|
|
||
| if (QFile::exists(qApp->applicationDirPath() + "/../../../../helper/mac/helper.app/Contents/MacOS/helper")) { | ||
| m_child->setProgram(QString("%1/../../../../helper/mac/helper.app/Contents/MacOS/helper").arg(qApp->applicationDirPath())); | ||
| m_process->setProgram(QString("%1/../../../../helper/mac/helper.app/Contents/MacOS/helper").arg(qApp->applicationDirPath())); | ||
| } else if (QFile::exists(qApp->applicationDirPath() + "/helper")) { | ||
| m_child->setProgram(QString("%1/helper").arg(qApp->applicationDirPath())); | ||
| m_process->setProgram(QString("%1/helper").arg(qApp->applicationDirPath())); | ||
| } else { | ||
| data->setErrorString(tr("Could not find the helper binary. Check your installation.")); | ||
| setDelayedWrite(false); | ||
|
|
@@ -114,39 +114,39 @@ bool MacDrive::write(ReleaseVariant *data) | |
| } | ||
| args.append(m_bsdDevice); | ||
|
|
||
| mCritical() << "The command is" << m_child->program() << args; | ||
| m_child->setArguments(args); | ||
| mCritical() << "The command is" << m_process->program() << args; | ||
| m_process->setArguments(args); | ||
|
|
||
| m_child->start(); | ||
| m_process->start(); | ||
|
|
||
| return true; | ||
| } | ||
|
|
||
| void MacDrive::cancel() | ||
|
||
| { | ||
| Drive::cancel(); | ||
| if (m_child) { | ||
| m_child->kill(); | ||
| m_child->deleteLater(); | ||
| m_child = nullptr; | ||
| if (m_process) { | ||
| m_process->kill(); | ||
| m_process->deleteLater(); | ||
| m_process = nullptr; | ||
| } | ||
| } | ||
|
|
||
| void MacDrive::restore() | ||
| { | ||
| mCritical() << "starting to restore"; | ||
| if (m_child) | ||
| m_child->deleteLater(); | ||
| if (m_process) | ||
| m_process->deleteLater(); | ||
|
|
||
| m_child = new QProcess(this); | ||
| m_process = new QProcess(this); | ||
|
|
||
| m_restoreStatus = RESTORING; | ||
| emit restoreStatusChanged(); | ||
|
|
||
| if (QFile::exists(qApp->applicationDirPath() + "/../../../../helper/mac/helper.app/Contents/MacOS/helper")) { | ||
| m_child->setProgram(QString("%1/../../../../helper/mac/helper.app/Contents/MacOS/helper").arg(qApp->applicationDirPath())); | ||
| m_process->setProgram(QString("%1/../../../../helper/mac/helper.app/Contents/MacOS/helper").arg(qApp->applicationDirPath())); | ||
| } else if (QFile::exists(qApp->applicationDirPath() + "/helper")) { | ||
| m_child->setProgram(QString("%1/helper").arg(qApp->applicationDirPath())); | ||
| m_process->setProgram(QString("%1/helper").arg(qApp->applicationDirPath())); | ||
| } else { | ||
| m_restoreStatus = RESTORE_ERROR; | ||
| return; | ||
|
|
@@ -155,16 +155,16 @@ void MacDrive::restore() | |
| QStringList args; | ||
| args.append("restore"); | ||
| args.append(m_bsdDevice); | ||
| m_child->setArguments(args); | ||
| m_process->setArguments(args); | ||
|
|
||
| m_child->setProcessChannelMode(QProcess::ForwardedChannels); | ||
| m_process->setProcessChannelMode(QProcess::ForwardedChannels); | ||
|
|
||
| connect(m_child, static_cast<void (QProcess::*)(int, QProcess::ExitStatus)>(&QProcess::finished), this, &MacDrive::onRestoreFinished); | ||
| connect(qApp, &QCoreApplication::aboutToQuit, m_child, &QProcess::terminate); | ||
| connect(m_process, static_cast<void (QProcess::*)(int, QProcess::ExitStatus)>(&QProcess::finished), this, &MacDrive::onRestoreFinished); | ||
| connect(qApp, &QCoreApplication::aboutToQuit, m_process, &QProcess::terminate); | ||
|
|
||
| mCritical() << "The command is" << m_child->program() << args; | ||
| mCritical() << "The command is" << m_process->program() << args; | ||
|
|
||
| m_child->start(); | ||
| m_process->start(); | ||
| } | ||
|
|
||
| void MacDrive::onFinished(int exitCode, QProcess::ExitStatus exitStatus) | ||
|
|
@@ -173,11 +173,11 @@ void MacDrive::onFinished(int exitCode, QProcess::ExitStatus exitStatus) | |
|
|
||
| setDelayedWrite(false); | ||
|
|
||
| if (!m_child) | ||
| if (!m_process) | ||
| return; | ||
|
|
||
| if (exitCode != 0) { | ||
| QString output = m_child->readAllStandardError(); | ||
| QString output = m_process->readAllStandardError(); | ||
| QRegularExpression re("^.+:.+: "); | ||
| QStringList lines = output.split('\n'); | ||
| if (lines.length() > 0) { | ||
|
|
@@ -194,25 +194,25 @@ void MacDrive::onFinished(int exitCode, QProcess::ExitStatus exitStatus) | |
|
|
||
| void MacDrive::onRestoreFinished(int exitCode, QProcess::ExitStatus exitStatus) | ||
| { | ||
| if (!m_child) | ||
| if (!m_process) | ||
| return; | ||
|
|
||
| mCritical() << "Process finished" << exitCode << exitStatus; | ||
| mCritical() << m_child->readAllStandardError(); | ||
| mCritical() << m_process->readAllStandardError(); | ||
|
|
||
| if (exitCode == 0) | ||
| m_restoreStatus = RESTORED; | ||
| else | ||
| m_restoreStatus = RESTORE_ERROR; | ||
| emit restoreStatusChanged(); | ||
|
|
||
| m_child->deleteLater(); | ||
| m_child = nullptr; | ||
| m_process->deleteLater(); | ||
| m_process = nullptr; | ||
| } | ||
|
|
||
| void MacDrive::onReadyRead() | ||
| { | ||
| if (!m_child) | ||
| if (!m_process) | ||
| return; | ||
|
|
||
| if (m_image->status() == ReleaseVariant::WRITING) { | ||
|
|
@@ -223,9 +223,9 @@ void MacDrive::onReadyRead() | |
| if (m_image->status() != ReleaseVariant::WRITE_VERIFYING && m_image->status() != ReleaseVariant::WRITING) | ||
| m_image->setStatus(ReleaseVariant::WRITING); | ||
|
|
||
| while (m_child->bytesAvailable() > 0) { | ||
| while (m_process->bytesAvailable() > 0) { | ||
| bool ok; | ||
| int64_t bytes = m_child->readLine().trimmed().toULongLong(&ok); | ||
| int64_t bytes = m_process->readLine().trimmed().toULongLong(&ok); | ||
| if (ok) | ||
| m_progress->setValue(bytes); | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -60,7 +60,6 @@ private slots: | |
|
|
||
| private: | ||
| QString m_bsdDevice; | ||
| QProcess *m_child{nullptr}; | ||
| }; | ||
|
|
||
| #endif // MACDRIVEMANAGER_H | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: this comment can be removed