[Improvement] Allow to disable notification sound from tray

This commit is contained in:
Eric Kotato 2022-09-10 20:32:35 +03:00
parent 9c03c310d8
commit 15278d895d
4 changed files with 32 additions and 0 deletions

View file

@ -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",

View file

@ -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<Ui::InformBox>(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 &notifications = Core::App().notifications();
notifications.notifySettingsChanged(Change::SoundEnabled);
}
void MainWindow::closeEvent(QCloseEvent *e) {
if (Core::Sandbox::Instance().isSavingSession() || Core::Quitting()) {
e->accept();

View file

@ -140,6 +140,7 @@ private:
void themeUpdated(const Window::Theme::BackgroundUpdate &data);
void toggleDisplayNotifyFromTray();
void toggleSoundNotifyFromTray();
QPixmap grabInner();

View file

@ -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