From 15278d895db83858d62b7c1805900ac013b1b006 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/mainwindow.cpp | 27 +++++++++++++++++++ Telegram/SourceFiles/mainwindow.h | 1 + .../window/notifications_manager.cpp | 2 ++ 4 files changed, 32 insertions(+) diff --git a/Telegram/Resources/langs/rewrites/en.json b/Telegram/Resources/langs/rewrites/en.json index 7057087ac..c808cde32 100644 --- a/Telegram/Resources/langs/rewrites/en.json +++ b/Telegram/Resources/langs/rewrites/en.json @@ -83,6 +83,8 @@ "ktg_settings_external_video_player": "External video player", "ktg_settings_external_video_player_about": "When this option is enabled, autoplay is force-disabled and system video player is used to play videos.", "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/mainwindow.cpp b/Telegram/SourceFiles/mainwindow.cpp index cce2ab5bb..a7eba8dca 100644 --- a/Telegram/SourceFiles/mainwindow.cpp +++ b/Telegram/SourceFiles/mainwindow.cpp @@ -8,6 +8,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "mainwindow.h" #include "kotato/kotato_lang.h" +#include "kotato/kotato_settings.h" #include "data/data_document.h" #include "data/data_session.h" #include "data/data_document_media.h" @@ -147,6 +148,9 @@ void MainWindow::createTrayIconMenu() { const auto notificationAction = trayIconMenu->addAction(QString(), [=] { toggleDisplayNotifyFromTray(); }); + const auto soundAction = trayIconMenu->addAction(QString(), [=] { + toggleSoundNotifyFromTray(); + }); trayIconMenu->addAction(ktr("ktg_quit_from_tray"), [=] { quitFromTray(); }); @@ -166,6 +170,11 @@ void MainWindow::createTrayIconMenu() { ? tr::lng_disable_notifications_from_tray(tr::now) : tr::lng_enable_notifications_from_tray(tr::now); notificationAction->setText(notificationActionText); + + auto soundActionText = Core::App().settings().soundNotify() + ? ktr("ktg_settings_disable_sound_from_tray") + : ktr("ktg_settings_enable_sound_from_tray"); + soundAction->setText(soundActionText); }, lifetime()); _updateTrayMenuTextActions.fire({}); @@ -806,6 +815,24 @@ void MainWindow::toggleDisplayNotifyFromTray() { } } +void MainWindow::toggleSoundNotifyFromTray() { + if (controller().locked()) { + if (!isActive()) showFromTray(); + Ui::show(Box(tr::lng_passcode_need_unblock(tr::now))); + return; + } + if (!sessionController()) { + return; + } + + auto &settings = Core::App().settings(); + settings.setSoundNotify(!settings.soundNotify()); + account().session().saveSettings(); + using Change = Window::Notifications::ChangeType; + auto ¬ifications = Core::App().notifications(); + notifications.notifySettingsChanged(Change::SoundEnabled); +} + void MainWindow::closeEvent(QCloseEvent *e) { if (Core::Sandbox::Instance().isSavingSession() || Core::Quitting()) { e->accept(); diff --git a/Telegram/SourceFiles/mainwindow.h b/Telegram/SourceFiles/mainwindow.h index 5bcd1ee82..3bea6f88c 100644 --- a/Telegram/SourceFiles/mainwindow.h +++ b/Telegram/SourceFiles/mainwindow.h @@ -140,6 +140,7 @@ private: void themeUpdated(const Window::Theme::BackgroundUpdate &data); void toggleDisplayNotifyFromTray(); + void toggleSoundNotifyFromTray(); QPixmap grabInner(); diff --git a/Telegram/SourceFiles/window/notifications_manager.cpp b/Telegram/SourceFiles/window/notifications_manager.cpp index b0002a6b3..a67624efa 100644 --- a/Telegram/SourceFiles/window/notifications_manager.cpp +++ b/Telegram/SourceFiles/window/notifications_manager.cpp @@ -94,6 +94,8 @@ System::System() ) | rpl::start_with_next([=](ChangeType type) { if (type == ChangeType::DesktopEnabled) { clearAll(); + } else if (type == ChangeType::SoundEnabled) { + App::wnd()->updateTrayMenu(); } else if (type == ChangeType::ViewParams) { updateAll(); } else if (type == ChangeType::IncludeMuted