Skip to content

Commit

Permalink
fix app quit logic
Browse files Browse the repository at this point in the history
  • Loading branch information
ddanilov committed Sep 17, 2023
1 parent 14741db commit 518a29a
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
2 changes: 0 additions & 2 deletions .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,6 @@ IndentWidth: 2
#PackConstructorInitializers: CurrentLine
PointerAlignment: Left

ReferenceAlignment: Left

#QualifierAlignment: Left

ReferenceAlignment: Left
Expand Down
17 changes: 12 additions & 5 deletions src/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
#include "TrackControls.h"
#include "Version.h"

#include <QApplication>
#include <QCloseEvent>
#include <QCoreApplication>
#include <QFileDialog>
#include <QJsonArray>
#include <QJsonDocument>
Expand Down Expand Up @@ -98,7 +98,7 @@ void MainWindow::addQuitItemToMenu(QMenu* menu) const
#endif

auto* quit_app = menu->addAction(tr("Quit"));
connect(quit_app, &QAction::triggered, qApp, &QCoreApplication::quit);
connect(quit_app, &QAction::triggered, this, &MainWindow::quit);
}

#if defined(Q_OS_WIN) || defined(Q_OS_LINUX)
Expand Down Expand Up @@ -222,14 +222,12 @@ void MainWindow::resumePausedTracks()
#if defined(Q_OS_WIN) || defined(Q_OS_LINUX)
void MainWindow::closeEvent(QCloseEvent* event)
{
if (!m_tray_available)
if (m_quit || !m_tray_available)
{
event->accept();
return;
}

if (!m_tray_icon->isVisible()) { event->accept(); }

windowHide();
event->ignore();
}
Expand All @@ -243,6 +241,15 @@ void MainWindow::mousePressEvent(QMouseEvent* event)
}
}

void MainWindow::quit()
{
#if defined(Q_OS_WIN) || defined(Q_OS_LINUX)
m_quit = true;
#endif

QApplication::quit();
}

#if defined(Q_OS_WIN) || defined(Q_OS_LINUX)
void MainWindow::setupTrayIcon()
{
Expand Down
5 changes: 5 additions & 0 deletions src/MainWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#pragma once

#include <QAtomicInteger>
#include <QFile>
#include <QLabel>
#include <QMainWindow>
Expand Down Expand Up @@ -48,6 +49,9 @@ public slots:
#endif
void mousePressEvent(QMouseEvent* event) override;

private slots:
void quit();

private:
#if defined(Q_OS_WIN) || defined(Q_OS_LINUX)
void setupTrayIcon();
Expand All @@ -66,6 +70,7 @@ public slots:
bool m_tray_available;
QPointer<QSystemTrayIcon> m_tray_icon;
QPointer<QMenu> m_tray_menu;
QAtomicInteger<bool> m_quit{false};
#endif
QPointer<QMenu> m_mouse_menu;
#if defined(Q_OS_LINUX)
Expand Down

0 comments on commit 518a29a

Please sign in to comment.