From 290a2504ff396696fa3c3238cf0780edbd731a4b Mon Sep 17 00:00:00 2001 From: Steven Powell Date: Thu, 5 May 2022 15:55:20 -0700 Subject: [PATCH] add progress bar and messages to start --- gui/window.cpp | 95 +++++++++++++++++++++++++++++++++++++++++++++++++- gui/window.h | 13 ++++++- 2 files changed, 106 insertions(+), 2 deletions(-) diff --git a/gui/window.cpp b/gui/window.cpp index 012d29e178..449b977235 100644 --- a/gui/window.cpp +++ b/gui/window.cpp @@ -326,7 +326,7 @@ void Window::startMinikube(QStringList moreArgs) QString text; QStringList args = { "start", "-o", "json" }; args << moreArgs; - bool success = sendMinikubeCommand(args, text); + bool success = sendMinikubeStart(args, text); #if __APPLE__ hyperkitPermissionFix(args, text); #endif @@ -714,6 +714,99 @@ bool Window::sendMinikubeCommand(QStringList cmds, QString &text) return success; } +bool Window::sendMinikubeStart(QStringList cmds, QString &text) +{ + QString program = minikubePath(); + if (program.isEmpty()) { + return false; + } + QStringList arguments = { "--user", "minikube-gui" }; + arguments << cmds; + + QProcess *process = new QProcess(this); + connect(process, &QProcess::readyReadStandardOutput, + [process, this]() { startStep(process->readAllStandardOutput()); }); + startProcess = process; +#if __APPLE__ + if (env.isEmpty()) { + env = setMacEnv(); + } + startProcess->setProcessEnvironment(env); +#endif + this->setCursor(Qt::WaitCursor); + startProcess->start(program, arguments); + startProgress(); + while (startProcess->state() != QProcess::NotRunning) { + delay(); + } + endProgress(); + int exitCode = startProcess->exitCode(); + bool success = exitCode == 0; + this->unsetCursor(); + + text = startProcess->readAllStandardOutput(); + if (success) { + } else { + qDebug() << text; + qDebug() << startProcess->readAllStandardError(); + } + delete startProcess; + return success; +} + +void Window::startProgress() +{ + progressDialog = new QDialog(this); + progressDialog->resize(300, 150); + progressDialog->setWindowTitle(tr("minikube start Progress")); + progressDialog->setWindowIcon(*trayIconIcon); + progressDialog->setWindowFlags(Qt::FramelessWindowHint); + progressDialog->setModal(true); + + QVBoxLayout form(progressDialog); + progressText = new QLabel(); + progressText->setText("Starting..."); + progressText->setWordWrap(true); + form.addWidget(progressText); + progressBar.setMaximum(19); + form.addWidget(&progressBar); + QPushButton *cancel = new QPushButton(tr("Cancel")); + connect(cancel, &QAbstractButton::clicked, startProcess, &QProcess::kill); + form.addWidget(cancel); + + progressDialog->open(); +} + +void Window::endProgress() +{ + progressDialog->hide(); + progressBar.setValue(0); +} + +void Window::startStep(QString step) +{ + QStringList lines; +#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0) + lines = step.split("\n", Qt::SkipEmptyParts); +#else + lines = step.split("\n", QString::SkipEmptyParts); +#endif + for (int i = 0; i < lines.size(); i++) { + QJsonDocument json = QJsonDocument::fromJson(lines[i].toUtf8()); + QJsonObject object = json.object(); + QString type = object["type"].toString(); + if (type != "io.k8s.sigs.minikube.step") { + return; + } + QJsonObject data = object["data"].toObject(); + QString stringStep = data["currentstep"].toString(); + int currStep = stringStep.toInt(); + QString message = data["message"].toString(); + progressBar.setValue(currStep); + progressText->setText(message); + } +} + static QString profile = "minikube"; static int cpus = 2; static int memory = 2400; diff --git a/gui/window.h b/gui/window.h index 7d65165bb4..dba9f1f95d 100644 --- a/gui/window.h +++ b/gui/window.h @@ -61,6 +61,7 @@ #include #include #include +#include #ifndef QT_NO_SYSTEMTRAYICON @@ -166,9 +167,19 @@ private: QComboBox *containerRuntimeComboBox; QComboBox *k8sVersionComboBox; - // Commands + // Start Commands void startMinikube(QStringList args); void startSelectedMinikube(); + bool sendMinikubeStart(QStringList cmds, QString &text); + void startProgress(); + void endProgress(); + void startStep(QString step); + QDialog *progressDialog; + QProgressBar progressBar; + QLabel *progressText; + QProcess *startProcess; + + // Other Commands void stopMinikube(); void pauseMinikube(); void unpauseMinikube();