mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2025-12-04 15:39:34 +01:00
Correct issues with system tray icon
* Close #5780 - Show window title as system tray icon tooltip * Fix #5943 - Try to show system tray icon up to 5 times, waiting 5 seconds between attempts, if the system tray is not available. This works around observed startup issues on Linux. * Change function of "isTrayIconEnabled()" to return true if the tray icon is created and visible. This may correct some long standing bugs with the window hiding forever unexpectedly.
This commit is contained in:
@@ -404,7 +404,6 @@ MainWindow::MainWindow()
|
||||
connect(m_ui->tabWidget, SIGNAL(currentChanged(int)), SLOT(updateWindowTitle()));
|
||||
connect(m_ui->tabWidget, SIGNAL(currentChanged(int)), SLOT(databaseTabChanged(int)));
|
||||
connect(m_ui->tabWidget, SIGNAL(currentChanged(int)), SLOT(setMenuActionState()));
|
||||
connect(m_ui->tabWidget, SIGNAL(currentChanged(int)), SLOT(updateTrayIcon()));
|
||||
connect(m_ui->tabWidget, SIGNAL(databaseLocked(DatabaseWidget*)), SLOT(databaseStatusChanged(DatabaseWidget*)));
|
||||
connect(m_ui->tabWidget, SIGNAL(databaseUnlocked(DatabaseWidget*)), SLOT(databaseStatusChanged(DatabaseWidget*)));
|
||||
connect(m_ui->tabWidget, SIGNAL(tabVisibilityChanged(bool)), SLOT(updateToolbarSeparatorVisibility()));
|
||||
@@ -929,6 +928,8 @@ void MainWindow::updateWindowTitle()
|
||||
|
||||
setWindowTitle(windowTitle);
|
||||
setWindowModified(isModified);
|
||||
|
||||
updateTrayIcon();
|
||||
}
|
||||
|
||||
void MainWindow::showAboutDialog()
|
||||
@@ -1169,8 +1170,7 @@ void MainWindow::closeEvent(QCloseEvent* event)
|
||||
void MainWindow::changeEvent(QEvent* event)
|
||||
{
|
||||
if ((event->type() == QEvent::WindowStateChange) && isMinimized()) {
|
||||
if (isTrayIconEnabled() && m_trayIcon && m_trayIcon->isVisible()
|
||||
&& config()->get(Config::GUI_MinimizeToTray).toBool()) {
|
||||
if (isTrayIconEnabled() && config()->get(Config::GUI_MinimizeToTray).toBool()) {
|
||||
event->ignore();
|
||||
hide();
|
||||
}
|
||||
@@ -1270,9 +1270,7 @@ bool MainWindow::saveLastDatabases()
|
||||
|
||||
void MainWindow::updateTrayIcon()
|
||||
{
|
||||
if (isTrayIconEnabled()) {
|
||||
QApplication::setQuitOnLastWindowClosed(false);
|
||||
|
||||
if (config()->get(Config::GUI_ShowTrayIcon).toBool()) {
|
||||
if (!m_trayIcon) {
|
||||
m_trayIcon = new QSystemTrayIcon(this);
|
||||
auto* menu = new QMenu(this);
|
||||
@@ -1284,40 +1282,46 @@ void MainWindow::updateTrayIcon()
|
||||
menu->addAction(m_ui->actionLockDatabases);
|
||||
|
||||
#ifdef Q_OS_MACOS
|
||||
QAction* actionQuit = new QAction(tr("Quit KeePassXC"), menu);
|
||||
menu->addAction(actionQuit);
|
||||
|
||||
auto actionQuit = new QAction(tr("Quit KeePassXC"), menu);
|
||||
connect(actionQuit, SIGNAL(triggered()), SLOT(appExit()));
|
||||
menu->addAction(actionQuit);
|
||||
#else
|
||||
menu->addAction(m_ui->actionQuit);
|
||||
|
||||
#endif
|
||||
m_trayIcon->setContextMenu(menu);
|
||||
|
||||
connect(m_trayIcon,
|
||||
SIGNAL(activated(QSystemTrayIcon::ActivationReason)),
|
||||
SLOT(trayIconTriggered(QSystemTrayIcon::ActivationReason)));
|
||||
connect(actionToggle, SIGNAL(triggered()), SLOT(toggleWindow()));
|
||||
|
||||
m_trayIcon->setContextMenu(menu);
|
||||
|
||||
m_trayIcon->setIcon(resources()->trayIcon());
|
||||
m_trayIcon->show();
|
||||
}
|
||||
|
||||
if (m_ui->tabWidget->count() == 0) {
|
||||
m_trayIcon->setIcon(resources()->trayIcon());
|
||||
} else if (m_ui->tabWidget->hasLockableDatabases()) {
|
||||
if (m_ui->tabWidget->hasLockableDatabases()) {
|
||||
m_trayIcon->setIcon(resources()->trayIconUnlocked());
|
||||
} else {
|
||||
m_trayIcon->setIcon(resources()->trayIconLocked());
|
||||
}
|
||||
} else {
|
||||
QApplication::setQuitOnLastWindowClosed(true);
|
||||
|
||||
m_trayIcon->setToolTip(windowTitle().replace("[*]", isWindowModified() ? "*" : ""));
|
||||
m_trayIcon->show();
|
||||
|
||||
if (!isTrayIconEnabled() || !QSystemTrayIcon::isSystemTrayAvailable()) {
|
||||
// Try to show tray icon after 5 seconds, try 5 times
|
||||
// This can happen if KeePassXC starts before the system tray is available
|
||||
static int trayIconAttempts = 0;
|
||||
if (trayIconAttempts < 5) {
|
||||
QTimer::singleShot(5000, this, &MainWindow::updateTrayIcon);
|
||||
++trayIconAttempts;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (m_trayIcon) {
|
||||
m_trayIcon->hide();
|
||||
delete m_trayIcon;
|
||||
}
|
||||
}
|
||||
|
||||
QApplication::setQuitOnLastWindowClosed(!isTrayIconEnabled());
|
||||
}
|
||||
|
||||
void MainWindow::obtainContextFocusLock()
|
||||
@@ -1559,7 +1563,7 @@ void MainWindow::forgetTouchIDAfterInactivity()
|
||||
|
||||
bool MainWindow::isTrayIconEnabled() const
|
||||
{
|
||||
return config()->get(Config::GUI_ShowTrayIcon).toBool() && QSystemTrayIcon::isSystemTrayAvailable();
|
||||
return m_trayIcon && m_trayIcon->isVisible();
|
||||
}
|
||||
|
||||
void MainWindow::displayGlobalMessage(const QString& text,
|
||||
|
||||
Reference in New Issue
Block a user