Only call QSystemTrayIcon::isSystemTrayAvailable once
Workaround file descriptor leak Fixes #724
This commit is contained in:
@@ -43,6 +43,7 @@ class SystemTrayIcon : public QObject {
|
||||
~SystemTrayIcon();
|
||||
|
||||
bool isSystemTrayAvailable() { return true; }
|
||||
bool IsSystemTrayAvailable() { return true; }
|
||||
void setVisible(const bool) {}
|
||||
|
||||
void SetTrayiconProgress(const bool enabled);
|
||||
|
||||
@@ -927,7 +927,7 @@ MainWindow::MainWindow(Application *app, std::shared_ptr<SystemTrayIcon> tray_ic
|
||||
show();
|
||||
break;
|
||||
case BehaviourSettingsPage::Startup_Hide:
|
||||
if (tray_icon_->isSystemTrayAvailable() && tray_icon_->isVisible()) {
|
||||
if (tray_icon_->IsSystemTrayAvailable() && tray_icon_->isVisible()) {
|
||||
hide();
|
||||
break;
|
||||
}
|
||||
@@ -941,7 +941,7 @@ MainWindow::MainWindow(Application *app, std::shared_ptr<SystemTrayIcon> tray_ic
|
||||
was_minimized_ = settings_.value("minimized", false).toBool();
|
||||
if (was_minimized_) setWindowState(windowState() | Qt::WindowMinimized);
|
||||
|
||||
if (!tray_icon_->isSystemTrayAvailable() || !tray_icon_->isVisible()) {
|
||||
if (!tray_icon_->IsSystemTrayAvailable() || !tray_icon_->isVisible()) {
|
||||
hidden_ = false;
|
||||
settings_.setValue("hidden", false);
|
||||
show();
|
||||
@@ -1017,12 +1017,12 @@ void MainWindow::ReloadSettings() {
|
||||
|
||||
#ifndef Q_OS_MACOS
|
||||
s.beginGroup(BehaviourSettingsPage::kSettingsGroup);
|
||||
bool showtrayicon = s.value("showtrayicon", tray_icon_->isSystemTrayAvailable()).toBool();
|
||||
bool showtrayicon = s.value("showtrayicon", tray_icon_->IsSystemTrayAvailable()).toBool();
|
||||
s.endGroup();
|
||||
if (tray_icon_->isSystemTrayAvailable()) {
|
||||
if (tray_icon_->IsSystemTrayAvailable()) {
|
||||
tray_icon_->setVisible(showtrayicon);
|
||||
}
|
||||
if ((!showtrayicon || !tray_icon_->isSystemTrayAvailable()) && !isVisible()) {
|
||||
if ((!showtrayicon || !tray_icon_->IsSystemTrayAvailable()) && !isVisible()) {
|
||||
show();
|
||||
}
|
||||
#endif
|
||||
@@ -1182,7 +1182,7 @@ void MainWindow::Exit() {
|
||||
if (app_->player()->GetState() == Engine::Playing) {
|
||||
app_->player()->Stop();
|
||||
hide();
|
||||
if (tray_icon_->isSystemTrayAvailable()) {
|
||||
if (tray_icon_->IsSystemTrayAvailable()) {
|
||||
tray_icon_->setVisible(false);
|
||||
}
|
||||
return; // Don't quit the application now: wait for the fadeout finished signal
|
||||
@@ -1552,7 +1552,7 @@ void MainWindow::showEvent(QShowEvent *e) {
|
||||
void MainWindow::closeEvent(QCloseEvent *e) {
|
||||
|
||||
if (!exit_) {
|
||||
if (!hidden_ && keep_running_ && e->spontaneous() && tray_icon_->isSystemTrayAvailable()) {
|
||||
if (!hidden_ && keep_running_ && e->spontaneous() && tray_icon_->IsSystemTrayAvailable()) {
|
||||
SetHiddenInTray(true);
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -49,6 +49,7 @@ SystemTrayIcon::SystemTrayIcon(QObject *parent)
|
||||
action_stop_(nullptr),
|
||||
action_stop_after_this_track_(nullptr),
|
||||
action_mute_(nullptr),
|
||||
available_(false),
|
||||
trayicon_progress_(false),
|
||||
song_progress_(0) {
|
||||
|
||||
@@ -59,6 +60,7 @@ SystemTrayIcon::SystemTrayIcon(QObject *parent)
|
||||
}
|
||||
|
||||
if (isSystemTrayAvailable()) {
|
||||
available_ = true;
|
||||
setIcon(normal_icon_);
|
||||
setToolTip(app_name_);
|
||||
}
|
||||
@@ -100,7 +102,7 @@ void SystemTrayIcon::SetupMenu(QAction *previous, QAction *play, QAction *stop,
|
||||
menu_->addSeparator();
|
||||
menu_->addAction(quit->icon(), quit->text(), quit, &QAction::trigger);
|
||||
|
||||
if (isSystemTrayAvailable()) setContextMenu(menu_);
|
||||
if (available_) setContextMenu(menu_);
|
||||
|
||||
}
|
||||
|
||||
@@ -123,12 +125,12 @@ void SystemTrayIcon::Clicked(const QSystemTrayIcon::ActivationReason reason) {
|
||||
}
|
||||
|
||||
void SystemTrayIcon::ShowPopup(const QString &summary, const QString &message, const int timeout) {
|
||||
if (isSystemTrayAvailable()) showMessage(summary, message, QSystemTrayIcon::NoIcon, timeout);
|
||||
if (available_) showMessage(summary, message, QSystemTrayIcon::NoIcon, timeout);
|
||||
}
|
||||
|
||||
void SystemTrayIcon::UpdateIcon() {
|
||||
|
||||
if (isSystemTrayAvailable()) setIcon(CreateIcon(normal_icon_, grey_icon_));
|
||||
if (available_) setIcon(CreateIcon(normal_icon_, grey_icon_));
|
||||
|
||||
}
|
||||
|
||||
@@ -187,11 +189,11 @@ void SystemTrayIcon::MuteButtonStateChanged(const bool value) {
|
||||
}
|
||||
|
||||
void SystemTrayIcon::SetNowPlaying(const Song &song, const QUrl&) {
|
||||
if (isSystemTrayAvailable()) setToolTip(song.PrettyTitleWithArtist());
|
||||
if (available_) setToolTip(song.PrettyTitleWithArtist());
|
||||
}
|
||||
|
||||
void SystemTrayIcon::ClearNowPlaying() {
|
||||
if (isSystemTrayAvailable()) setToolTip(app_name_);
|
||||
if (available_) setToolTip(app_name_);
|
||||
}
|
||||
|
||||
void SystemTrayIcon::LoveVisibilityChanged(const bool value) {
|
||||
|
||||
@@ -44,6 +44,8 @@ class SystemTrayIcon : public QSystemTrayIcon {
|
||||
explicit SystemTrayIcon(QObject *parent = nullptr);
|
||||
~SystemTrayIcon() override;
|
||||
|
||||
bool IsSystemTrayAvailable() const { return available_; }
|
||||
|
||||
void SetTrayiconProgress(const bool enabled);
|
||||
|
||||
void SetupMenu(QAction *previous, QAction *play, QAction *stop, QAction *stop_after, QAction *next, QAction *mute, QAction *love, QAction *quit);
|
||||
@@ -93,6 +95,7 @@ class SystemTrayIcon : public QSystemTrayIcon {
|
||||
QAction *action_mute_;
|
||||
QAction *action_love_;
|
||||
|
||||
bool available_;
|
||||
bool trayicon_progress_;
|
||||
int song_progress_;
|
||||
|
||||
|
||||
@@ -435,7 +435,7 @@ bool OSDBase::SupportsNativeNotifications() {
|
||||
}
|
||||
|
||||
bool OSDBase::SupportsTrayPopups() {
|
||||
return tray_icon_->isSystemTrayAvailable();
|
||||
return tray_icon_->IsSystemTrayAvailable();
|
||||
}
|
||||
|
||||
void OSDBase::ShowMessageNative(const QString&, const QString&, const QString&, const QImage&) {
|
||||
|
||||
@@ -58,11 +58,13 @@ bool LocaleAwareCompare(const QString &a, const QString &b) {
|
||||
} // namespace
|
||||
#endif
|
||||
|
||||
BehaviourSettingsPage::BehaviourSettingsPage(SettingsDialog *dialog) : SettingsPage(dialog), ui_(new Ui_BehaviourSettingsPage) {
|
||||
BehaviourSettingsPage::BehaviourSettingsPage(SettingsDialog *dialog) : SettingsPage(dialog), ui_(new Ui_BehaviourSettingsPage), systemtray_available_(false) {
|
||||
|
||||
ui_->setupUi(this);
|
||||
setWindowIcon(IconLoader::Load("strawberry"));
|
||||
|
||||
systemtray_available_ = QSystemTrayIcon::isSystemTrayAvailable();
|
||||
|
||||
QObject::connect(ui_->checkbox_showtrayicon, &QCheckBox::toggled, this, &BehaviourSettingsPage::ShowTrayIconToggled);
|
||||
|
||||
#ifdef Q_OS_MACOS
|
||||
@@ -144,7 +146,7 @@ void BehaviourSettingsPage::Load() {
|
||||
s.beginGroup(kSettingsGroup);
|
||||
|
||||
#ifndef Q_OS_MACOS
|
||||
if (QSystemTrayIcon::isSystemTrayAvailable()) {
|
||||
if (systemtray_available_) {
|
||||
ui_->checkbox_showtrayicon->setEnabled(true);
|
||||
ui_->checkbox_showtrayicon->setChecked(s.value("showtrayicon", true).toBool());
|
||||
ui_->radiobutton_hide->setEnabled(true);
|
||||
@@ -157,7 +159,7 @@ void BehaviourSettingsPage::Load() {
|
||||
}
|
||||
#endif
|
||||
|
||||
if (QSystemTrayIcon::isSystemTrayAvailable()) {
|
||||
if (systemtray_available_) {
|
||||
ui_->checkbox_keeprunning->setEnabled(true);
|
||||
ui_->checkbox_keeprunning->setChecked(s.value("keeprunning", false).toBool());
|
||||
ui_->checkbox_trayicon_progress->setEnabled(true);
|
||||
@@ -186,7 +188,7 @@ void BehaviourSettingsPage::Load() {
|
||||
ui_->radiobutton_show_minimized->setChecked(true);
|
||||
break;
|
||||
case Startup_Hide:
|
||||
if (QSystemTrayIcon::isSystemTrayAvailable()) {
|
||||
if (systemtray_available_) {
|
||||
ui_->radiobutton_hide->setChecked(true);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -77,12 +77,13 @@ public:
|
||||
void Load() override;
|
||||
void Save() override;
|
||||
|
||||
private slots:
|
||||
private slots:
|
||||
void ShowTrayIconToggled(bool on);
|
||||
|
||||
private:
|
||||
private:
|
||||
Ui_BehaviourSettingsPage *ui_;
|
||||
QMap<QString, QString> language_map_;
|
||||
bool systemtray_available_;
|
||||
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user