clicking the tray icon opens GUI

pull/14049/head
Steven Powell 2022-04-25 15:23:27 -07:00
parent 889ee1c5a3
commit 49e5551b31
2 changed files with 27 additions and 1 deletions

View File

@ -180,7 +180,6 @@ void Window::createAdvancedView()
connect(deleteButton, &QAbstractButton::clicked, this, &Window::deleteMinikube);
connect(refreshButton, &QAbstractButton::clicked, this, &Window::updateClusters);
connect(createButton, &QAbstractButton::clicked, this, &Window::initMachine);
connect(trayIcon, &QSystemTrayIcon::messageClicked, this, &Window::messageClicked);
clusterGroupBox->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
stackedWidget->addWidget(clusterGroupBox);
@ -230,12 +229,35 @@ void Window::createActions()
connect(quitAction, &QAction::triggered, qApp, &QCoreApplication::quit);
}
void Window::iconActivated(QSystemTrayIcon::ActivationReason reason)
{
switch (reason) {
case QSystemTrayIcon::Trigger:
case QSystemTrayIcon::DoubleClick:
Window::restoreWindow();
break;
default:;
}
}
void Window::restoreWindow()
{
bool wasVisible = isVisible();
QWidget::showNormal();
activateWindow();
if (wasVisible) {
return;
}
// without this delay window doesn't render until updateClusters() completes
delay();
updateClusters();
}
void Window::delay()
{
QCoreApplication::processEvents(QEventLoop::AllEvents, 100);
}
static QString minikubePath()
{
QString program = QStandardPaths::findExecutable("minikube");
@ -257,6 +279,8 @@ void Window::createTrayIcon()
trayIcon = new QSystemTrayIcon(this);
trayIcon->setContextMenu(trayIconMenu);
trayIcon->setIcon(*trayIconIcon);
connect(trayIcon, &QSystemTrayIcon::activated, this, &Window::iconActivated);
}
void Window::startMinikube(QStringList moreArgs)

View File

@ -102,6 +102,7 @@ private:
// Tray icon
void createTrayIcon();
void createActions();
void iconActivated(QSystemTrayIcon::ActivationReason reason);
QAction *minimizeAction;
QAction *restoreAction;
QAction *quitAction;
@ -179,6 +180,7 @@ private:
QProcessEnvironment setMacEnv();
QStackedWidget *stackedWidget;
bool isBasicView;
void delay();
};
#endif // QT_NO_SYSTEMTRAYICON