Browse Source

Reload system tray icon to replace menu

PR #18250.
Closes #18074.
adaptive-webui-19844
Vladimir Golovnev 2 years ago committed by GitHub
parent
commit
2310dcd136
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      src/app/application.cpp
  2. 32
      src/gui/desktopintegration.cpp
  3. 1
      src/gui/desktopintegration.h
  4. 3
      src/gui/mainwindow.cpp

2
src/app/application.cpp

@ -803,7 +803,6 @@ try
disconnect(m_desktopIntegration, &DesktopIntegration::activationRequested, this, &Application::createStartupProgressDialog); disconnect(m_desktopIntegration, &DesktopIntegration::activationRequested, this, &Application::createStartupProgressDialog);
// we must not delete menu while it is used by DesktopIntegration // we must not delete menu while it is used by DesktopIntegration
auto *oldMenu = m_desktopIntegration->menu();
#ifndef Q_OS_MACOS #ifndef Q_OS_MACOS
const WindowState windowState = !m_startupProgressDialog ? WindowState::Hidden const WindowState windowState = !m_startupProgressDialog ? WindowState::Hidden
: (m_startupProgressDialog->windowState() & Qt::WindowMinimized) ? WindowState::Minimized : (m_startupProgressDialog->windowState() & Qt::WindowMinimized) ? WindowState::Minimized
@ -813,7 +812,6 @@ try
? WindowState::Minimized : WindowState::Normal; ? WindowState::Minimized : WindowState::Normal;
#endif #endif
m_window = new MainWindow(this, windowState); m_window = new MainWindow(this, windowState);
delete oldMenu;
delete m_startupProgressDialog; delete m_startupProgressDialog;
#ifdef Q_OS_WIN #ifdef Q_OS_WIN
auto *pref = Preferences::instance(); auto *pref = Preferences::instance();

32
src/gui/desktopintegration.cpp

@ -99,6 +99,12 @@ DesktopIntegration::DesktopIntegration(QObject *parent)
connect(Preferences::instance(), &Preferences::changed, this, &DesktopIntegration::onPreferencesChanged); connect(Preferences::instance(), &Preferences::changed, this, &DesktopIntegration::onPreferencesChanged);
} }
DesktopIntegration::~DesktopIntegration()
{
if (m_menu)
delete m_menu;
}
bool DesktopIntegration::isActive() const bool DesktopIntegration::isActive() const
{ {
#ifdef Q_OS_MACOS #ifdef Q_OS_MACOS
@ -135,12 +141,36 @@ void DesktopIntegration::setMenu(QMenu *menu)
if (menu == m_menu) if (menu == m_menu)
return; return;
#if defined Q_OS_MACOS
if (m_menu)
delete m_menu;
m_menu = menu; m_menu = menu;
#ifdef Q_OS_MACOS
if (m_menu) if (m_menu)
m_menu->setAsDockMenu(); m_menu->setAsDockMenu();
#elif defined Q_OS_UNIX
const bool systemTrayEnabled = m_systrayIcon;
if (m_menu)
{
if (m_systrayIcon)
{
delete m_systrayIcon;
m_systrayIcon = nullptr;
}
delete m_menu;
}
m_menu = menu;
if (systemTrayEnabled && !m_systrayIcon)
createTrayIcon();
#else #else
if (m_menu)
delete m_menu;
m_menu = menu;
if (m_systrayIcon) if (m_systrayIcon)
m_systrayIcon->setContextMenu(m_menu); m_systrayIcon->setContextMenu(m_menu);
#endif #endif

1
src/gui/desktopintegration.h

@ -49,6 +49,7 @@ class DesktopIntegration final : public QObject
public: public:
explicit DesktopIntegration(QObject *parent = nullptr); explicit DesktopIntegration(QObject *parent = nullptr);
~DesktopIntegration() override;
bool isActive() const; bool isActive() const;

3
src/gui/mainwindow.cpp

@ -460,7 +460,6 @@ MainWindow::MainWindow(IGUIApplication *app, WindowState initialState)
MainWindow::~MainWindow() MainWindow::~MainWindow()
{ {
app()->desktopIntegration()->setMenu(nullptr);
delete m_ui; delete m_ui;
} }
@ -1570,7 +1569,7 @@ void MainWindow::downloadFromURLList(const QStringList &urlList)
QMenu *MainWindow::createDesktopIntegrationMenu() QMenu *MainWindow::createDesktopIntegrationMenu()
{ {
auto *menu = new QMenu(this); auto *menu = new QMenu;
#ifndef Q_OS_MACOS #ifndef Q_OS_MACOS
connect(menu, &QMenu::aboutToShow, this, [this]() connect(menu, &QMenu::aboutToShow, this, [this]()

Loading…
Cancel
Save