diff --git a/gui/releases.json b/gui/releases.json new file mode 100644 index 0000000000..7b4698cff5 --- /dev/null +++ b/gui/releases.json @@ -0,0 +1,5 @@ +[ + { + "name":"0.0.0" + } +] diff --git a/gui/systray.pro b/gui/systray.pro index 6d75f1e485..45c3639daf 100644 --- a/gui/systray.pro +++ b/gui/systray.pro @@ -6,7 +6,7 @@ SOURCES = main.cpp \ RESOURCES = systray.qrc ICON = images/minikube.icns -QT += widgets +QT += widgets network requires(qtConfig(combobox)) DISTFILES += \ diff --git a/gui/window.cpp b/gui/window.cpp index 90da636225..8af1f5c827 100644 --- a/gui/window.cpp +++ b/gui/window.cpp @@ -83,6 +83,7 @@ #include #include #include +#include #ifndef QT_NO_TERMWIDGET #include @@ -90,6 +91,8 @@ #include "qtermwidget.h" #endif +const QVersionNumber version = QVersionNumber::fromString("0.0.1"); + Window::Window() { trayIconIcon = new QIcon(":/images/minikube.png"); @@ -115,6 +118,7 @@ Window::Window() setWindowTitle(tr("minikube")); setWindowIcon(*trayIconIcon); + checkForUpdates(); } QProcessEnvironment Window::setMacEnv() @@ -910,10 +914,8 @@ void Window::sshConsole() mainWindow->show(); #elif __APPLE__ QString command = program + " ssh -p " + selectedClusterName(); - QStringList arguments = { "-e", "tell app \"Terminal\"", - "-e", "activate", - "-e", "do script \"" + command + "\"", - "-e", "end tell" }; + QStringList arguments = { "-e", "tell app \"Terminal\"", "-e", "activate", + "-e", "do script \"" + command + "\"", "-e", "end tell" }; QProcess *process = new QProcess(this); process->start("/usr/bin/osascript", arguments); #else @@ -982,4 +984,63 @@ void Window::checkForMinikube() exit(EXIT_FAILURE); } +void Window::checkForUpdates() +{ + QString releases = getRequest("https://storage.googleapis.com/minikube-gui/releases.json"); + QJsonObject latestRelease = + QJsonDocument::fromJson(releases.toUtf8()).array().first().toObject(); + QString latestReleaseVersion = latestRelease["name"].toString(); + QVersionNumber latestReleaseVersionNumber = QVersionNumber::fromString(latestReleaseVersion); + if (version >= latestReleaseVersionNumber) { + return; + } + QJsonObject links = latestRelease["links"].toObject(); + QString link; +#if __linux__ + link = links["linux"].toString(); +#elif __APPLE__ + link = links["darwin"].toString(); +#else + link = links["windows"].toString(); +#endif + notifyUpdate(latestReleaseVersion, link); +} + +void Window::notifyUpdate(QString latest, QString link) +{ + QDialog dialog; + dialog.setWindowTitle(tr("minikube GUI Update Available")); + dialog.setWindowIcon(*trayIconIcon); + dialog.setModal(true); + QFormLayout form(&dialog); + QLabel *msgLabel = new QLabel(this); + msgLabel->setText("Version " + latest + + " of minikube GUI is now available!\n\nDownload the update from:"); + form.addWidget(msgLabel); + QLabel *linkLabel = new QLabel(this); + linkLabel->setOpenExternalLinks(true); + linkLabel->setText("" + link + ""); + form.addWidget(linkLabel); + QDialogButtonBox buttonBox(Qt::Horizontal, &dialog); + buttonBox.addButton(QString(tr("OK")), QDialogButtonBox::AcceptRole); + connect(&buttonBox, &QDialogButtonBox::accepted, &dialog, &QDialog::accept); + form.addRow(&buttonBox); + dialog.exec(); +} + +QString Window::getRequest(QString url) +{ + QNetworkAccessManager *manager = new QNetworkAccessManager(); + QObject::connect(manager, &QNetworkAccessManager::finished, this, [=](QNetworkReply *reply) { + if (reply->error()) { + qDebug() << reply->errorString(); + } + }); + QNetworkReply *resp = manager->get(QNetworkRequest(QUrl(url))); + QEventLoop loop; + connect(resp, &QNetworkReply::finished, &loop, &QEventLoop::quit); + loop.exec(); + return resp->readAll(); +} + #endif diff --git a/gui/window.h b/gui/window.h index e7491dfd52..e306424a1e 100644 --- a/gui/window.h +++ b/gui/window.h @@ -58,6 +58,9 @@ #include #include #include +#include +#include +#include #ifndef QT_NO_SYSTEMTRAYICON @@ -193,6 +196,9 @@ private: bool isBasicView; void delay(); int getCenter(int widgetSize, int parentSize); + void checkForUpdates(); + QString getRequest(QString url); + void notifyUpdate(QString latest, QString link); }; #endif // QT_NO_SYSTEMTRAYICON