From d29a1de9804193c2dd6f4732749f507b1f3a0273 Mon Sep 17 00:00:00 2001 From: Jonas Kvinge Date: Sun, 24 Oct 2021 23:09:20 +0200 Subject: [PATCH] Allow users to select native notifications on Windows Setting will fallback to system tray notifications which are native notifications on Windows. --- src/osd/osdbase.cpp | 17 ++++++++++++++--- src/settings/notificationssettingspage.cpp | 14 +++++++++++++- 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/src/osd/osdbase.cpp b/src/osd/osdbase.cpp index bdc1c320..69b9a4a4 100644 --- a/src/osd/osdbase.cpp +++ b/src/osd/osdbase.cpp @@ -89,7 +89,11 @@ void OSDBase::ReloadSettings() { custom_text2_ = s.value("CustomText2").toString(); s.endGroup(); +#ifdef Q_OS_WIN32 + if (!SupportsNativeNotifications() && !SupportsTrayPopups() && behaviour_ == Native) { +#else if (!SupportsNativeNotifications() && behaviour_ == Native) { +#endif behaviour_ = Pretty; } @@ -302,6 +306,10 @@ void OSDBase::ShowMessage(const QString &summary, const QString &message, const else { switch (behaviour_) { case Native: +#ifdef Q_OS_WIN32 + Q_UNUSED(icon) + // fallthrough +#else if (image.isNull()) { ShowMessageNative(summary, message, icon, QImage()); } @@ -309,13 +317,14 @@ void OSDBase::ShowMessage(const QString &summary, const QString &message, const ShowMessageNative(summary, message, QString(), image); } break; - -#ifndef Q_OS_MACOS +#endif case TrayPopup: +#ifdef Q_OS_MACOS + // fallthrough +#else if (tray_icon_) tray_icon_->ShowPopup(summary, message, timeout_msec_); break; #endif - case Disabled: if (!force_show_next_) break; force_show_next_ = false; @@ -393,6 +402,8 @@ QString OSDBase::ReplaceMessage(const MessageType type, const QString &message, } } break; +#elif defined(Q_OS_WIN32) + // fallthrough #else // Other OSes doesn't support native notifications. qLog(Debug) << "Native notifications are not supported on this OS."; diff --git a/src/settings/notificationssettingspage.cpp b/src/settings/notificationssettingspage.cpp index b84ef94d..8f2f841d 100644 --- a/src/settings/notificationssettingspage.cpp +++ b/src/settings/notificationssettingspage.cpp @@ -111,10 +111,18 @@ NotificationsSettingsPage::NotificationsSettingsPage(SettingsDialog *dialog, QWi QObject::connect(ui_->notifications_exp_chooser2, &QToolButton::triggered, this, &NotificationsSettingsPage::InsertVariableSecondLine); QObject::connect(ui_->notifications_disable_duration, &QCheckBox::toggled, ui_->notifications_duration, &NotificationsSettingsPage::setDisabled); +#ifdef Q_OS_WIN32 + if (!dialog->osd()->SupportsNativeNotifications() && !dialog->osd()->SupportsTrayPopups()) { + ui_->notifications_native->setEnabled(false); + } +#else if (!dialog->osd()->SupportsNativeNotifications()) { ui_->notifications_native->setEnabled(false); } - if (!dialog->osd()->SupportsTrayPopups()) ui_->notifications_tray->setEnabled(false); +#endif + if (!dialog->osd()->SupportsTrayPopups()) { + ui_->notifications_tray->setEnabled(false); + } QObject::connect(ui_->notifications_pretty, &QRadioButton::toggled, this, &NotificationsSettingsPage::UpdatePopupVisible); @@ -150,7 +158,11 @@ void NotificationsSettingsPage::Load() { OSDBase::Behaviour osd_behaviour = OSDBase::Behaviour(s.value("Behaviour", OSDBase::Native).toInt()); switch (osd_behaviour) { case OSDBase::Native: +#ifdef Q_OS_WIN32 + if (dialog()->osd()->SupportsNativeNotifications() || dialog()->osd()->SupportsTrayPopups()) { +#else if (dialog()->osd()->SupportsNativeNotifications()) { +#endif ui_->notifications_native->setChecked(true); break; }