diff --git a/src/osd/osdbase.cpp b/src/osd/osdbase.cpp index f251d3267..932381796 100644 --- a/src/osd/osdbase.cpp +++ b/src/osd/osdbase.cpp @@ -23,6 +23,7 @@ #include #include +#include #include #include #include @@ -80,22 +81,48 @@ void OSDBase::ReloadSettings() { custom_text2_ = s.value("CustomText2").toString(); s.endGroup(); -#ifdef Q_OS_WIN32 - if (!SupportsNativeNotifications() && !SupportsTrayPopups() && type_ == OSDSettings::Type::Native) { -#else - if (!SupportsNativeNotifications() && type_ == OSDSettings::Type::Native) { -#endif - type_ = OSDSettings::Type::Pretty; - } - - if (!SupportsTrayPopups() && type_ == OSDSettings::Type::TrayPopup) { - type_ = OSDSettings::Type::Disabled; + if (!IsTypeSupported(type_)) { + type_ = GetSupportedType(); } ReloadPrettyOSDSettings(); } +OSDSettings::Type OSDBase::GetSupportedType() const { + + if (SupportsNativeNotifications()) { + return OSDSettings::Type::Native; + } + if (SupportsOSDPretty()) { + return OSDSettings::Type::Pretty; + } + if (SupportsTrayPopups()) { + return OSDSettings::Type::TrayPopup; + } + + return OSDSettings::Type::Disabled; + +} + +bool OSDBase::IsTypeSupported(const OSDSettings::Type type) const { + + switch (type) { + case OSDSettings::Type::Native: + return SupportsNativeNotifications(); + case OSDSettings::Type::TrayPopup: + return SupportsTrayPopups(); + case OSDSettings::Type::Pretty: + return SupportsOSDPretty(); + break; + case OSDSettings::Type::Disabled: + return true; + } + + return false; + +} + // Reload just Pretty OSD settings, not everything void OSDBase::ReloadPrettyOSDSettings() { @@ -432,14 +459,24 @@ void OSDBase::SetPrettyOSDToggleMode(const bool toggle) { pretty_popup_->set_toggle_mode(toggle); } -bool OSDBase::SupportsNativeNotifications() { +bool OSDBase::SupportsNativeNotifications() const { + +#ifdef Q_OS_WIN32 + return SupportsTrayPopups(); +#endif + return false; + } -bool OSDBase::SupportsTrayPopups() { +bool OSDBase::SupportsTrayPopups() const { return tray_icon_->IsSystemTrayAvailable(); } +bool OSDBase::SupportsOSDPretty() { + return QGuiApplication::platformName() != "wayland"_L1; +} + void OSDBase::ShowMessageNative(const QString &summary, const QString &message, const QString &icon, const QImage &image) { Q_UNUSED(summary) diff --git a/src/osd/osdbase.h b/src/osd/osdbase.h index ecb9ec6bc..0fa9a97cf 100644 --- a/src/osd/osdbase.h +++ b/src/osd/osdbase.h @@ -50,8 +50,11 @@ class OSDBase : public QObject { void ReloadPrettyOSDSettings(); void SetPrettyOSDToggleMode(bool toggle); - virtual bool SupportsNativeNotifications(); - virtual bool SupportsTrayPopups(); + OSDSettings::Type GetSupportedType() const; + bool IsTypeSupported(const OSDSettings::Type type) const; + virtual bool SupportsNativeNotifications() const; + virtual bool SupportsTrayPopups() const; + static bool SupportsOSDPretty(); public Q_SLOTS: void ReloadSettings(); diff --git a/src/osd/osddbus.cpp b/src/osd/osddbus.cpp index 9e32afafa..50d617a18 100644 --- a/src/osd/osddbus.cpp +++ b/src/osd/osddbus.cpp @@ -136,9 +136,9 @@ void OSDDBus::Init() { } -bool OSDDBus::SupportsNativeNotifications() { return true; } +bool OSDDBus::SupportsNativeNotifications() const { return true; } -bool OSDDBus::SupportsTrayPopups() { return true; } +bool OSDDBus::SupportsTrayPopups() const { return true; } void OSDDBus::ShowMessageNative(const QString &summary, const QString &message, const QString &icon, const QImage &image) { diff --git a/src/osd/osddbus.h b/src/osd/osddbus.h index ee2793af7..865706343 100644 --- a/src/osd/osddbus.h +++ b/src/osd/osddbus.h @@ -50,8 +50,8 @@ class OSDDBus : public OSDBase { static const char *kSettingsGroup; - bool SupportsNativeNotifications() override; - bool SupportsTrayPopups() override; + bool SupportsNativeNotifications() const override; + bool SupportsTrayPopups() const override; private: void Init(); diff --git a/src/osd/osdmac.h b/src/osd/osdmac.h index 8eadc1f26..8b691ea83 100644 --- a/src/osd/osdmac.h +++ b/src/osd/osdmac.h @@ -40,8 +40,8 @@ class OSDMac : public OSDBase { explicit OSDMac(const SharedPtr tray_icon, QObject *parent = nullptr); ~OSDMac() override; - bool SupportsNativeNotifications() override; - bool SupportsTrayPopups() override; + bool SupportsNativeNotifications() const override; + bool SupportsTrayPopups() const override; private: void ShowMessageNative(const QString &summary, const QString &message, const QString &icon, const QImage &image) override; diff --git a/src/osd/osdmac.mm b/src/osd/osdmac.mm index 69b84f7c2..12465c568 100644 --- a/src/osd/osdmac.mm +++ b/src/osd/osdmac.mm @@ -57,11 +57,11 @@ OSDMac::OSDMac(const SharedPtr tray_icon, QObject *parent) : OSD OSDMac::~OSDMac() = default; -bool OSDMac::SupportsNativeNotifications() { +bool OSDMac::SupportsNativeNotifications() const { return NotificationCenterSupported(); } -bool OSDMac::SupportsTrayPopups() { return false; } +bool OSDMac::SupportsTrayPopups() const { return false; } void OSDMac::ShowMessageNative(const QString &summary, const QString &message, const QString &icon, const QImage &image) { diff --git a/src/settings/notificationssettingspage.cpp b/src/settings/notificationssettingspage.cpp index 039b39a93..f8ec9d02b 100644 --- a/src/settings/notificationssettingspage.cpp +++ b/src/settings/notificationssettingspage.cpp @@ -115,18 +115,9 @@ NotificationsSettingsPage::NotificationsSettingsPage(SettingsDialog *dialog, OSD 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 (!osd_->SupportsNativeNotifications() && !osd_->SupportsTrayPopups()) { - ui_->notifications_native->setEnabled(false); - } -#else - if (!osd_->SupportsNativeNotifications()) { - ui_->notifications_native->setEnabled(false); - } -#endif - if (!osd_->SupportsTrayPopups()) { - ui_->notifications_tray->setEnabled(false); - } + ui_->notifications_native->setEnabled(osd_->SupportsNativeNotifications()); + ui_->notifications_tray->setEnabled(osd_->SupportsTrayPopups()); + ui_->notifications_pretty->setEnabled(osd_->SupportsOSDPretty()); QObject::connect(ui_->notifications_pretty, &QRadioButton::toggled, this, &NotificationsSettingsPage::UpdatePopupVisible); @@ -161,30 +152,20 @@ void NotificationsSettingsPage::Load() { Settings s; s.beginGroup(OSDSettings::kSettingsGroup); - const OSDSettings::Type osd_type = static_cast(s.value(OSDSettings::kType, static_cast(OSDSettings::Type::Native)).toInt()); + OSDSettings::Type osd_type = static_cast(s.value(OSDSettings::kType, static_cast(OSDSettings::Type::Native)).toInt()); + if (!osd_->IsTypeSupported(osd_type)) { + osd_type = osd_->GetSupportedType(); + } switch (osd_type) { case OSDSettings::Type::Native: -#ifdef Q_OS_WIN32 - if (osd_->SupportsNativeNotifications() || osd_->SupportsTrayPopups()) { -#else - if (osd_->SupportsNativeNotifications()) { -#endif - ui_->notifications_native->setChecked(true); - break; - } - // Fallthrough - + ui_->notifications_native->setChecked(true); + break; case OSDSettings::Type::Pretty: ui_->notifications_pretty->setChecked(true); break; - case OSDSettings::Type::TrayPopup: - if (osd_->SupportsTrayPopups()) { - ui_->notifications_tray->setChecked(true); - break; - } - // Fallthrough - + ui_->notifications_tray->setChecked(true); + break; case OSDSettings::Type::Disabled: default: ui_->notifications_none->setChecked(true); @@ -238,9 +219,9 @@ void NotificationsSettingsPage::Save() { OSDSettings::Type osd_type = OSDSettings::Type::Disabled; if (ui_->notifications_none->isChecked()) osd_type = OSDSettings::Type::Disabled; - else if (ui_->notifications_native->isChecked()) osd_type = OSDSettings::Type::Native; - else if (ui_->notifications_tray->isChecked()) osd_type = OSDSettings::Type::TrayPopup; - else if (ui_->notifications_pretty->isChecked()) osd_type = OSDSettings::Type::Pretty; + else if (osd_->SupportsNativeNotifications() && ui_->notifications_native->isChecked()) osd_type = OSDSettings::Type::Native; + else if (osd_->SupportsTrayPopups() && ui_->notifications_tray->isChecked()) osd_type = OSDSettings::Type::TrayPopup; + else if (osd_->SupportsOSDPretty() && ui_->notifications_pretty->isChecked()) osd_type = OSDSettings::Type::Pretty; s.beginGroup(OSDSettings::kSettingsGroup); s.setValue(OSDSettings::kType, static_cast(osd_type));