From ae2ca175d38779ada4e753228b46b486070924bc Mon Sep 17 00:00:00 2001 From: Jonas Kvinge Date: Fri, 16 Apr 2021 18:27:24 +0200 Subject: [PATCH] Fix remembering hidden state Prevent SetHiddenInTray() or Exit() from being called again after qApp->quit() in MainWindow::closeEvent() --- src/core/mainwindow.cpp | 15 ++++++++++----- src/core/mainwindow.h | 1 + 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/core/mainwindow.cpp b/src/core/mainwindow.cpp index e8298d4c6..c1ee27fb3 100644 --- a/src/core/mainwindow.cpp +++ b/src/core/mainwindow.cpp @@ -315,6 +315,7 @@ MainWindow::MainWindow(Application *app, SystemTrayIcon *tray_icon, OSDBase *osd was_maximized_(true), was_minimized_(false), hidden_(false), + exit_(false), exit_count_(0), delete_files_(false) { @@ -1171,6 +1172,7 @@ void MainWindow::Exit() { if (exit_count_ > 1) { qApp->quit(); + exit_ = true; } else { if (app_->player()->engine()->is_fadeout_enabled()) { @@ -1192,6 +1194,7 @@ void MainWindow::DoExit() { QObject::connect(app_, &Application::ExitFinished, this, &MainWindow::ExitFinished); app_->Exit(); + exit_ = true; } @@ -1563,11 +1566,13 @@ void MainWindow::showEvent(QShowEvent *e) { void MainWindow::closeEvent(QCloseEvent *e) { - if (!hidden_ && keep_running_ && e->spontaneous() && QSystemTrayIcon::isSystemTrayAvailable()) { - SetHiddenInTray(true); - } - else { - Exit(); + if (!exit_) { + if (!hidden_ && keep_running_ && e->spontaneous() && QSystemTrayIcon::isSystemTrayAvailable()) { + SetHiddenInTray(true); + } + else { + Exit(); + } } QMainWindow::closeEvent(e); diff --git a/src/core/mainwindow.h b/src/core/mainwindow.h index 8b45554fe..c989ac2d7 100644 --- a/src/core/mainwindow.h +++ b/src/core/mainwindow.h @@ -390,6 +390,7 @@ class MainWindow : public QMainWindow, public PlatformInterface { Song song_; Song song_playing_; AlbumCoverImageResult album_cover_; + bool exit_; int exit_count_; bool delete_files_;