mirror of
https://github.com/telegramdesktop/tdesktop
synced 2025-08-22 02:07:24 +00:00
Change notification volume visibility on support change
Cross platform VolumeSupported wrapper
This commit is contained in:
parent
2d23a5860a
commit
efda892205
@ -12,7 +12,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
#include "data/notify/data_peer_notify_settings.h"
|
||||
#include "main/main_session.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 "ui/vertical_list.h"
|
||||
#include "ui/widgets/continuous_sliders.h"
|
||||
@ -67,16 +68,20 @@ void AddRingtonesVolumeSlider(
|
||||
rpl::producer<bool> toggleOn,
|
||||
rpl::producer<QString> subtitle,
|
||||
Data::VolumeController volumeController) {
|
||||
if (!Platform::Notifications::VolumeSupported()) {
|
||||
return;
|
||||
}
|
||||
Expects(volumeController.volume && volumeController.saveVolume);
|
||||
|
||||
const auto volumeWrap = container->add(
|
||||
object_ptr<Ui::SlideWrap<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();
|
||||
|
||||
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 "core/application.h"
|
||||
#include "core/sandbox.h"
|
||||
#include "core/core_settings.h"
|
||||
#include "data/data_forum_topic.h"
|
||||
#include "data/data_saved_sublist.h"
|
||||
#include "data/data_peer.h"
|
||||
@ -234,7 +233,7 @@ bool ByDefault() {
|
||||
}
|
||||
|
||||
bool VolumeSupported() {
|
||||
return false;
|
||||
return UseGNotification() || !HasCapability("sound");
|
||||
}
|
||||
|
||||
void Create(Window::Notifications::System *system) {
|
||||
@ -242,10 +241,12 @@ void Create(Window::Notifications::System *system) {
|
||||
|
||||
const auto managerSetter = [=](
|
||||
XdgNotifications::NotificationsProxy proxy) {
|
||||
system->setManager([=] {
|
||||
auto manager = std::make_unique<Manager>(system);
|
||||
manager->_private->init(proxy);
|
||||
return manager;
|
||||
Core::Sandbox::Instance().customEnterFromEventLoop([&] {
|
||||
system->setManager([=] {
|
||||
auto manager = std::make_unique<Manager>(system);
|
||||
manager->_private->init(proxy);
|
||||
return manager;
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
@ -931,11 +932,7 @@ bool Manager::doSkipToast() const {
|
||||
}
|
||||
|
||||
void Manager::doMaybePlaySound(Fn<void()> playSound) {
|
||||
if (UseGNotification()
|
||||
|| !HasCapability("sound")
|
||||
|| !Core::App().settings().desktopNotify()) {
|
||||
_private->invokeIfNotInhibited(std::move(playSound));
|
||||
}
|
||||
_private->invokeIfNotInhibited(std::move(playSound));
|
||||
}
|
||||
|
||||
void Manager::doMaybeFlashBounce(Fn<void()> flashBounce) {
|
||||
|
@ -579,10 +579,7 @@ bool Manager::doSkipToast() const {
|
||||
}
|
||||
|
||||
void Manager::doMaybePlaySound(Fn<void()> playSound) {
|
||||
// Play through native notification system if toasts are enabled.
|
||||
if (!Core::App().settings().desktopNotify()) {
|
||||
playSound();
|
||||
}
|
||||
playSound();
|
||||
}
|
||||
|
||||
void Manager::doMaybeFlashBounce(Fn<void()> flashBounce) {
|
||||
|
@ -1021,7 +1021,7 @@ void SetupNotificationsContent(
|
||||
|
||||
Ui::AddRingtonesVolumeSlider(
|
||||
container,
|
||||
soundAllowed->events_starting_with(allowed()),
|
||||
rpl::single(true),
|
||||
tr::lng_settings_master_volume_notifications(),
|
||||
Data::VolumeController{
|
||||
.volume = []() -> ushort {
|
||||
|
@ -189,8 +189,12 @@ void System::createManager() {
|
||||
|
||||
void System::setManager(Fn<std::unique_ptr<Manager>()> create) {
|
||||
Expects(_manager != nullptr);
|
||||
const auto oldManager = _manager.get();
|
||||
const auto guard = gsl::finally([&] {
|
||||
Ensures(_manager != nullptr);
|
||||
if (oldManager != _manager.get()) {
|
||||
_managerChanged.fire({});
|
||||
}
|
||||
});
|
||||
|
||||
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 {
|
||||
for (const auto &[index, account] : Core::App().domain().accounts()) {
|
||||
if (const auto session = account->maybeSession()) {
|
||||
@ -977,6 +990,24 @@ void System::notifySettingsChanged(ChangeType 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(
|
||||
not_null<Main::Session*> session,
|
||||
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) {
|
||||
const auto options = getNotificationOptions(
|
||||
fields.item,
|
||||
|
@ -106,6 +106,8 @@ public:
|
||||
|
||||
void createManager();
|
||||
void setManager(Fn<std::unique_ptr<Manager>()> create);
|
||||
[[nodiscard]] Manager &manager() const;
|
||||
[[nodiscard]] rpl::producer<> managerChanged() const;
|
||||
|
||||
void checkDelayed();
|
||||
void schedule(Data::ItemNotification notification);
|
||||
@ -124,6 +126,9 @@ public:
|
||||
[[nodiscard]] rpl::producer<ChangeType> settingsChanged() const;
|
||||
void notifySettingsChanged(ChangeType type);
|
||||
|
||||
[[nodiscard]] bool volumeSupported() const;
|
||||
[[nodiscard]] rpl::producer<bool> volumeSupportedValue() const;
|
||||
|
||||
void playSound(
|
||||
not_null<Main::Session*> session,
|
||||
DocumentId id,
|
||||
@ -216,6 +221,7 @@ private:
|
||||
crl::time> _sentReactionNotifications;
|
||||
|
||||
std::unique_ptr<Manager> _manager;
|
||||
rpl::event_stream<> _managerChanged;
|
||||
|
||||
rpl::event_stream<ChangeType> _settingsChanged;
|
||||
|
||||
@ -334,9 +340,7 @@ public:
|
||||
[[nodiscard]] bool skipToast() const {
|
||||
return doSkipToast();
|
||||
}
|
||||
void maybePlaySound(Fn<void()> playSound) {
|
||||
doMaybePlaySound(std::move(playSound));
|
||||
}
|
||||
void maybePlaySound(Fn<void()> playSound);
|
||||
void maybeFlashBounce(Fn<void()> flashBounce) {
|
||||
doMaybeFlashBounce(std::move(flashBounce));
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user