add progress bar and messages to start

pull/14108/head
Steven Powell 2022-05-05 15:55:20 -07:00
parent 9d12786fac
commit 290a2504ff
2 changed files with 106 additions and 2 deletions

View File

@ -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;

View File

@ -61,6 +61,7 @@
#include <QVersionNumber>
#include <QtNetwork/QNetworkAccessManager>
#include <QtNetwork/QNetworkReply>
#include <QProgressBar>
#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();