commit
12d22dd338
|
@ -7,16 +7,34 @@
|
|||
#include <QJsonParseError>
|
||||
#include <QDebug>
|
||||
|
||||
CommandRunner::CommandRunner(QDialog *parent)
|
||||
CommandRunner::CommandRunner(QDialog *parent, Logger *logger)
|
||||
{
|
||||
m_env = QProcessEnvironment::systemEnvironment();
|
||||
m_parent = parent;
|
||||
m_logger = logger;
|
||||
minikubePath();
|
||||
#if __APPLE__
|
||||
setMinikubePath();
|
||||
#endif
|
||||
}
|
||||
|
||||
void CommandRunner::executeCommand(QString program, QStringList args)
|
||||
{
|
||||
QProcess *process = new QProcess(this);
|
||||
process->setProcessEnvironment(m_env);
|
||||
process->start(program, args);
|
||||
process->waitForFinished(-1);
|
||||
if (process->exitCode() == 0) {
|
||||
return;
|
||||
}
|
||||
QString out = process->readAllStandardOutput();
|
||||
QString err = process->readAllStandardError();
|
||||
QString log = QString("The following command failed:\n%1 %2\n\nStdout:\n%3\n\nStderr:\n%4\n\n")
|
||||
.arg(program, args.join(" "), out, err);
|
||||
m_logger->log(log);
|
||||
delete process;
|
||||
}
|
||||
|
||||
void CommandRunner::executeMinikubeCommand(QStringList args)
|
||||
{
|
||||
m_isRunning = true;
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
#define COMMANDRUNNER_H
|
||||
|
||||
#include "cluster.h"
|
||||
#include "logger.h"
|
||||
|
||||
#include <QString>
|
||||
#include <QDialog>
|
||||
|
@ -16,8 +17,9 @@ class CommandRunner : public QObject
|
|||
Q_OBJECT
|
||||
|
||||
public:
|
||||
CommandRunner(QDialog *parent);
|
||||
CommandRunner(QDialog *parent, Logger *logger);
|
||||
|
||||
void executeCommand(QString program, QStringList args);
|
||||
void startMinikube(QStringList args);
|
||||
void stopMinikube(QStringList args);
|
||||
void pauseMinikube(QStringList args);
|
||||
|
@ -53,6 +55,7 @@ private:
|
|||
QString m_minikubePath;
|
||||
QString m_command;
|
||||
QDialog *m_parent;
|
||||
Logger *m_logger;
|
||||
QStringList m_args;
|
||||
bool m_isRunning;
|
||||
};
|
||||
|
|
|
@ -0,0 +1,26 @@
|
|||
#include "logger.h"
|
||||
|
||||
#include <QStandardPaths>
|
||||
#include <QFile>
|
||||
#include <QDir>
|
||||
#include <QTextStream>
|
||||
|
||||
Logger::Logger()
|
||||
{
|
||||
QDir dir = QDir(QDir::homePath() + "/.minikube-gui");
|
||||
if (!dir.exists()) {
|
||||
dir.mkpath(".");
|
||||
}
|
||||
m_logPath = dir.filePath("logs.txt");
|
||||
}
|
||||
|
||||
void Logger::log(QString message)
|
||||
{
|
||||
QFile file(m_logPath);
|
||||
if (!file.open(QIODevice::Append)) {
|
||||
return;
|
||||
}
|
||||
QTextStream stream(&file);
|
||||
stream << message << "\n";
|
||||
file.close();
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
#ifndef LOGGER_H
|
||||
#define LOGGER_H
|
||||
|
||||
#include <QObject>
|
||||
|
||||
class Logger : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit Logger();
|
||||
void log(QString message);
|
||||
|
||||
private:
|
||||
QString m_logPath;
|
||||
};
|
||||
|
||||
#endif // LOGGER_H
|
|
@ -60,14 +60,14 @@
|
|||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
Q_INIT_RESOURCE(systray);
|
||||
Q_INIT_RESOURCE(minikube);
|
||||
|
||||
QCoreApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);
|
||||
|
||||
QApplication app(argc, argv);
|
||||
|
||||
if (!QSystemTrayIcon::isSystemTrayAvailable()) {
|
||||
QMessageBox::critical(0, QObject::tr("Systray"),
|
||||
QMessageBox::critical(0, QObject::tr("minikube"),
|
||||
QObject::tr("I couldn't detect any system tray "
|
||||
"on this system."));
|
||||
return 1;
|
||||
|
|
|
@ -5,6 +5,7 @@ HEADERS = window.h \
|
|||
commandrunner.h \
|
||||
errormessage.h \
|
||||
hyperkit.h \
|
||||
logger.h \
|
||||
operator.h \
|
||||
progresswindow.h \
|
||||
tray.h \
|
||||
|
@ -16,12 +17,13 @@ SOURCES = main.cpp \
|
|||
commandrunner.cpp \
|
||||
errormessage.cpp \
|
||||
hyperkit.cpp \
|
||||
logger.cpp \
|
||||
operator.cpp \
|
||||
progresswindow.cpp \
|
||||
tray.cpp \
|
||||
updater.cpp \
|
||||
window.cpp
|
||||
RESOURCES = systray.qrc
|
||||
RESOURCES = minikube.qrc
|
||||
ICON = images/minikube.icns
|
||||
|
||||
QT += widgets network
|
|
@ -335,8 +335,7 @@ void Operator::sshConsole()
|
|||
"-e", "do script \"" + command + "\"",
|
||||
"-e", "activate",
|
||||
"-e", "end tell" };
|
||||
QProcess *process = new QProcess(this);
|
||||
process->start("/usr/bin/osascript", arguments);
|
||||
m_commandRunner->executeCommand("/usr/bin/osascript", arguments);
|
||||
#else
|
||||
QString terminal = qEnvironmentVariable("TERMINAL");
|
||||
if (terminal.isEmpty()) {
|
||||
|
@ -346,8 +345,7 @@ void Operator::sshConsole()
|
|||
}
|
||||
}
|
||||
|
||||
QProcess *process = new QProcess(this);
|
||||
process->start(QStandardPaths::findExecutable(terminal), { "-e", command });
|
||||
m_commandRunner->executeCommand(QStandardPaths::findExecutable(terminal), { "-e", command });
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -383,8 +381,7 @@ void Operator::dockerEnv()
|
|||
"-e", "do script \"" + command + "\"",
|
||||
"-e", "activate",
|
||||
"-e", "end tell" };
|
||||
QProcess *process = new QProcess(this);
|
||||
process->start("/usr/bin/osascript", arguments);
|
||||
m_commandRunner->executeCommand("/usr/bin/osascript", arguments);
|
||||
#else
|
||||
QString terminal = qEnvironmentVariable("TERMINAL");
|
||||
if (terminal.isEmpty()) {
|
||||
|
@ -394,8 +391,7 @@ void Operator::dockerEnv()
|
|||
}
|
||||
}
|
||||
|
||||
QProcess *process = new QProcess(this);
|
||||
process->start(QStandardPaths::findExecutable(terminal), { "-e", command });
|
||||
m_commandRunner->executeCommand(QStandardPaths::findExecutable(terminal), { "-e", command });
|
||||
#endif
|
||||
}
|
||||
|
||||
|
|
|
@ -99,7 +99,8 @@ Window::Window()
|
|||
checkForMinikube();
|
||||
|
||||
stackedWidget = new QStackedWidget;
|
||||
commandRunner = new CommandRunner(this);
|
||||
logger = new Logger();
|
||||
commandRunner = new CommandRunner(this, logger);
|
||||
basicView = new BasicView();
|
||||
advancedView = new AdvancedView(*trayIconIcon);
|
||||
errorMessage = new ErrorMessage(this, *trayIconIcon);
|
||||
|
@ -135,7 +136,7 @@ void Window::closeEvent(QCloseEvent *event)
|
|||
}
|
||||
#endif
|
||||
if (tray->isVisible()) {
|
||||
QMessageBox::information(this, tr("Systray"),
|
||||
QMessageBox::information(this, tr("minikube"),
|
||||
tr("The program will keep running in the "
|
||||
"system tray. To terminate the program, "
|
||||
"choose <b>Quit</b> in the context menu "
|
||||
|
|
|
@ -83,7 +83,6 @@ class QTableView;
|
|||
class QProcess;
|
||||
QT_END_NAMESPACE
|
||||
|
||||
#include "cluster.h"
|
||||
#include "basicview.h"
|
||||
#include "advancedview.h"
|
||||
#include "progresswindow.h"
|
||||
|
@ -92,6 +91,7 @@ QT_END_NAMESPACE
|
|||
#include "tray.h"
|
||||
#include "hyperkit.h"
|
||||
#include "updater.h"
|
||||
#include "logger.h"
|
||||
|
||||
class Window : public QDialog
|
||||
{
|
||||
|
@ -125,6 +125,7 @@ private:
|
|||
HyperKit *hyperKit;
|
||||
Updater *updater;
|
||||
QVBoxLayout *layout;
|
||||
Logger *logger;
|
||||
};
|
||||
|
||||
#endif // QT_NO_SYSTEMTRAYICON
|
||||
|
|
Loading…
Reference in New Issue