From 47a0d30e570f3e6a40e53290f957e6aa8a70cda1 Mon Sep 17 00:00:00 2001 From: Tobias Fella Date: Fri, 25 Feb 2022 16:41:21 +0100 Subject: [PATCH] Fix quitting without tray icon Setting KSNI status to Passive doesn't *disable* the tray icon, it just moves it to the overflow menu. This causes the application to not quit when closing the app even when disabling the tray icon --- src/controller.cpp | 18 ++++++++++-------- src/controller.h | 2 ++ 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/controller.cpp b/src/controller.cpp index 629f84103..92defd35d 100644 --- a/src/controller.cpp +++ b/src/controller.cpp @@ -70,19 +70,21 @@ Controller::Controller(QObject *parent) Connection::setUserType(); #ifndef Q_OS_ANDROID - TrayIcon *trayIcon = new TrayIcon(this); if (NeoChatConfig::self()->systemTray()) { - trayIcon->show(); - connect(trayIcon, &TrayIcon::showWindow, this, &Controller::showWindow); + m_trayIcon = new TrayIcon(this); + m_trayIcon->show(); + connect(m_trayIcon, &TrayIcon::showWindow, this, &Controller::showWindow); QGuiApplication::setQuitOnLastWindowClosed(false); } - connect(NeoChatConfig::self(), &NeoChatConfig::SystemTrayChanged, this, [this, trayIcon]() { + connect(NeoChatConfig::self(), &NeoChatConfig::SystemTrayChanged, this, [this]() { if (NeoChatConfig::self()->systemTray()) { - trayIcon->show(); - connect(trayIcon, &TrayIcon::showWindow, this, &Controller::showWindow); + m_trayIcon = new TrayIcon(this); + m_trayIcon->show(); + connect(m_trayIcon, &TrayIcon::showWindow, this, &Controller::showWindow); } else { - trayIcon->hide(); - disconnect(trayIcon, &TrayIcon::showWindow, this, &Controller::showWindow); + disconnect(m_trayIcon, &TrayIcon::showWindow, this, &Controller::showWindow); + delete m_trayIcon; + m_trayIcon = nullptr; } QGuiApplication::setQuitOnLastWindowClosed(!NeoChatConfig::self()->systemTray()); }); diff --git a/src/controller.h b/src/controller.h index 889f38ac4..eef1342fd 100644 --- a/src/controller.h +++ b/src/controller.h @@ -19,6 +19,7 @@ class QKeySequences; class NeoChatRoom; class NeoChatUser; +class TrayIcon; class QQuickWindow; namespace QKeychain @@ -100,6 +101,7 @@ private: QPointer m_connection; bool m_busy = false; + TrayIcon *m_trayIcon = nullptr; static QByteArray loadAccessTokenFromFile(const AccountSettings &account); QKeychain::ReadPasswordJob *loadAccessTokenFromKeyChain(const AccountSettings &account);