Skip to content
Snippets Groups Projects
Commit bb8f4cc3 authored by Andreas Traczyk's avatar Andreas Traczyk
Browse files

systray: fix crash on linux

QSystemTray::setContextMenu isn't working using a QScopedPointer on GNU/Linux, don't know why, not investigating.
Also, resetting the contextMenu has different behaviour on different platforms, so avoid that.

Change-Id: I3464e4c5e410a2c7028555b8177e0e56f7c5d1c3
parent 1d7d10a1
No related branches found
No related tags found
No related merge requests found
...@@ -371,8 +371,13 @@ MainApplication::initSystray() ...@@ -371,8 +371,13 @@ MainApplication::initSystray()
{ {
systemTray_->setIcon(QIcon(":/images/jami.svg")); systemTray_->setIcon(QIcon(":/images/jami.svg"));
// Create a new menu QMenu* menu {nullptr};
systemTrayMenu_.reset(new QMenu); // If there was a previous menu, reuse it, otherwise create a new one.
if ((menu = systemTray_->contextMenu())) {
menu->clear();
} else {
menu = new QMenu;
}
QString quitString; QString quitString;
#ifdef Q_OS_WINDOWS #ifdef Q_OS_WINDOWS
...@@ -381,10 +386,10 @@ MainApplication::initSystray() ...@@ -381,10 +386,10 @@ MainApplication::initSystray()
quitString = tr("&Quit"); quitString = tr("&Quit");
#endif #endif
QAction* quitAction = new QAction(quitString, systemTrayMenu_.get()); QAction* quitAction = new QAction(quitString, this);
connect(quitAction, &QAction::triggered, this, &MainApplication::closeRequested); connect(quitAction, &QAction::triggered, this, &MainApplication::closeRequested);
QAction* restoreAction = new QAction(tr("&Show Jami"), systemTrayMenu_.get()); QAction* restoreAction = new QAction(tr("&Show Jami"), this);
connect(restoreAction, &QAction::triggered, this, &MainApplication::restoreApp); connect(restoreAction, &QAction::triggered, this, &MainApplication::restoreApp);
connect(systemTray_, connect(systemTray_,
...@@ -395,20 +400,18 @@ MainApplication::initSystray() ...@@ -395,20 +400,18 @@ MainApplication::initSystray()
#ifdef Q_OS_WINDOWS #ifdef Q_OS_WINDOWS
restoreApp(); restoreApp();
#elif !defined(Q_OS_MACOS) #elif !defined(Q_OS_MACOS)
QWindow* window = focusWindow(); QWindow* window = focusWindow();
if (window) if (window)
window->close(); window->close();
else else
restoreApp(); restoreApp();
#endif #endif
} }
}); });
systemTrayMenu_->addAction(restoreAction); menu->addAction(restoreAction);
systemTrayMenu_->addAction(quitAction); menu->addAction(quitAction);
systemTray_->setContextMenu(menu);
// Set the new menu as the context menu
systemTray_->setContextMenu(systemTrayMenu_.get());
systemTray_->show(); systemTray_->show();
} }
......
...@@ -124,8 +124,5 @@ private: ...@@ -124,8 +124,5 @@ private:
ScreenInfo screenInfo_; ScreenInfo screenInfo_;
// We will recreate the system tray menu when the user changes the language.
QScopedPointer<QMenu> systemTrayMenu_;
bool isCleanupped; bool isCleanupped;
}; };
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment