Use exit() instead of quit() to be able to add a returnCode in case of failure.

This commit is contained in:
Gerhard Hoffmann 2023-08-03 09:06:50 +02:00
parent 0ee92f0181
commit 9b08420ac1
3 changed files with 51 additions and 14 deletions

View File

@ -77,7 +77,8 @@ void MainWindow::onRestartExitTimer() {
void MainWindow::onQuit() { void MainWindow::onQuit() {
if (!m_worker->updateProcessRunning()) { if (!m_worker->updateProcessRunning()) {
qApp->quit(); // qApp->quit();
qApp->exit(m_worker->returnCode());
} }
} }
@ -91,12 +92,16 @@ void MainWindow::onAppendText(QString text, QString suffix) {
for (int i=0; i<lines.size(); ++i) { for (int i=0; i<lines.size(); ++i) {
qCritical() << lines.at(i); qCritical() << lines.at(i);
} }
if (!suffix.contains("[SUCCESS]")) { if (suffix.contains("[SUCCESS]")) {
editText += text.leftJustified(m_width-9) + suffix;
ui->updateStatus->setPlainText(editText);
} else {
editText += QString("\n").leftJustified(m_width-3, '='); editText += QString("\n").leftJustified(m_width-3, '=');
editText += QString("\n").leftJustified(m_width-12) + " [SUCCESS]"; editText += QString("\n").leftJustified(m_width-12) + " [SUCCESS]";
} else
if (suffix.contains(" [fail]")) {
editText += QString("\n").leftJustified(m_width-3, '=');
editText += QString("\n").leftJustified(m_width-9) + " [fail]";
} else {
editText += text.leftJustified(m_width-9) + suffix;
ui->updateStatus->setPlainText(editText);
} }
ui->updateStatus->setText(editText); ui->updateStatus->setText(editText);
ui->updateStatus->setEnabled(true); ui->updateStatus->setEnabled(true);

View File

@ -65,7 +65,8 @@ Worker::Worker(hwinf *hw,
, m_ismasUpdateRequests(ISMAS_UPDATE_REQUESTS) , m_ismasUpdateRequests(ISMAS_UPDATE_REQUESTS)
, m_waitForNewUpdates(this) , m_waitForNewUpdates(this)
, m_filesToUpdate() , m_filesToUpdate()
, m_updateProcessRunning(false) { , m_updateProcessRunning(false)
, m_returnCode(0) {
QDir::setCurrent(m_workingDirectory); QDir::setCurrent(m_workingDirectory);
@ -127,6 +128,7 @@ void Worker::privateUpdate() {
bool sentIsmasLastVersionNotification = false; bool sentIsmasLastVersionNotification = false;
m_returnCode = -1;
QDir customerRepository(m_customerRepository); QDir customerRepository(m_customerRepository);
if (!customerRepository.exists()) { if (!customerRepository.exists()) {
if (m_gc.gitCloneAndCheckoutBranch()) { if (m_gc.gitCloneAndCheckoutBranch()) {
@ -146,10 +148,7 @@ void Worker::privateUpdate() {
m_ismasClient.setProgressInPercent(95); m_ismasClient.setProgressInPercent(95);
IsmasClient::sendRequestReceiveResponse(IsmasClient::APISM::DB_PORT, IsmasClient::sendRequestReceiveResponse(IsmasClient::APISM::DB_PORT,
QString("#M=APISM#C=CMD_EVENT#J=") + m_ismasClient.updateOfPSAActivated()); QString("#M=APISM#C=CMD_EVENT#J=") + m_ismasClient.updateOfPSAActivated());
m_returnCode = 0;
//emit setProgress(100);
//m_ismasClient.setProgressInPercent(100);
//emit appendText(QString(""), UPDATE_STEP_SUCCESS);
} }
} else { } else {
// checkout branch // checkout branch
@ -199,22 +198,51 @@ void Worker::privateUpdate() {
IsmasClient::sendRequestReceiveResponse(IsmasClient::APISM::DB_PORT, IsmasClient::sendRequestReceiveResponse(IsmasClient::APISM::DB_PORT,
QString("#M=APISM#C=CMD_EVENT#J=") + QString("#M=APISM#C=CMD_EVENT#J=") +
m_ismasClient.updateOfPSAActivated()); m_ismasClient.updateOfPSAActivated());
m_returnCode = 0;
} else {
m_returnCode = -9;
} }
} else {
m_returnCode = -8;
} }
} else {
m_returnCode = -7;
} }
} else {
m_returnCode = -6;
} }
} else {
m_returnCode = -5;
} }
} else {
m_returnCode = -4;
} }
} else {
m_returnCode = -3;
} }
} else {
m_returnCode = -2;
} }
} else {
m_returnCode = -1;
} }
} }
if (!sentIsmasLastVersionNotification) { if (!sentIsmasLastVersionNotification) {
// try even if the backend is not connected // try even if the backend is not connected
sendIsmasLastVersionNotification();
emit setProgress(100); emit setProgress(100);
m_ismasClient.setProgressInPercent(100); m_ismasClient.setProgressInPercent(100);
emit appendText(QString(""), UPDATE_STEP_SUCCESS);
if (m_returnCode == 0) {
IsmasClient::sendRequestReceiveResponse(IsmasClient::APISM::DB_PORT,
QString("#M=APISM#C=CMD_EVENT#J=") +
m_ismasClient.updateOfPSASucceeded(""));
emit appendText(QString(""), UPDATE_STEP_SUCCESS);
} else {
emit appendText(QString(""), UPDATE_STEP_FAIL);
}
sendIsmasLastVersionNotification();
} }
m_updateProcessRunning = false; m_updateProcessRunning = false;
@ -253,7 +281,7 @@ bool Worker::backendConnected() {
bool ismas = obj.value("ISMAS").toBool(); bool ismas = obj.value("ISMAS").toBool();
QString status = obj.value("Broker").toString(); QString status = obj.value("Broker").toString();
qCritical() << "XXXXXXXXXX STATUS" << status; qCritical() << "STATUS" << status;
if (ismas) { if (ismas) {
if (status == "Connected") { if (status == "Connected") {
@ -494,7 +522,9 @@ bool Worker::updateFiles(quint8 percent) {
} }
} }
qCritical() << "XXXXXXXXXXXXXXXXXXX FILES_TO_WORK_ON" << filesToDownload; if (filesToDownload.size() > 0) {
qCritical() << "FILES_TO_WORK_ON" << filesToDownload;
}
return m_update->doUpdate(m_displayIndex, filesToDownload); return m_update->doUpdate(m_displayIndex, filesToDownload);
} }

View File

@ -122,6 +122,7 @@ class Worker : public QObject {
QStringList m_filesToUpdate; QStringList m_filesToUpdate;
bool m_updateProcessRunning; bool m_updateProcessRunning;
int m_displayIndex; int m_displayIndex;
int m_returnCode;
bool executeOpkgCommand(QString opkgCommand); bool executeOpkgCommand(QString opkgCommand);
QString getOsVersion() const; QString getOsVersion() const;
@ -156,6 +157,7 @@ public:
IsmasClient const &getIsmasClient() const { return m_ismasClient; } IsmasClient const &getIsmasClient() const { return m_ismasClient; }
bool updateProcessRunning() const { return m_updateProcessRunning; } bool updateProcessRunning() const { return m_updateProcessRunning; }
bool returnCode() const { return m_returnCode; }
int machineNr() const { return m_machineNr; } int machineNr() const { return m_machineNr; }
int customerNr() const { return m_customerNr; } int customerNr() const { return m_customerNr; }