Allow users to select native notifications on Windows

Setting will fallback to system tray notifications which are
native notifications on Windows.
This commit is contained in:
Jonas Kvinge 2021-10-24 23:09:20 +02:00
parent 57f5ccff81
commit d29a1de980
2 changed files with 27 additions and 4 deletions

View File

@ -89,7 +89,11 @@ void OSDBase::ReloadSettings() {
custom_text2_ = s.value("CustomText2").toString(); custom_text2_ = s.value("CustomText2").toString();
s.endGroup(); s.endGroup();
#ifdef Q_OS_WIN32
if (!SupportsNativeNotifications() && !SupportsTrayPopups() && behaviour_ == Native) {
#else
if (!SupportsNativeNotifications() && behaviour_ == Native) { if (!SupportsNativeNotifications() && behaviour_ == Native) {
#endif
behaviour_ = Pretty; behaviour_ = Pretty;
} }
@ -302,6 +306,10 @@ void OSDBase::ShowMessage(const QString &summary, const QString &message, const
else { else {
switch (behaviour_) { switch (behaviour_) {
case Native: case Native:
#ifdef Q_OS_WIN32
Q_UNUSED(icon)
// fallthrough
#else
if (image.isNull()) { if (image.isNull()) {
ShowMessageNative(summary, message, icon, QImage()); ShowMessageNative(summary, message, icon, QImage());
} }
@ -309,13 +317,14 @@ void OSDBase::ShowMessage(const QString &summary, const QString &message, const
ShowMessageNative(summary, message, QString(), image); ShowMessageNative(summary, message, QString(), image);
} }
break; break;
#endif
#ifndef Q_OS_MACOS
case TrayPopup: case TrayPopup:
#ifdef Q_OS_MACOS
// fallthrough
#else
if (tray_icon_) tray_icon_->ShowPopup(summary, message, timeout_msec_); if (tray_icon_) tray_icon_->ShowPopup(summary, message, timeout_msec_);
break; break;
#endif #endif
case Disabled: case Disabled:
if (!force_show_next_) break; if (!force_show_next_) break;
force_show_next_ = false; force_show_next_ = false;
@ -393,6 +402,8 @@ QString OSDBase::ReplaceMessage(const MessageType type, const QString &message,
} }
} }
break; break;
#elif defined(Q_OS_WIN32)
// fallthrough
#else #else
// Other OSes doesn't support native notifications. // Other OSes doesn't support native notifications.
qLog(Debug) << "Native notifications are not supported on this OS."; qLog(Debug) << "Native notifications are not supported on this OS.";

View File

@ -111,10 +111,18 @@ NotificationsSettingsPage::NotificationsSettingsPage(SettingsDialog *dialog, QWi
QObject::connect(ui_->notifications_exp_chooser2, &QToolButton::triggered, this, &NotificationsSettingsPage::InsertVariableSecondLine); QObject::connect(ui_->notifications_exp_chooser2, &QToolButton::triggered, this, &NotificationsSettingsPage::InsertVariableSecondLine);
QObject::connect(ui_->notifications_disable_duration, &QCheckBox::toggled, ui_->notifications_duration, &NotificationsSettingsPage::setDisabled); 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()) { if (!dialog->osd()->SupportsNativeNotifications()) {
ui_->notifications_native->setEnabled(false); 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); 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()); OSDBase::Behaviour osd_behaviour = OSDBase::Behaviour(s.value("Behaviour", OSDBase::Native).toInt());
switch (osd_behaviour) { switch (osd_behaviour) {
case OSDBase::Native: case OSDBase::Native:
#ifdef Q_OS_WIN32
if (dialog()->osd()->SupportsNativeNotifications() || dialog()->osd()->SupportsTrayPopups()) {
#else
if (dialog()->osd()->SupportsNativeNotifications()) { if (dialog()->osd()->SupportsNativeNotifications()) {
#endif
ui_->notifications_native->setChecked(true); ui_->notifications_native->setChecked(true);
break; break;
} }