fix opening window during command running

pull/14238/head
Steven Powell 2022-05-27 11:42:13 -07:00
parent 59bf38f286
commit ead3e59064
9 changed files with 37 additions and 15 deletions

View File

@ -18,11 +18,13 @@ CommandRunner::CommandRunner(QDialog *parent)
void CommandRunner::executeMinikubeCommand(QStringList args) void CommandRunner::executeMinikubeCommand(QStringList args)
{ {
m_isRunning = true;
m_output = ""; m_output = "";
QStringList userArgs = { "--user", "minikube-gui" }; QStringList userArgs = { "--user", "minikube-gui" };
args << userArgs; args << userArgs;
m_process = new QProcess(m_parent); m_process = new QProcess(m_parent);
connect(m_process, QOverload<int, QProcess::ExitStatus>::of(&QProcess::finished), this, &CommandRunner::executionCompleted); connect(m_process, QOverload<int, QProcess::ExitStatus>::of(&QProcess::finished), this,
&CommandRunner::executionCompleted);
connect(m_process, &QProcess::readyReadStandardError, this, &CommandRunner::errorReady); connect(m_process, &QProcess::readyReadStandardError, this, &CommandRunner::errorReady);
connect(m_process, &QProcess::readyReadStandardOutput, this, &CommandRunner::outputReady); connect(m_process, &QProcess::readyReadStandardOutput, this, &CommandRunner::outputReady);
m_process->setProcessEnvironment(m_env); m_process->setProcessEnvironment(m_env);
@ -163,6 +165,7 @@ void CommandRunner::requestClusters()
void CommandRunner::executionCompleted() void CommandRunner::executionCompleted()
{ {
m_isRunning = false;
QString cmd = m_command; QString cmd = m_command;
m_command = ""; m_command = "";
QString output = m_output; QString output = m_output;
@ -212,3 +215,8 @@ void CommandRunner::minikubePath()
QStringList path = { "/usr/local/bin" }; QStringList path = { "/usr/local/bin" };
m_minikubePath = QStandardPaths::findExecutable("minikube", path); m_minikubePath = QStandardPaths::findExecutable("minikube", path);
} }
bool CommandRunner::isRunning()
{
return m_isRunning;
}

View File

@ -25,6 +25,7 @@ public:
void deleteMinikube(QStringList args); void deleteMinikube(QStringList args);
void stopCommand(); void stopCommand();
void requestClusters(); void requestClusters();
bool isRunning();
signals: signals:
void startingExecution(); void startingExecution();
@ -53,6 +54,7 @@ private:
QString m_command; QString m_command;
QDialog *m_parent; QDialog *m_parent;
QStringList m_args; QStringList m_args;
bool m_isRunning;
}; };
#endif // COMMANDRUNNER_H #endif // COMMANDRUNNER_H

View File

@ -13,7 +13,8 @@ ErrorMessage::ErrorMessage(QDialog *parent, QIcon icon)
m_icon = icon; m_icon = icon;
} }
void ErrorMessage::error(QString errorCode, QString advice, QString message, QString url, QString issues) void ErrorMessage::error(QString errorCode, QString advice, QString message, QString url,
QString issues)
{ {
m_dialog = new QDialog(m_parent); m_dialog = new QDialog(m_parent);

View File

@ -14,7 +14,8 @@ class ErrorMessage : public QObject
public: public:
explicit ErrorMessage(QDialog *parent, QIcon icon); explicit ErrorMessage(QDialog *parent, QIcon icon);
void error(QString errorCode, QString advice, QString errorMessage, QString url, QString issues); void error(QString errorCode, QString advice, QString errorMessage, QString url,
QString issues);
QLabel *createLabel(QString title, QString text, QFormLayout *form, bool isLink); QLabel *createLabel(QString title, QString text, QFormLayout *form, bool isLink);
private: private:

View File

@ -5,7 +5,10 @@
#include <QJsonDocument> #include <QJsonDocument>
#include <QStandardPaths> #include <QStandardPaths>
Operator::Operator(AdvancedView *advancedView, BasicView *basicView, CommandRunner *commandRunner, ErrorMessage *errorMessage, ProgressWindow *progressWindow, Tray *tray, HyperKit *hyperKit, Updater *updater, QStackedWidget *stackedWidget, QDialog *parent) Operator::Operator(AdvancedView *advancedView, BasicView *basicView, CommandRunner *commandRunner,
ErrorMessage *errorMessage, ProgressWindow *progressWindow, Tray *tray,
HyperKit *hyperKit, Updater *updater, QStackedWidget *stackedWidget,
QDialog *parent)
{ {
m_advancedView = advancedView; m_advancedView = advancedView;
m_basicView = basicView; m_basicView = basicView;
@ -37,14 +40,16 @@ Operator::Operator(AdvancedView *advancedView, BasicView *basicView, CommandRunn
connect(m_advancedView, &AdvancedView::dashboard, this, &Operator::dashboardBrowser); connect(m_advancedView, &AdvancedView::dashboard, this, &Operator::dashboardBrowser);
connect(m_advancedView, &AdvancedView::basic, this, &Operator::toBasicView); connect(m_advancedView, &AdvancedView::basic, this, &Operator::toBasicView);
connect(m_advancedView, &AdvancedView::createCluster, this, &Operator::createCluster); connect(m_advancedView, &AdvancedView::createCluster, this, &Operator::createCluster);
connect(m_advancedView->clusterListView, SIGNAL(clicked(QModelIndex)), this, SLOT(updateButtons())); connect(m_advancedView->clusterListView, SIGNAL(clicked(QModelIndex)), this,
SLOT(updateButtons()));
connect(m_commandRunner, &CommandRunner::startingExecution, this, &Operator::commandStarting); connect(m_commandRunner, &CommandRunner::startingExecution, this, &Operator::commandStarting);
connect(m_commandRunner, &CommandRunner::executionEnded, this, &Operator::commandEnding); connect(m_commandRunner, &CommandRunner::executionEnded, this, &Operator::commandEnding);
connect(m_commandRunner, &CommandRunner::output, this, &Operator::commandOutput); connect(m_commandRunner, &CommandRunner::output, this, &Operator::commandOutput);
connect(m_commandRunner, &CommandRunner::error, this, &Operator::commandError); connect(m_commandRunner, &CommandRunner::error, this, &Operator::commandError);
connect(m_commandRunner, &CommandRunner::updatedClusters, this, &Operator::clustersReceived); connect(m_commandRunner, &CommandRunner::updatedClusters, this, &Operator::clustersReceived);
connect(m_commandRunner, &CommandRunner::startCommandStarting, this, &Operator::startCommandStarting); connect(m_commandRunner, &CommandRunner::startCommandStarting, this,
&Operator::startCommandStarting);
connect(m_progressWindow, &ProgressWindow::cancelled, this, &Operator::cancelCommand); connect(m_progressWindow, &ProgressWindow::cancelled, this, &Operator::cancelCommand);
@ -185,6 +190,8 @@ void Operator::restoreWindow()
if (wasVisible) { if (wasVisible) {
return; return;
} }
if (m_commandRunner->isRunning())
return;
updateClusters(); updateClusters();
} }

View File

@ -18,7 +18,9 @@ class Operator : public QObject
Q_OBJECT Q_OBJECT
public: public:
Operator(AdvancedView *advancedView, BasicView *basicView, CommandRunner *commandRunner, ErrorMessage *errorMessage, ProgressWindow *progressWindow, Tray *tray, HyperKit *hyperKit, Updater *updater, QStackedWidget *stackedWidget, QDialog *parent); Operator(AdvancedView *advancedView, BasicView *basicView, CommandRunner *commandRunner,
ErrorMessage *errorMessage, ProgressWindow *progressWindow, Tray *tray,
HyperKit *hyperKit, Updater *updater, QStackedWidget *stackedWidget, QDialog *parent);
public slots: public slots:
void startMinikube(); void startMinikube();

View File

@ -1,8 +1,8 @@
#include "tray.h" #include "tray.h"
#include<QAction> #include <QAction>
#include<QCoreApplication> #include <QCoreApplication>
#include<QMenu> #include <QMenu>
Tray::Tray(QIcon icon) Tray::Tray(QIcon icon)
{ {

View File

@ -13,7 +13,6 @@
#include <QStandardPaths> #include <QStandardPaths>
#include <QDir> #include <QDir>
Updater::Updater(QVersionNumber version, QIcon icon) Updater::Updater(QVersionNumber version, QIcon icon)
{ {
m_version = version; m_version = version;
@ -22,7 +21,8 @@ Updater::Updater(QVersionNumber version, QIcon icon)
static bool checkedForUpdateRecently() static bool checkedForUpdateRecently()
{ {
QString filePath = QStandardPaths::locate(QStandardPaths::HomeLocation, "/.minikube-gui/last_update_check"); QString filePath = QStandardPaths::locate(QStandardPaths::HomeLocation,
"/.minikube-gui/last_update_check");
if (filePath == "") { if (filePath == "") {
return false; return false;
} }
@ -32,14 +32,14 @@ static bool checkedForUpdateRecently()
} }
QTextStream in(&file); QTextStream in(&file);
QString line = in.readLine(); QString line = in.readLine();
QDateTime nextCheck = QDateTime::fromString(line).addSecs(60*60*24); QDateTime nextCheck = QDateTime::fromString(line).addSecs(60 * 60 * 24);
QDateTime now = QDateTime::currentDateTime(); QDateTime now = QDateTime::currentDateTime();
return nextCheck > now; return nextCheck > now;
} }
static void logUpdateCheck() static void logUpdateCheck()
{ {
QDir dir = QDir(QDir::homePath() + "/.minikube-gui"); QDir dir = QDir(QDir::homePath() + "/.minikube-gui");
if (!dir.exists()) { if (!dir.exists()) {
dir.mkpath("."); dir.mkpath(".");
} }

View File

@ -108,7 +108,8 @@ Window::Window()
hyperKit = new HyperKit(*trayIconIcon); hyperKit = new HyperKit(*trayIconIcon);
updater = new Updater(version, *trayIconIcon); updater = new Updater(version, *trayIconIcon);
op = new Operator(advancedView, basicView, commandRunner, errorMessage, progressWindow, tray, hyperKit, updater, stackedWidget, this); op = new Operator(advancedView, basicView, commandRunner, errorMessage, progressWindow, tray,
hyperKit, updater, stackedWidget, this);
stackedWidget->addWidget(basicView->basicView); stackedWidget->addWidget(basicView->basicView);
stackedWidget->addWidget(advancedView->advancedView); stackedWidget->addWidget(advancedView->advancedView);