Skip to content

Commit

Permalink
fixed crash with tray menu
Browse files Browse the repository at this point in the history
  • Loading branch information
Odizinne committed Sep 15, 2024
1 parent f36e1e6 commit 8c0fbf2
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 12 deletions.
31 changes: 19 additions & 12 deletions src/HeadsetControlQt/headsetcontrolqt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ HeadsetControlQt::HeadsetControlQt(QWidget *parent)
setWindowIcon(QIcon(":/icons/icon.png"));
initUI();
createTrayIcon();
createTrayMenu();
loadSettings();
setupUIConnections();
updateHeadsetInfo();
Expand Down Expand Up @@ -142,20 +141,19 @@ void HeadsetControlQt::checkStartupCheckbox()
void HeadsetControlQt::createTrayIcon()
{
trayIcon->setIcon(QIcon(":/icons/icon.png"));
trayIcon->show();
connect(trayIcon, &QSystemTrayIcon::activated, this, &HeadsetControlQt::trayIconActivated);
}
trayMenu = new QMenu(this);
showAction = new QAction(tr("Show"), this);
exitAction = new QAction(tr("Exit"), this);

void HeadsetControlQt::createTrayMenu()
{
QMenu *trayMenu = new QMenu(this);
QAction *showAction = new QAction(tr("Show"), this);
connect(showAction, &QAction::triggered, this, &HeadsetControlQt::toggleWindow);
trayMenu->addAction(showAction);
QAction *exitAction = new QAction(tr("Exit"), this);
connect(exitAction, &QAction::triggered, this, &QApplication::quit);

trayMenu->addAction(showAction);
trayMenu->addAction(exitAction);
trayIcon->setContextMenu(trayMenu);
trayIcon->show();

connect(trayIcon, &QSystemTrayIcon::activated, this, &HeadsetControlQt::trayIconActivated);
}

void HeadsetControlQt::createDefaultSettings()
Expand Down Expand Up @@ -580,7 +578,16 @@ void HeadsetControlQt::changeApplicationLanguage()
}

ui->retranslateUi(this);
delete trayIcon->contextMenu();
createTrayMenu();
updateTrayMenu();
saveSettings();
}

void HeadsetControlQt::updateTrayMenu()
{
if (this->isVisible()) {
showAction->setText(tr("Hide"));
} else {
showAction->setText(tr("Show"));
}
exitAction->setText(tr("Exit"));
}
4 changes: 4 additions & 0 deletions src/HeadsetControlQt/headsetcontrolqt.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ private slots:
void noDeviceFound();
void toggleUIElements(bool show);
void sendFirstMinimizeNotification();
void updateTrayMenu();
static const QString settingsFile;
static const QString headsetcontrolExecutable;
static const QString desktopFile;
Expand All @@ -73,6 +74,9 @@ private slots:
bool soundNotificationSent;
bool firstRun;
bool closing;
QMenu *trayMenu;
QAction *exitAction;
QAction *showAction;

QThread workerThread;
Worker *worker;
Expand Down

0 comments on commit 8c0fbf2

Please sign in to comment.