1
0
Fork 0
mirror of https://git.jami.net/savoirfairelinux/jami-client-qt.git synced 2025-08-04 06:45:45 +02:00

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
This commit is contained in:
Andreas Traczyk 2023-11-24 12:01:19 -05:00
parent 1d7d10a12d
commit bb8f4cc3a7
2 changed files with 17 additions and 17 deletions

View file

@ -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()
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_,
@ -404,11 +409,9 @@ MainApplication::initSystray()
} }
}); });
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();
} }

View file

@ -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;
}; };