From 90d62514e9e8f806bc4dde3a713a8db4ed99689e Mon Sep 17 00:00:00 2001 From: ZavaruKitsu Date: Sat, 1 Jul 2023 15:48:31 +0300 Subject: [PATCH] fix: tray ghost toggle --- Telegram/SourceFiles/ayu/ayu_settings.cpp | 6 +-- Telegram/SourceFiles/ayu/ayu_settings.h | 6 +-- .../SourceFiles/ayu/settings/settings_ayu.cpp | 2 +- Telegram/SourceFiles/tray.cpp | 42 +++++++++---------- .../SourceFiles/window/window_main_menu.cpp | 2 +- 5 files changed, 29 insertions(+), 29 deletions(-) diff --git a/Telegram/SourceFiles/ayu/ayu_settings.cpp b/Telegram/SourceFiles/ayu/ayu_settings.cpp index 8fe14ebb8..9b86bf764 100644 --- a/Telegram/SourceFiles/ayu/ayu_settings.cpp +++ b/Telegram/SourceFiles/ayu/ayu_settings.cpp @@ -164,7 +164,7 @@ namespace AyuSettings { voiceConfirmation = val; } - bool AyuGramSettings::getGhostModeValue() { + bool AyuGramSettings::get_ghostModeEnabled() const { return (!sendReadPackets && !sendOnlinePackets && !sendUploadProgress @@ -179,11 +179,11 @@ namespace AyuSettings { return editedMarkReactive.value(); } - rpl::producer get_showPeerId() { + rpl::producer get_showPeerIdReactive() { return showPeerIdReactive.value(); } - rpl::producer get_ghostModeEnabled() { + rpl::producer get_ghostModeEnabledReactive() { return ghostModeEnabled.value(); } } diff --git a/Telegram/SourceFiles/ayu/ayu_settings.h b/Telegram/SourceFiles/ayu/ayu_settings.h index 8d3577409..53a81b65c 100644 --- a/Telegram/SourceFiles/ayu/ayu_settings.h +++ b/Telegram/SourceFiles/ayu/ayu_settings.h @@ -122,7 +122,7 @@ namespace AyuSettings { void set_GIFConfirmation(bool val); void set_voiceConfirmation(bool val); - bool getGhostModeValue(); + bool get_ghostModeEnabled() const; }; AyuGramSettings &getInstance(); @@ -133,8 +133,8 @@ namespace AyuSettings { rpl::producer get_deletedMarkReactive(); rpl::producer get_editedMarkReactive(); - rpl::producer get_showPeerId(); + rpl::producer get_showPeerIdReactive(); // computed fields - rpl::producer get_ghostModeEnabled(); + rpl::producer get_ghostModeEnabledReactive(); } diff --git a/Telegram/SourceFiles/ayu/settings/settings_ayu.cpp b/Telegram/SourceFiles/ayu/settings/settings_ayu.cpp index 2971a07c9..909e34418 100644 --- a/Telegram/SourceFiles/ayu/settings/settings_ayu.cpp +++ b/Telegram/SourceFiles/ayu/settings/settings_ayu.cpp @@ -260,7 +260,7 @@ namespace Settings { QString("Bot API") }; - auto currentVal = AyuSettings::get_showPeerId() | rpl::map([=](int val) { + auto currentVal = AyuSettings::get_showPeerIdReactive() | rpl::map([=](int val) { return options[val]; }); diff --git a/Telegram/SourceFiles/tray.cpp b/Telegram/SourceFiles/tray.cpp index 9e9890af5..91205e853 100644 --- a/Telegram/SourceFiles/tray.cpp +++ b/Telegram/SourceFiles/tray.cpp @@ -90,28 +90,28 @@ void Tray::rebuildMenu() { [=] { toggleSoundNotifications(); }); } -// auto turnGhostModeText = _textUpdates.events( -// ) | rpl::map([=] { -// auto settings = AyuSettings::AyuGramSettings(); -// bool ghostModeEnabled = settings.getGhostModeValue(); -// -// return ghostModeEnabled -// ? tr::ayu_DisableGhostMode(tr::now) -// : tr::ayu_EnableGhostMode(tr::now); -// }); + auto turnGhostModeText = _textUpdates.events( + ) | rpl::map([=] { + auto settings = &AyuSettings::getInstance(); + bool ghostModeEnabled = settings->get_ghostModeEnabled(); -// _tray.addAction(rpl::single(QString("Toggle ghost mode")), [=] { -// auto settings = &AyuSettings::getInstance(); -// bool ghostMode = (bool) AyuSettings::get_ghostModeEnabled(); -// -// settings->set_sendReadPackets(!ghostMode); -// settings->set_sendOnlinePackets(!ghostMode); -// settings->set_sendUploadProgress(!ghostMode); -// -// settings->set_sendOfflinePacketAfterOnline(ghostMode); -// -// AyuSettings::save(); -// }); + return ghostModeEnabled + ? tr::ayu_DisableGhostMode(tr::now) + : tr::ayu_EnableGhostMode(tr::now); + }); + + _tray.addAction(std::move(turnGhostModeText), [=] { + auto settings = &AyuSettings::getInstance(); + bool ghostMode = !settings->get_ghostModeEnabled(); + + settings->set_sendReadPackets(!ghostMode); + settings->set_sendOnlinePackets(!ghostMode); + settings->set_sendUploadProgress(!ghostMode); + + settings->set_sendOfflinePacketAfterOnline(ghostMode); + + AyuSettings::save(); + }); auto quitText = _textUpdates.events( ) | rpl::map([=] { diff --git a/Telegram/SourceFiles/window/window_main_menu.cpp b/Telegram/SourceFiles/window/window_main_menu.cpp index b2eec63f3..944ee260e 100644 --- a/Telegram/SourceFiles/window/window_main_menu.cpp +++ b/Telegram/SourceFiles/window/window_main_menu.cpp @@ -851,7 +851,7 @@ void MainMenu::setupMenu() { _ghostModeToggle = addAction( tr::ayu_DrawerGhostModeToggle(), {&st::ayuGhostIcon, kIconPurple} - )->toggleOn(AyuSettings::get_ghostModeEnabled()); + )->toggleOn(AyuSettings::get_ghostModeEnabledReactive()); _ghostModeToggle->toggledChanges( ) | rpl::start_with_next([=](bool ghostMode) {