mirror of
https://github.com/telegramdesktop/tdesktop
synced 2025-08-31 06:26:18 +00:00
Change notification volume visibility on support change
Cross platform VolumeSupported wrapper
This commit is contained in:
@@ -12,7 +12,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||||||
#include "data/notify/data_peer_notify_settings.h"
|
#include "data/notify/data_peer_notify_settings.h"
|
||||||
#include "main/main_session.h"
|
#include "main/main_session.h"
|
||||||
#include "main/main_session_settings.h"
|
#include "main/main_session_settings.h"
|
||||||
#include "platform/platform_notifications_manager.h"
|
#include "core/application.h"
|
||||||
|
#include "window/notifications_manager.h"
|
||||||
#include "settings/settings_common.h"
|
#include "settings/settings_common.h"
|
||||||
#include "ui/vertical_list.h"
|
#include "ui/vertical_list.h"
|
||||||
#include "ui/widgets/continuous_sliders.h"
|
#include "ui/widgets/continuous_sliders.h"
|
||||||
@@ -67,16 +68,20 @@ void AddRingtonesVolumeSlider(
|
|||||||
rpl::producer<bool> toggleOn,
|
rpl::producer<bool> toggleOn,
|
||||||
rpl::producer<QString> subtitle,
|
rpl::producer<QString> subtitle,
|
||||||
Data::VolumeController volumeController) {
|
Data::VolumeController volumeController) {
|
||||||
if (!Platform::Notifications::VolumeSupported()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
Expects(volumeController.volume && volumeController.saveVolume);
|
Expects(volumeController.volume && volumeController.saveVolume);
|
||||||
|
|
||||||
const auto volumeWrap = container->add(
|
const auto volumeWrap = container->add(
|
||||||
object_ptr<Ui::SlideWrap<Ui::VerticalLayout>>(
|
object_ptr<Ui::SlideWrap<Ui::VerticalLayout>>(
|
||||||
container,
|
container,
|
||||||
object_ptr<Ui::VerticalLayout>(container)));
|
object_ptr<Ui::VerticalLayout>(container)));
|
||||||
volumeWrap->toggleOn(std::move(toggleOn), anim::type::normal);
|
volumeWrap->toggleOn(
|
||||||
|
rpl::combine(
|
||||||
|
Core::App().notifications().volumeSupportedValue(),
|
||||||
|
std::move(toggleOn)
|
||||||
|
) | rpl::map(
|
||||||
|
rpl::mappers::_1 && rpl::mappers::_2
|
||||||
|
) | rpl::distinct_until_changed(),
|
||||||
|
anim::type::normal);
|
||||||
volumeWrap->finishAnimating();
|
volumeWrap->finishAnimating();
|
||||||
|
|
||||||
Ui::AddSubsectionTitle(volumeWrap->entity(), std::move(subtitle));
|
Ui::AddSubsectionTitle(volumeWrap->entity(), std::move(subtitle));
|
||||||
|
@@ -14,7 +14,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||||||
#include "platform/platform_specific.h"
|
#include "platform/platform_specific.h"
|
||||||
#include "core/application.h"
|
#include "core/application.h"
|
||||||
#include "core/sandbox.h"
|
#include "core/sandbox.h"
|
||||||
#include "core/core_settings.h"
|
|
||||||
#include "data/data_forum_topic.h"
|
#include "data/data_forum_topic.h"
|
||||||
#include "data/data_saved_sublist.h"
|
#include "data/data_saved_sublist.h"
|
||||||
#include "data/data_peer.h"
|
#include "data/data_peer.h"
|
||||||
@@ -234,7 +233,7 @@ bool ByDefault() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool VolumeSupported() {
|
bool VolumeSupported() {
|
||||||
return false;
|
return UseGNotification() || !HasCapability("sound");
|
||||||
}
|
}
|
||||||
|
|
||||||
void Create(Window::Notifications::System *system) {
|
void Create(Window::Notifications::System *system) {
|
||||||
@@ -242,10 +241,12 @@ void Create(Window::Notifications::System *system) {
|
|||||||
|
|
||||||
const auto managerSetter = [=](
|
const auto managerSetter = [=](
|
||||||
XdgNotifications::NotificationsProxy proxy) {
|
XdgNotifications::NotificationsProxy proxy) {
|
||||||
system->setManager([=] {
|
Core::Sandbox::Instance().customEnterFromEventLoop([&] {
|
||||||
auto manager = std::make_unique<Manager>(system);
|
system->setManager([=] {
|
||||||
manager->_private->init(proxy);
|
auto manager = std::make_unique<Manager>(system);
|
||||||
return manager;
|
manager->_private->init(proxy);
|
||||||
|
return manager;
|
||||||
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -931,11 +932,7 @@ bool Manager::doSkipToast() const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Manager::doMaybePlaySound(Fn<void()> playSound) {
|
void Manager::doMaybePlaySound(Fn<void()> playSound) {
|
||||||
if (UseGNotification()
|
_private->invokeIfNotInhibited(std::move(playSound));
|
||||||
|| !HasCapability("sound")
|
|
||||||
|| !Core::App().settings().desktopNotify()) {
|
|
||||||
_private->invokeIfNotInhibited(std::move(playSound));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Manager::doMaybeFlashBounce(Fn<void()> flashBounce) {
|
void Manager::doMaybeFlashBounce(Fn<void()> flashBounce) {
|
||||||
|
@@ -579,10 +579,7 @@ bool Manager::doSkipToast() const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Manager::doMaybePlaySound(Fn<void()> playSound) {
|
void Manager::doMaybePlaySound(Fn<void()> playSound) {
|
||||||
// Play through native notification system if toasts are enabled.
|
playSound();
|
||||||
if (!Core::App().settings().desktopNotify()) {
|
|
||||||
playSound();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Manager::doMaybeFlashBounce(Fn<void()> flashBounce) {
|
void Manager::doMaybeFlashBounce(Fn<void()> flashBounce) {
|
||||||
|
@@ -1021,7 +1021,7 @@ void SetupNotificationsContent(
|
|||||||
|
|
||||||
Ui::AddRingtonesVolumeSlider(
|
Ui::AddRingtonesVolumeSlider(
|
||||||
container,
|
container,
|
||||||
soundAllowed->events_starting_with(allowed()),
|
rpl::single(true),
|
||||||
tr::lng_settings_master_volume_notifications(),
|
tr::lng_settings_master_volume_notifications(),
|
||||||
Data::VolumeController{
|
Data::VolumeController{
|
||||||
.volume = []() -> ushort {
|
.volume = []() -> ushort {
|
||||||
|
@@ -189,8 +189,12 @@ void System::createManager() {
|
|||||||
|
|
||||||
void System::setManager(Fn<std::unique_ptr<Manager>()> create) {
|
void System::setManager(Fn<std::unique_ptr<Manager>()> create) {
|
||||||
Expects(_manager != nullptr);
|
Expects(_manager != nullptr);
|
||||||
|
const auto oldManager = _manager.get();
|
||||||
const auto guard = gsl::finally([&] {
|
const auto guard = gsl::finally([&] {
|
||||||
Ensures(_manager != nullptr);
|
Ensures(_manager != nullptr);
|
||||||
|
if (oldManager != _manager.get()) {
|
||||||
|
_managerChanged.fire({});
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
if ((Core::App().settings().nativeNotifications()
|
if ((Core::App().settings().nativeNotifications()
|
||||||
@@ -215,6 +219,15 @@ void System::setManager(Fn<std::unique_ptr<Manager>()> create) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Manager &System::manager() const {
|
||||||
|
Expects(_manager != nullptr);
|
||||||
|
return *_manager;
|
||||||
|
}
|
||||||
|
|
||||||
|
rpl::producer<> System::managerChanged() const {
|
||||||
|
return _managerChanged.events();
|
||||||
|
}
|
||||||
|
|
||||||
Main::Session *System::findSession(uint64 sessionId) const {
|
Main::Session *System::findSession(uint64 sessionId) const {
|
||||||
for (const auto &[index, account] : Core::App().domain().accounts()) {
|
for (const auto &[index, account] : Core::App().domain().accounts()) {
|
||||||
if (const auto session = account->maybeSession()) {
|
if (const auto session = account->maybeSession()) {
|
||||||
@@ -977,6 +990,24 @@ void System::notifySettingsChanged(ChangeType type) {
|
|||||||
return _settingsChanged.fire(std::move(type));
|
return _settingsChanged.fire(std::move(type));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool System::volumeSupported() const {
|
||||||
|
// Play through native notification system if toasts are enabled.
|
||||||
|
return Core::App().settings().soundNotify()
|
||||||
|
&& (!Core::App().settings().desktopNotify()
|
||||||
|
|| _manager->type() != ManagerType::Native
|
||||||
|
|| Platform::Notifications::VolumeSupported());
|
||||||
|
}
|
||||||
|
|
||||||
|
rpl::producer<bool> System::volumeSupportedValue() const {
|
||||||
|
return rpl::single(
|
||||||
|
rpl::empty_value()
|
||||||
|
) | rpl::then(
|
||||||
|
rpl::merge(settingsChanged() | rpl::to_empty, managerChanged())
|
||||||
|
) | rpl::map([=] {
|
||||||
|
return volumeSupported();
|
||||||
|
}) | rpl::distinct_until_changed();
|
||||||
|
}
|
||||||
|
|
||||||
void System::playSound(
|
void System::playSound(
|
||||||
not_null<Main::Session*> session,
|
not_null<Main::Session*> session,
|
||||||
DocumentId id,
|
DocumentId id,
|
||||||
@@ -1343,6 +1374,12 @@ void Manager::notificationReplied(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Manager::maybePlaySound(Fn<void()> playSound) {
|
||||||
|
if (_system->volumeSupported()) {
|
||||||
|
doMaybePlaySound(std::move(playSound));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void NativeManager::doShowNotification(NotificationFields &&fields) {
|
void NativeManager::doShowNotification(NotificationFields &&fields) {
|
||||||
const auto options = getNotificationOptions(
|
const auto options = getNotificationOptions(
|
||||||
fields.item,
|
fields.item,
|
||||||
|
@@ -106,6 +106,8 @@ public:
|
|||||||
|
|
||||||
void createManager();
|
void createManager();
|
||||||
void setManager(Fn<std::unique_ptr<Manager>()> create);
|
void setManager(Fn<std::unique_ptr<Manager>()> create);
|
||||||
|
[[nodiscard]] Manager &manager() const;
|
||||||
|
[[nodiscard]] rpl::producer<> managerChanged() const;
|
||||||
|
|
||||||
void checkDelayed();
|
void checkDelayed();
|
||||||
void schedule(Data::ItemNotification notification);
|
void schedule(Data::ItemNotification notification);
|
||||||
@@ -124,6 +126,9 @@ public:
|
|||||||
[[nodiscard]] rpl::producer<ChangeType> settingsChanged() const;
|
[[nodiscard]] rpl::producer<ChangeType> settingsChanged() const;
|
||||||
void notifySettingsChanged(ChangeType type);
|
void notifySettingsChanged(ChangeType type);
|
||||||
|
|
||||||
|
[[nodiscard]] bool volumeSupported() const;
|
||||||
|
[[nodiscard]] rpl::producer<bool> volumeSupportedValue() const;
|
||||||
|
|
||||||
void playSound(
|
void playSound(
|
||||||
not_null<Main::Session*> session,
|
not_null<Main::Session*> session,
|
||||||
DocumentId id,
|
DocumentId id,
|
||||||
@@ -216,6 +221,7 @@ private:
|
|||||||
crl::time> _sentReactionNotifications;
|
crl::time> _sentReactionNotifications;
|
||||||
|
|
||||||
std::unique_ptr<Manager> _manager;
|
std::unique_ptr<Manager> _manager;
|
||||||
|
rpl::event_stream<> _managerChanged;
|
||||||
|
|
||||||
rpl::event_stream<ChangeType> _settingsChanged;
|
rpl::event_stream<ChangeType> _settingsChanged;
|
||||||
|
|
||||||
@@ -334,9 +340,7 @@ public:
|
|||||||
[[nodiscard]] bool skipToast() const {
|
[[nodiscard]] bool skipToast() const {
|
||||||
return doSkipToast();
|
return doSkipToast();
|
||||||
}
|
}
|
||||||
void maybePlaySound(Fn<void()> playSound) {
|
void maybePlaySound(Fn<void()> playSound);
|
||||||
doMaybePlaySound(std::move(playSound));
|
|
||||||
}
|
|
||||||
void maybeFlashBounce(Fn<void()> flashBounce) {
|
void maybeFlashBounce(Fn<void()> flashBounce) {
|
||||||
doMaybeFlashBounce(std::move(flashBounce));
|
doMaybeFlashBounce(std::move(flashBounce));
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user