From 420219083669f1fa958df2cde7b2b974bec94beb Mon Sep 17 00:00:00 2001 From: Steven Powell Date: Wed, 8 Mar 2023 13:44:51 -0800 Subject: [PATCH 1/3] implement automated updating on macOS --- src/updater.cpp | 65 ++++++++++++++++++++++++++++++++++++++++++++++++- src/updater.h | 5 +++- src/window.cpp | 2 +- 3 files changed, 69 insertions(+), 3 deletions(-) diff --git a/src/updater.cpp b/src/updater.cpp index b269533..291a0e9 100644 --- a/src/updater.cpp +++ b/src/updater.cpp @@ -28,11 +28,13 @@ limitations under the License. #include #include #include +#include -Updater::Updater(QVersionNumber version, QIcon icon) +Updater::Updater(QWidget *parent, QVersionNumber version, QIcon icon) { m_version = version; m_icon = icon; + m_parent = parent; } static bool checkedForUpdateRecently() @@ -92,7 +94,68 @@ void Updater::checkForUpdates() key = "windows"; #endif QString link = links[key].toString(); +#if __APPLE__ + askToUpdate(latestReleaseVersion, link); +#else notifyUpdate(latestReleaseVersion, link); +#endif +} + +void Updater::askToUpdate(QString latest, QString link) +{ + QDialog dialog; + dialog.setWindowTitle(tr("minikube GUI Update Available")); + dialog.setWindowIcon(m_icon); + dialog.setModal(true); + QFormLayout form(&dialog); + QLabel *msgLabel = new QLabel(); + msgLabel->setText("Version " + latest + + " of minikube GUI is now available!\n\nWould you like to update?"); + form.addWidget(msgLabel); + QDialogButtonBox buttonBox(Qt::Horizontal, &dialog); + buttonBox.addButton(QString(tr("Yes")), QDialogButtonBox::AcceptRole); + connect(&buttonBox, &QDialogButtonBox::accepted, &dialog, &QDialog::accept); + buttonBox.addButton(QString(tr("No")), QDialogButtonBox::RejectRole); + connect(&buttonBox, &QDialogButtonBox::rejected, &dialog, &QDialog::reject); + form.addRow(&buttonBox); + int code = dialog.exec(); + if (code == QDialog::Accepted) { + downloadUpdate(link); + } +} + +void Updater::downloadUpdate(QString link) +{ + QDialog dialog(m_parent); + dialog.setWindowTitle(tr("Downloading update")); + dialog.setWindowIcon(m_icon); + dialog.setModal(true); + QFormLayout form(&dialog); + QLabel *msgLabel = new QLabel("Downloading update, please wait..."); + form.addWidget(msgLabel); + dialog.open(); + QProcess *process = new QProcess(this); + QString cmd = QString("cd $TMPDIR && curl -LO %1 && tar -xf minikube-gui-macos.tar.gz && rm " + "minikube-gui-macos.tar.gz") + .arg(link); + process->start("bash", { "-c", cmd }); + process->waitForFinished(-1); + QDialogButtonBox buttonBox(Qt::Horizontal, &dialog); + buttonBox.addButton(QString(tr("Restart")), QDialogButtonBox::AcceptRole); + connect(&buttonBox, &QDialogButtonBox::accepted, &dialog, &QDialog::accept); + form.addRow(&buttonBox); + msgLabel->setText( + "Download complete!\n\nAfter clicking 'Restart' do the following:\n\n1. You will see: " + "\"minikube-gui cannot be opened...\" click 'Cancel'\n2. Your Appliciations folder " + "will be opened, right click on minikube-gui and click 'Open'"); + dialog.exec(); + process->start("bash", + { "-c", + "cd $TMPDIR && rm -rf /Applications/minikube-gui.app/ && mv " + "minikube-gui-macos/minikube-gui.app/ /Applications/ && rm -rf " + "minikube-gui-macos && open -R /Applications/minikube-gui.app/ && open " + "/Applications/minikube-gui.app/" }); + exit(0); } void Updater::notifyUpdate(QString latest, QString link) diff --git a/src/updater.h b/src/updater.h index 30e22fd..eb8aa69 100644 --- a/src/updater.h +++ b/src/updater.h @@ -25,14 +25,17 @@ class Updater : public QObject Q_OBJECT public: - explicit Updater(QVersionNumber version, QIcon icon); + explicit Updater(QWidget *parent, QVersionNumber version, QIcon icon); void checkForUpdates(); private: + void askToUpdate(QString latest, QString link); + void downloadUpdate(QString link); void notifyUpdate(QString latest, QString link); QString getRequest(QString url); QVersionNumber m_version; QIcon m_icon; + QWidget *m_parent; }; #endif // UPDATER_H diff --git a/src/window.cpp b/src/window.cpp index 7be0f09..339399c 100644 --- a/src/window.cpp +++ b/src/window.cpp @@ -52,7 +52,7 @@ Window::Window() progressWindow = new ProgressWindow(this, *trayIconIcon); tray = new Tray(*trayIconIcon); hyperKit = new HyperKit(*trayIconIcon); - updater = new Updater(version, *trayIconIcon); + updater = new Updater(this, version, *trayIconIcon); op = new Operator(advancedView, basicView, serviceView, addonsView, commandRunner, errorMessage, progressWindow, tray, hyperKit, updater, stackedWidget, this); From b2bdeb245d190cf4d3d8a24dcaded068b0a99b97 Mon Sep 17 00:00:00 2001 From: Steven Powell Date: Wed, 8 Mar 2023 13:52:49 -0800 Subject: [PATCH 2/3] build macOS tar.gz on release --- .github/workflows/tag-and-release.yml | 4 ++++ Makefile | 1 + 2 files changed, 5 insertions(+) diff --git a/.github/workflows/tag-and-release.yml b/.github/workflows/tag-and-release.yml index d315976..ae4fac9 100644 --- a/.github/workflows/tag-and-release.yml +++ b/.github/workflows/tag-and-release.yml @@ -39,6 +39,10 @@ jobs: with: name: minikube-gui-macos-release path: ./minikube-gui-macos.dmg + - uses: actions/upload-artifact@0b7f8abb1508181956e8e162db84b466c27e18ce + with: + name: minikube-gui-macos-tar-release + path: ./minikube-gui-macos.tar.gz build-windows-release: runs-on: windows-latest steps: diff --git a/Makefile b/Makefile index fb4a98c..e265cc3 100644 --- a/Makefile +++ b/Makefile @@ -24,6 +24,7 @@ build-macos: make (cd ./bin && macdeployqt ./minikube-gui.app -qmldir=. -verbose=1 -dmg) mv ./bin/minikube-gui.dmg ./minikube-gui-macos.dmg + tar -czf minikube-gui-macos.tar.gz ./bin .PHONY: build-windows build-windows: From ec75227646eaabdf728f3c02a48c56ccfa4c191a Mon Sep 17 00:00:00 2001 From: Steven Powell Date: Wed, 8 Mar 2023 13:54:55 -0800 Subject: [PATCH 3/3] upload macOS tar on release --- .github/workflows/tag-and-release.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/tag-and-release.yml b/.github/workflows/tag-and-release.yml index ae4fac9..94ffbf4 100644 --- a/.github/workflows/tag-and-release.yml +++ b/.github/workflows/tag-and-release.yml @@ -80,6 +80,9 @@ jobs: - uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a with: name: minikube-gui-macos-release + - uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a + with: + name: minikube-gui-macos-tar-release - uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a with: name: minikube-gui-windows-release @@ -90,4 +93,5 @@ jobs: files: | minikube-gui-linux.tar.gz minikube-gui-macos.dmg + minikube-gui-macos.tar.gz minikube-gui-windows.zip