From 8a4092954841b1ebb5d3098cb3cd85c9c149223b Mon Sep 17 00:00:00 2001 From: RadRussianRus Date: Sat, 10 Sep 2022 20:32:35 +0300 Subject: [PATCH] [Improvement] Allow to disable notification sound from tray --- Telegram/Resources/langs/rewrites/en.json | 2 ++ Telegram/SourceFiles/tray.cpp | 20 ++++++++++++++++++++ Telegram/SourceFiles/tray.h | 1 + 3 files changed, 23 insertions(+) diff --git a/Telegram/Resources/langs/rewrites/en.json b/Telegram/Resources/langs/rewrites/en.json index 15893bb1f..f437b84bf 100644 --- a/Telegram/Resources/langs/rewrites/en.json +++ b/Telegram/Resources/langs/rewrites/en.json @@ -59,6 +59,8 @@ "ktg_settings_ffmpeg_multithread": "Multithread video decoding", "ktg_settings_ffmpeg_multithread_about": "When enabled, CPU and RAM consumption is higher, video decodes faster. When disabled, CPU and RAM consumption is lower, video decodes slower. The more CPU cores you have, the more RAM consumption you have when this option is enabled. You can set exact number of threads in the JSON configuration file.", "ktg_settings_adaptive_bubbles": "Adaptive bubbles", + "ktg_settings_disable_sound_from_tray": "Disable sound", + "ktg_settings_enable_sound_from_tray": "Enable sound", "ktg_settings_recent_stickers_limit": { "zero": "Recent stickers: show {count} stickers", "one": "Recent stickers: show {count} sticker", diff --git a/Telegram/SourceFiles/tray.cpp b/Telegram/SourceFiles/tray.cpp index 778e39325..607e455ba 100644 --- a/Telegram/SourceFiles/tray.cpp +++ b/Telegram/SourceFiles/tray.cpp @@ -94,6 +94,17 @@ void Tray::rebuildMenu() { _tray.addAction( std::move(notificationsText), [=] { toggleSoundNotifications(); }); + + auto soundText = _textUpdates.events( + ) | rpl::map([=] { + return Core::App().settings().soundNotify() + ? ktr("ktg_settings_disable_sound_from_tray") + : ktr("ktg_settings_enable_sound_from_tray"); + }); + + _tray.addAction( + std::move(soundText), + [=] { toggleSound(); }); } _tray.addAction(rktr("ktg_quit_from_tray"), [] { Core::Quit(); }); @@ -139,6 +150,15 @@ rpl::producer<> Tray::hideToTrayRequests() const { } } +void Tray::toggleSound() { + auto &settings = Core::App().settings(); + settings.setSoundNotify(!settings.soundNotify()); + Core::App().saveSettingsDelayed(); + using Change = Window::Notifications::ChangeType; + auto ¬ifications = Core::App().notifications(); + notifications.notifySettingsChanged(Change::SoundEnabled); +} + void Tray::toggleSoundNotifications() { auto soundNotifyChanged = false; auto flashBounceNotifyChanged = false; diff --git a/Telegram/SourceFiles/tray.h b/Telegram/SourceFiles/tray.h index f5d68dcc0..688baa704 100644 --- a/Telegram/SourceFiles/tray.h +++ b/Telegram/SourceFiles/tray.h @@ -27,6 +27,7 @@ public: private: void rebuildMenu(); + void toggleSound(); void toggleSoundNotifications(); Platform::Tray _tray;