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