From 3d9e14e001df58d77bad22076a0c3fc5f3338f5d Mon Sep 17 00:00:00 2001 From: Integral Date: Sun, 1 Feb 2026 21:17:16 +0800 Subject: [PATCH] Change "Show" to "Hide" in tray icon menu when the window is visible This change updates the tray icon menu action to reflect the current state of the window. Closes: #2000 --- src/TrayIcon.cpp | 14 +++++++++++--- src/TrayIcon.h | 2 +- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/TrayIcon.cpp b/src/TrayIcon.cpp index 5fe6b4dc..0493e620 100644 --- a/src/TrayIcon.cpp +++ b/src/TrayIcon.cpp @@ -107,13 +107,21 @@ TrayIcon::TrayIcon(const QString &filename, QWindow *parent) QMenu *menu = new QMenu(); setContextMenu(menu); - viewAction_ = new QAction(tr("Show"), this); + toggleAction_ = new QAction(tr("Show"), this); quitAction_ = new QAction(tr("Quit"), this); - connect(viewAction_, &QAction::triggered, parent, &QWindow::show); + connect(toggleAction_, &QAction::triggered, parent, [=, this](){ + if (parent->isVisible()) { + parent->hide(); + toggleAction_->setText(tr("Show")); + } else { + parent->show(); + toggleAction_->setText(tr("Hide")); + } + }); connect(quitAction_, &QAction::triggered, this, QApplication::quit); - menu->addAction(viewAction_); + menu->addAction(toggleAction_); menu->addAction(quitAction_); QString toolTip = QLatin1String("nheko"); diff --git a/src/TrayIcon.h b/src/TrayIcon.h index 7c0bc7b2..5ed0dad1 100644 --- a/src/TrayIcon.h +++ b/src/TrayIcon.h @@ -40,7 +40,7 @@ public slots: void setUnreadCount(int count); private: - QAction *viewAction_; + QAction *toggleAction_; QAction *quitAction_; int previousCount = 0;