Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implement automated updating on macOS #40

Merged
merged 3 commits into from
Mar 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .github/workflows/tag-and-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -76,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
Expand All @@ -86,4 +93,5 @@ jobs:
files: |
minikube-gui-linux.tar.gz
minikube-gui-macos.dmg
minikube-gui-macos.tar.gz
minikube-gui-windows.zip
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
65 changes: 64 additions & 1 deletion src/updater.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,13 @@ limitations under the License.
#include <QNetworkAccessManager>
#include <QNetworkReply>
#include <QStandardPaths>
#include <QProcess>

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()
Expand Down Expand Up @@ -92,7 +94,68 @@ void Updater::checkForUpdates()
key = "windows";
#endif
QString link = links[key].toString();
#if __APPLE__
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is good, we could later have a settings in the GUI settings to disable update notifications and or provide an option to auto update without even prompting or asking user (for smooth auto-update experiecne)

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)
Expand Down
5 changes: 4 additions & 1 deletion src/updater.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion src/window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down