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()
{
systemTray_->setIcon(QIcon(":/images/jami.svg"));
// Create a new menu
systemTrayMenu_.reset(new QMenu);
QMenu* menu {nullptr};
// 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;
#ifdef Q_OS_WINDOWS
......@@ -381,10 +386,10 @@ MainApplication::initSystray()
quitString = tr("&Quit");
#endif
QAction* quitAction = new QAction(quitString, systemTrayMenu_.get());
QAction* quitAction = new QAction(quitString, this);
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(systemTray_,
......@@ -395,20 +400,18 @@ MainApplication::initSystray()
#ifdef Q_OS_WINDOWS
restoreApp();
#elif !defined(Q_OS_MACOS)
QWindow* window = focusWindow();
if (window)
window->close();
else
restoreApp();
QWindow* window = focusWindow();
if (window)
window->close();
else
restoreApp();
#endif
}
});
systemTrayMenu_->addAction(restoreAction);
systemTrayMenu_->addAction(quitAction);
// Set the new menu as the context menu
systemTray_->setContextMenu(systemTrayMenu_.get());
menu->addAction(restoreAction);
menu->addAction(quitAction);
systemTray_->setContextMenu(menu);
systemTray_->show();
}
......
......@@ -124,8 +124,5 @@ private:
ScreenInfo screenInfo_;
// We will recreate the system tray menu when the user changes the language.
QScopedPointer<QMenu> systemTrayMenu_;
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