From e21ccd6024749d54675106ef56dd9f0262a41498 Mon Sep 17 00:00:00 2001 From: ZavaruKitsu Date: Sun, 4 Jun 2023 14:36:38 +0300 Subject: [PATCH] feat: settings overhaul fix: use more translations --- Telegram/SourceFiles/ayu/ayu_lang.cpp | 30 ++-- Telegram/SourceFiles/ayu/ayu_lang.h | 10 +- Telegram/SourceFiles/ayu/ayu_settings.cpp | 148 ++++++++++++++++-- Telegram/SourceFiles/ayu/ayu_settings.h | 76 +++------ Telegram/SourceFiles/ayu/ayu_state.h | 2 +- .../ayu/boxes/confirmation_box.cpp | 2 +- .../SourceFiles/ayu/boxes/confirmation_box.h | 7 +- .../ayu/boxes/edit_deleted_mark.cpp | 4 +- .../SourceFiles/ayu/boxes/edit_deleted_mark.h | 4 +- .../ayu/boxes/edit_edited_mark.cpp | 5 +- .../SourceFiles/ayu/boxes/edit_edited_mark.h | 4 +- .../ayu/context_menu/context_menu.cpp | 2 +- .../ayu/context_menu/message_history_box.cpp | 4 +- .../ayu/context_menu/message_history_box.h | 6 +- .../SourceFiles/ayu/database/ayu_database.cpp | 2 +- .../SourceFiles/ayu/database/ayu_database.h | 2 +- .../SourceFiles/ayu/settings/settings_ayu.cpp | 23 +-- .../SourceFiles/ayu/settings/settings_ayu.h | 29 ++-- .../SourceFiles/window/window_main_menu.cpp | 17 +- 19 files changed, 237 insertions(+), 140 deletions(-) diff --git a/Telegram/SourceFiles/ayu/ayu_lang.cpp b/Telegram/SourceFiles/ayu/ayu_lang.cpp index cb83310c7..ba03424eb 100644 --- a/Telegram/SourceFiles/ayu/ayu_lang.cpp +++ b/Telegram/SourceFiles/ayu/ayu_lang.cpp @@ -18,25 +18,34 @@ CustomLangPack *CustomLangPack::currentInstance() { return instance; } -void CustomLangPack::fetchCustomLangPack(const QString& langPackId, const QString& langPackBaseId) { +void CustomLangPack::fetchCustomLangPack(const QString &langPackId, const QString &langPackBaseId) { LOG(("Current Language pack ID: %1, Base ID: %2").arg(langPackId, langPackBaseId)); - const auto proxy = Core::App().settings().proxy().isEnabled() ? Core::App().settings().proxy().selected() : MTP::ProxyData(); + auto finalLangPackId = langPackId; + if (finalLangPackId == qsl("pt-br")) { // meh + finalLangPackId = qsl("pt"); + } + + const auto proxy = Core::App().settings().proxy().isEnabled() ? Core::App().settings().proxy().selected() + : MTP::ProxyData(); if (proxy.type == MTP::ProxyData::Type::Socks5 || proxy.type == MTP::ProxyData::Type::Http) { QNetworkProxy LocaleProxy = MTP::ToNetworkProxy(MTP::ToDirectIpProxy(proxy)); networkManager.setProxy(LocaleProxy); } QUrl url; - if (!langPackId.isEmpty() && !langPackBaseId.isEmpty() && !needFallback) { - url.setUrl(qsl("https://raw.githubusercontent.com/AyuGram/localization/translations/desktop/%1.json").arg(langPackId)); + if (!finalLangPackId.isEmpty() && !langPackBaseId.isEmpty() && !needFallback) { + url.setUrl(qsl("https://raw.githubusercontent.com/AyuGram/localization/translations/desktop/%1.json").arg( + finalLangPackId)); } else { - url.setUrl(qsl("https://raw.githubusercontent.com/AyuGram/localization/translations/desktop/%1.json").arg(needFallback ? langPackBaseId : langPackId)); + url.setUrl(qsl("https://raw.githubusercontent.com/AyuGram/localization/translations/desktop/%1.json").arg( + needFallback ? langPackBaseId : finalLangPackId)); } _chkReply = networkManager.get(QNetworkRequest(url)); connect(_chkReply, SIGNAL(error(QNetworkReply::NetworkError)), this, SLOT(fetchError(QNetworkReply::NetworkError))); connect(_chkReply, SIGNAL(finished()), this, SLOT(fetchFinished())); - LOG(("Fetching %1 lang pack...").arg(needFallback ? (langPackBaseId.isEmpty() ? langPackId : langPackBaseId) : langPackId)); + LOG(("Fetching %1 lang pack...").arg( + needFallback ? (langPackBaseId.isEmpty() ? finalLangPackId : langPackBaseId) : finalLangPackId)); } void CustomLangPack::fetchFinished() { @@ -51,8 +60,7 @@ void CustomLangPack::fetchFinished() { needFallback = true; _chkReply->disconnect(); fetchCustomLangPack("", langPackBaseId); - } - else { + } else { QByteArray result = _chkReply->readAll().trimmed(); QJsonParseError error{}; QJsonDocument str = QJsonDocument::fromJson(result, &error); @@ -92,7 +100,7 @@ void CustomLangPack::loadDefaultLangFile() { if (file.open(QIODevice::ReadOnly)) { QJsonDocument str = QJsonDocument::fromJson(file.readAll()); QJsonObject json = str.object(); - for (const QString& key : json.keys()) { + for (const QString &key: json.keys()) { Lang::GetInstance().applyValue(key.toUtf8(), json.value(key).toString().toUtf8()); } Lang::GetInstance().updatePluralRules(); @@ -102,9 +110,9 @@ void CustomLangPack::loadDefaultLangFile() { void CustomLangPack::parseLangFile(QJsonDocument str) { QJsonObject json = str.object(); - for (const QString& brokenKey : json.keys()) { + for (const QString &brokenKey: json.keys()) { auto key = qsl("ayu_") + brokenKey; - auto val = json.value(brokenKey).toString().toUtf8(); + auto val = json.value(brokenKey).toString().replace(qsl("&"), qsl("&")).toUtf8(); Lang::GetInstance().resetValue(key.toUtf8()); Lang::GetInstance().applyValue(key.toUtf8(), val); diff --git a/Telegram/SourceFiles/ayu/ayu_lang.h b/Telegram/SourceFiles/ayu/ayu_lang.h index fe5af4880..a1ad32a3a 100644 --- a/Telegram/SourceFiles/ayu/ayu_lang.h +++ b/Telegram/SourceFiles/ayu/ayu_lang.h @@ -5,23 +5,31 @@ class CustomLangPack : public QObject { Q_OBJECT + Q_DISABLE_COPY(CustomLangPack) public: static CustomLangPack *currentInstance(); + static void initInstance(); + static CustomLangPack *instance; - void fetchCustomLangPack(const QString& langPackId, const QString& langPackBaseId); + void fetchCustomLangPack(const QString &langPackId, const QString &langPackBaseId); + void loadDefaultLangFile(); + void parseLangFile(QJsonDocument str); public Q_SLOTS: + void fetchFinished(); + void fetchError(QNetworkReply::NetworkError e); private: CustomLangPack(); + ~CustomLangPack() = default; QNetworkAccessManager networkManager; diff --git a/Telegram/SourceFiles/ayu/ayu_settings.cpp b/Telegram/SourceFiles/ayu/ayu_settings.cpp index 5fd384f56..c944d18c5 100644 --- a/Telegram/SourceFiles/ayu/ayu_settings.cpp +++ b/Telegram/SourceFiles/ayu/ayu_settings.cpp @@ -1,14 +1,57 @@ #include "ayu_settings.h" +#include "rpl/lifetime.h" namespace AyuSettings { const QString filename = "tdata/ayu_settings.json"; - const int latestMigration = 1; std::optional settings = std::nullopt; - AyuGramSettings &getInstance() { - if (!settings.has_value()) { - settings = std::optional(AyuGramSettings()); + rpl::variable sendReadPacketsReactive; + rpl::variable sendOnlinePacketsReactive; + rpl::variable sendOfflinePacketAfterOnlineReactive; + rpl::variable sendUploadProgressReactive; + rpl::variable useScheduledMessagesReactive; + rpl::variable keepDeletedMessagesReactive; + rpl::variable keepMessagesHistoryReactive; + rpl::variable deletedMarkReactive; + rpl::variable editedMarkReactive; + rpl::variable ghostModeEnabled; + + rpl::lifetime lifetime = rpl::lifetime(); + + void initialize() { + if (settings.has_value()) { + return; } + + settings = std::optional(AyuGramSettings()); + + sendReadPacketsReactive.value() | rpl::filter([=](bool val) { + return (val != settings->sendReadPackets); + }) | rpl::start_with_next([=](bool val) { + ghostModeEnabled = !settings->sendReadPackets && !settings->sendOnlinePackets; + }, lifetime); + sendOnlinePacketsReactive.value() | rpl::filter([=](bool val) { + return (val != settings->sendOnlinePackets); + }) | rpl::start_with_next([=](bool val) { + ghostModeEnabled = !settings->sendReadPackets && !settings->sendOnlinePackets; + }, lifetime); + } + + void postinitialize() { + sendReadPacketsReactive = settings->sendReadPackets; + sendOnlinePacketsReactive = settings->sendOnlinePackets; + sendOfflinePacketAfterOnlineReactive = settings->sendOfflinePacketAfterOnline; + sendUploadProgressReactive = settings->sendUploadProgress; + useScheduledMessagesReactive = settings->useScheduledMessages; + keepDeletedMessagesReactive = settings->keepDeletedMessages; + keepMessagesHistoryReactive = settings->keepMessagesHistory; + deletedMarkReactive = settings->deletedMark; + editedMarkReactive = settings->editedMark; + ghostModeEnabled = !settings->sendReadPackets && !settings->sendOnlinePackets; + } + + AyuGramSettings &getInstance() { + initialize(); return settings.value(); } @@ -21,23 +64,106 @@ namespace AyuSettings { QByteArray json = file.readAll(); file.close(); - if (!settings.has_value()) { - settings = std::optional(AyuGramSettings()); - } + initialize(); settings->fromJson(json); + postinitialize(); } void save() { - if (!settings.has_value()) { - settings = std::optional(AyuGramSettings()); - } + initialize(); - settings->migrationVersion = latestMigration; QByteArray json = settings->toRawJson(); QFile file(filename); file.open(QIODevice::WriteOnly); file.write(json); file.close(); + + postinitialize(); + } + + void AyuGramSettings::set_sendReadPackets(bool val) { + sendReadPackets = val; + sendReadPacketsReactive = val; + } + + void AyuGramSettings::set_sendOnlinePackets(bool val) { + sendOnlinePackets = val; + sendOnlinePacketsReactive = val; + } + + void AyuGramSettings::set_sendOfflinePacketAfterOnline(bool val) { + sendOfflinePacketAfterOnline = val; + sendOfflinePacketAfterOnlineReactive = val; + } + + void AyuGramSettings::set_sendUploadProgress(bool val) { + sendUploadProgress = val; + sendUploadProgressReactive = val; + } + + void AyuGramSettings::set_useScheduledMessages(bool val) { + useScheduledMessages = val; + useScheduledMessagesReactive = val; + } + + void AyuGramSettings::set_keepDeletedMessages(bool val) { + keepDeletedMessages = val; + keepDeletedMessagesReactive = val; + } + + void AyuGramSettings::set_keepMessagesHistory(bool val) { + keepMessagesHistory = val; + keepMessagesHistoryReactive = val; + } + + void AyuGramSettings::set_deletedMark(QString val) { + deletedMark = std::move(val); + deletedMarkReactive = deletedMark; + } + + void AyuGramSettings::set_editedMark(QString val) { + editedMark = std::move(val); + editedMarkReactive = editedMark; + } + + rpl::variable get_sendReadPacketsReactive() { + return sendReadPacketsReactive; + } + + rpl::variable get_sendOnlinePacketsReactive() { + return sendOnlinePacketsReactive; + } + + rpl::variable get_sendOfflinePacketAfterOnlineReactive() { + return sendOfflinePacketAfterOnlineReactive; + } + + rpl::variable get_sendUploadProgressReactive() { + return sendUploadProgressReactive; + } + + rpl::variable get_useScheduledMessagesReactive() { + return useScheduledMessagesReactive; + } + + rpl::variable get_keepDeletedMessagesReactive() { + return keepDeletedMessagesReactive; + } + + rpl::variable get_keepMessagesHistoryReactive() { + return keepMessagesHistoryReactive; + } + + rpl::variable get_deletedMarkReactive() { + return deletedMarkReactive; + } + + rpl::variable get_editedMarkReactive() { + return editedMarkReactive; + } + + rpl::variable get_ghostModeEnabled() { + return ghostModeEnabled; } } diff --git a/Telegram/SourceFiles/ayu/ayu_settings.h b/Telegram/SourceFiles/ayu/ayu_settings.h index deba8fb58..6a3075593 100644 --- a/Telegram/SourceFiles/ayu/ayu_settings.h +++ b/Telegram/SourceFiles/ayu/ayu_settings.h @@ -1,8 +1,10 @@ #pragma once +#include "rpl/producer.h" + #define QS_HAS_JSON -#include +#include "lang_auto.h" #include "qserializer.h" namespace AyuSettings { @@ -11,8 +13,6 @@ namespace AyuSettings { public: AyuGramSettings() { - migrationVersion = 0; - sendReadPackets = true; sendOnlinePackets = true; sendOfflinePacketAfterOnline = false; @@ -22,13 +22,10 @@ namespace AyuSettings { keepMessagesHistory = false; deletedMark = "🧹"; editedMark = tr::lng_edited(tr::now); - ghostMode = true; } QS_SERIALIZABLE - QS_FIELD(int, migrationVersion) - QS_FIELD(bool, sendReadPackets) QS_FIELD(bool, sendOnlinePackets) @@ -47,52 +44,16 @@ namespace AyuSettings { QS_FIELD(QString, editedMark) - QS_FIELD(bool, ghostMode) - public: - void set_migrationVersion(int val) { - migrationVersion = val; - } - - void set_sendReadPackets(bool val) { - sendReadPackets = val; - } - - void set_sendOnlinePackets(bool val) { - sendOnlinePackets = val; - } - - void set_sendOfflinePacketAfterOnline(bool val) { - sendOfflinePacketAfterOnline = val; - } - - void set_sendUploadProgress(bool val) { - sendUploadProgress = val; - } - - void set_useScheduledMessages(bool val) { - useScheduledMessages = val; - } - - void set_keepDeletedMessages(bool val) { - keepDeletedMessages = val; - } - - void set_keepMessagesHistory(bool val) { - keepMessagesHistory = val; - } - - void set_deletedMark(QString val) { - deletedMark = val; - } - - void set_editedMark(QString val) { - editedMark = val; - } - - void set_ghostMode(bool val) { - ghostMode = val; - } + void set_sendReadPackets(bool val); + void set_sendOnlinePackets(bool val); + void set_sendOfflinePacketAfterOnline(bool val); + void set_sendUploadProgress(bool val); + void set_useScheduledMessages(bool val); + void set_keepDeletedMessages(bool val); + void set_keepMessagesHistory(bool val); + void set_deletedMark(QString val); + void set_editedMark(QString val); }; AyuGramSettings &getInstance(); @@ -100,4 +61,17 @@ namespace AyuSettings { void load(); void save(); + + rpl::variable get_sendReadPacketsReactive(); + rpl::variable get_sendOnlinePacketsReactive(); + rpl::variable get_sendOfflinePacketAfterOnlineReactive(); + rpl::variable get_sendUploadProgressReactive(); + rpl::variable get_useScheduledMessagesReactive(); + rpl::variable get_keepDeletedMessagesReactive(); + rpl::variable get_keepMessagesHistoryReactive(); + rpl::variable get_deletedMarkReactive(); + rpl::variable get_editedMarkReactive(); + + // computed fields + rpl::variable get_ghostModeEnabled(); } diff --git a/Telegram/SourceFiles/ayu/ayu_state.h b/Telegram/SourceFiles/ayu/ayu_state.h index 3cd3bdc17..feb32b102 100644 --- a/Telegram/SourceFiles/ayu/ayu_state.h +++ b/Telegram/SourceFiles/ayu/ayu_state.h @@ -12,7 +12,7 @@ namespace AyuState { AyuStateVariable allowSendReadPacket; - bool processVariable(AyuStateVariable& variable) { + bool processVariable(AyuStateVariable &variable) { if (variable.resetAfter == -1) { return variable.val; } diff --git a/Telegram/SourceFiles/ayu/boxes/confirmation_box.cpp b/Telegram/SourceFiles/ayu/boxes/confirmation_box.cpp index aa4b035b0..ab9f6b23e 100644 --- a/Telegram/SourceFiles/ayu/boxes/confirmation_box.cpp +++ b/Telegram/SourceFiles/ayu/boxes/confirmation_box.cpp @@ -9,7 +9,7 @@ namespace AyuUi { ConfirmationBox::ConfirmationBox( - QWidget*, + QWidget *, not_null controller) : _controller(controller) { // } diff --git a/Telegram/SourceFiles/ayu/boxes/confirmation_box.h b/Telegram/SourceFiles/ayu/boxes/confirmation_box.h index 78943de0b..ca2db79fd 100644 --- a/Telegram/SourceFiles/ayu/boxes/confirmation_box.h +++ b/Telegram/SourceFiles/ayu/boxes/confirmation_box.h @@ -4,11 +4,14 @@ namespace AyuUi { class ConfirmationBox : public Ui::BoxContent { public: - ConfirmationBox(QWidget*, not_null controller); + ConfirmationBox(QWidget *, not_null controller); + protected: void prepare() override; + private: void ReadAllPeers(); - not_null _controller; + + not_null _controller; }; } \ No newline at end of file diff --git a/Telegram/SourceFiles/ayu/boxes/edit_deleted_mark.cpp b/Telegram/SourceFiles/ayu/boxes/edit_deleted_mark.cpp index 784c86db2..7530c12d8 100644 --- a/Telegram/SourceFiles/ayu/boxes/edit_deleted_mark.cpp +++ b/Telegram/SourceFiles/ayu/boxes/edit_deleted_mark.cpp @@ -75,8 +75,8 @@ void EditDeletedMarkBox::resizeEvent(QResizeEvent *e) { void EditDeletedMarkBox::save() { const auto settings = &AyuSettings::getInstance(); - settings->deletedMark = _text->getLastText(); - Local::writeSettings(); + settings->set_deletedMark(_text->getLastText()); + AyuSettings::save(); closeBox(); } diff --git a/Telegram/SourceFiles/ayu/boxes/edit_deleted_mark.h b/Telegram/SourceFiles/ayu/boxes/edit_deleted_mark.h index 54197c44d..b303b5152 100644 --- a/Telegram/SourceFiles/ayu/boxes/edit_deleted_mark.h +++ b/Telegram/SourceFiles/ayu/boxes/edit_deleted_mark.h @@ -6,16 +6,18 @@ class EditDeletedMarkBox : public Ui::BoxContent { public: - EditDeletedMarkBox(QWidget*); + EditDeletedMarkBox(QWidget *); protected: void setInnerFocus() override; + void prepare() override; void resizeEvent(QResizeEvent *e) override; private: void submit(); + void save(); object_ptr _text; diff --git a/Telegram/SourceFiles/ayu/boxes/edit_edited_mark.cpp b/Telegram/SourceFiles/ayu/boxes/edit_edited_mark.cpp index b1cda468a..4075b0e17 100644 --- a/Telegram/SourceFiles/ayu/boxes/edit_edited_mark.cpp +++ b/Telegram/SourceFiles/ayu/boxes/edit_edited_mark.cpp @@ -31,7 +31,6 @@ EditEditedMarkBox::EditEditedMarkBox(QWidget *) : } - void EditEditedMarkBox::prepare() { const auto defaultEditedMark = tr::lng_edited(tr::now); auto newHeight = st::contactPadding.top() + _text->height(); @@ -78,8 +77,8 @@ void EditEditedMarkBox::resizeEvent(QResizeEvent *e) { void EditEditedMarkBox::save() { const auto settings = &AyuSettings::getInstance(); - settings->editedMark = _text->getLastText(); - Local::writeSettings(); + settings->set_editedMark(_text->getLastText()); + AyuSettings::save(); closeBox(); } \ No newline at end of file diff --git a/Telegram/SourceFiles/ayu/boxes/edit_edited_mark.h b/Telegram/SourceFiles/ayu/boxes/edit_edited_mark.h index 601ba51dd..966fa9cd0 100644 --- a/Telegram/SourceFiles/ayu/boxes/edit_edited_mark.h +++ b/Telegram/SourceFiles/ayu/boxes/edit_edited_mark.h @@ -6,16 +6,18 @@ class EditEditedMarkBox : public Ui::BoxContent { public: - EditEditedMarkBox(QWidget*); + EditEditedMarkBox(QWidget *); protected: void setInnerFocus() override; + void prepare() override; void resizeEvent(QResizeEvent *e) override; private: void submit(); + void save(); object_ptr _text; diff --git a/Telegram/SourceFiles/ayu/context_menu/context_menu.cpp b/Telegram/SourceFiles/ayu/context_menu/context_menu.cpp index dc43dd1ea..ddf5df590 100644 --- a/Telegram/SourceFiles/ayu/context_menu/context_menu.cpp +++ b/Telegram/SourceFiles/ayu/context_menu/context_menu.cpp @@ -16,7 +16,7 @@ namespace AyuUi { void AyuPopupMenu::addHistoryAction(HistoryItem *item) { if (AyuDatabase::editedMessagesTableExists() && !((AyuDatabase::getEditedMessages(item)).empty())) { - _ayuSubMenu->addAction(QString("History"), [=] { + _ayuSubMenu->addAction(tr::ayu_EditsHistoryMenuText(tr::now), [=] { auto box = Box(item); Ui::show(std::move(box)); }, &st::menuIconInfo); diff --git a/Telegram/SourceFiles/ayu/context_menu/message_history_box.cpp b/Telegram/SourceFiles/ayu/context_menu/message_history_box.cpp index 69b2cb6d3..4d40357d3 100644 --- a/Telegram/SourceFiles/ayu/context_menu/message_history_box.cpp +++ b/Telegram/SourceFiles/ayu/context_menu/message_history_box.cpp @@ -40,7 +40,7 @@ namespace AyuUi { } void MessageHistoryBox::prepare() { - setTitle(rpl::single(QString("Message history"))); + setTitle(tr::ayu_EditsHistoryTitle()); // setDimensionsToContent(st::boxWideWidth, _content); setDimensions(st::boxWideWidth, 900); @@ -53,7 +53,7 @@ namespace AyuUi { return; } - for (const auto& message : messages) { + for (const auto &message: messages) { AddSkip(_content); AddDividerText(_content, rpl::single(QString::fromStdString(message.text))); AddSkip(_content); diff --git a/Telegram/SourceFiles/ayu/context_menu/message_history_box.h b/Telegram/SourceFiles/ayu/context_menu/message_history_box.h index d8ae31d06..b8267abb5 100644 --- a/Telegram/SourceFiles/ayu/context_menu/message_history_box.h +++ b/Telegram/SourceFiles/ayu/context_menu/message_history_box.h @@ -6,12 +6,16 @@ namespace AyuUi { class MessageHistoryBox : public Ui::BoxContent { public: - MessageHistoryBox(QWidget*, HistoryItem *item); + MessageHistoryBox(QWidget *, HistoryItem *item); + protected: void prepare() override; + void resizeEvent(QResizeEvent *e) override; + private: void setupControls(); + void addEditedMessagesToLayout(HistoryItem *item); object_ptr _content; diff --git a/Telegram/SourceFiles/ayu/database/ayu_database.cpp b/Telegram/SourceFiles/ayu/database/ayu_database.cpp index fd2dea76d..d619e1435 100644 --- a/Telegram/SourceFiles/ayu/database/ayu_database.cpp +++ b/Telegram/SourceFiles/ayu/database/ayu_database.cpp @@ -56,7 +56,7 @@ namespace AyuDatabase { c(&EditedMessage::userId) == userId and c(&EditedMessage::dialogId) == dialogId and c(&EditedMessage::messageId) == messageId) - ); + ); } std::vector getEditedMessages(HistoryItem *item) { diff --git a/Telegram/SourceFiles/ayu/database/ayu_database.h b/Telegram/SourceFiles/ayu/database/ayu_database.h index 6651feecd..09f1c9a2a 100644 --- a/Telegram/SourceFiles/ayu/database/ayu_database.h +++ b/Telegram/SourceFiles/ayu/database/ayu_database.h @@ -9,7 +9,7 @@ namespace AyuDatabase { long userId, long dialogId, long messageId, - const QString& text, + const QString &text, bool isDocument, QString path, long date); diff --git a/Telegram/SourceFiles/ayu/settings/settings_ayu.cpp b/Telegram/SourceFiles/ayu/settings/settings_ayu.cpp index 370ec46e7..78e8d1824 100644 --- a/Telegram/SourceFiles/ayu/settings/settings_ayu.cpp +++ b/Telegram/SourceFiles/ayu/settings/settings_ayu.cpp @@ -35,8 +35,7 @@ namespace Settings { setupContent(controller); } - void Ayu::SetupAyuGramSettings(not_null container, - not_null controller) { + void Ayu::SetupAyuGramSettings(not_null container) { auto settings = &AyuSettings::getInstance(); AddSkip(container); @@ -150,41 +149,27 @@ namespace Settings { AddSubsectionTitle(container, tr::ayu_CustomizationHeader()); - auto currentDeletedMark = lifetime().make_state>(); - auto btn = AddButtonWithLabel( container, tr::ayu_DeletedMarkText(), - currentDeletedMark->changes(), + AyuSettings::get_deletedMarkReactive().value(), st::settingsButtonNoIcon ); btn->addClickHandler([=]() { auto box = Box(); - box->boxClosing() | rpl::start_with_next([=]() { - *currentDeletedMark = settings->deletedMark; - }, container->lifetime()); - Ui::show(std::move(box)); }); - *currentDeletedMark = settings->deletedMark; - - auto currentEditedMark = lifetime().make_state>(); auto btn2 = AddButtonWithLabel( container, rpl::single(QString("Edited mark")), - currentEditedMark->changes(), + AyuSettings::get_editedMarkReactive().value(), st::settingsButtonNoIcon ); btn2->addClickHandler([=]() { auto box = Box(); - box->boxClosing() | rpl::start_with_next([=]() { - *currentEditedMark = settings->editedMark; - }, container->lifetime()); - Ui::show(std::move(box)); }); - *currentEditedMark = settings->editedMark; AddDividerText(container, tr::ayu_SettingsWatermark()); } @@ -192,7 +177,7 @@ namespace Settings { void Ayu::setupContent(not_null controller) { const auto content = Ui::CreateChild(this); - SetupAyuGramSettings(content, controller); + SetupAyuGramSettings(content); Ui::ResizeFitChild(this, content); } diff --git a/Telegram/SourceFiles/ayu/settings/settings_ayu.h b/Telegram/SourceFiles/ayu/settings/settings_ayu.h index 790911fca..e1000c46c 100644 --- a/Telegram/SourceFiles/ayu/settings/settings_ayu.h +++ b/Telegram/SourceFiles/ayu/settings/settings_ayu.h @@ -1,10 +1,3 @@ -/* -This file is part of 64Gram Desktop, -the unofficial app based on Telegram Desktop. - -For license and copyright information please follow this link: -https://github.com/TDesktop-x64/tdesktop/blob/dev/LEGAL -*/ #pragma once #include "settings/settings_common.h" @@ -12,21 +5,21 @@ https://github.com/TDesktop-x64/tdesktop/blob/dev/LEGAL class BoxContent; namespace Window { -class Controller; -class SessionController; + class Controller; + + class SessionController; } // namespace Window namespace Settings { - class Ayu : public Section { - public: - Ayu( - QWidget *parent, - not_null controller); + class Ayu : public Section { + public: + Ayu(QWidget *parent, not_null controller); + [[nodiscard]] rpl::producer title() override; - private: - void SetupAyuGramSettings(not_null container, not_null null); - void setupContent(not_null controller); - }; + private: + void SetupAyuGramSettings(not_null container); + void setupContent(not_null controller); + }; } // namespace Settings diff --git a/Telegram/SourceFiles/window/window_main_menu.cpp b/Telegram/SourceFiles/window/window_main_menu.cpp index 3370c2a8a..909228c2c 100644 --- a/Telegram/SourceFiles/window/window_main_menu.cpp +++ b/Telegram/SourceFiles/window/window_main_menu.cpp @@ -843,28 +843,21 @@ void MainMenu::setupMenu() { toggle); }, _nightThemeToggle->lifetime()); + const auto settings = &AyuSettings::getInstance(); _ghostModeToggle = addAction( rpl::single(QString("Ghost Mode")), { &st::menuIconFake, kIconPurple } - )->toggleOn(rpl::single((&AyuSettings::getInstance())->ghostMode)); + )->toggleOn(AyuSettings::get_ghostModeEnabled().value()); _ghostModeToggle->toggledChanges( - ) | rpl::filter([=](bool ghostMode) { - const auto settings = &AyuSettings::getInstance(); - return (ghostMode != settings->ghostMode); - }) | rpl::start_with_next([=](bool ghostMode) { - const auto settings = &AyuSettings::getInstance(); - settings->set_ghostMode(ghostMode); - + ) | rpl::start_with_next([=](bool ghostMode) { settings->set_sendReadPackets(!ghostMode); settings->set_sendOnlinePackets(!ghostMode); - settings->set_sendOfflinePacketAfterOnline(ghostMode); settings->set_sendUploadProgress(!ghostMode); - settings->set_keepDeletedMessages(ghostMode); - settings->set_keepMessagesHistory(ghostMode); + + settings->set_sendOfflinePacketAfterOnline(ghostMode); AyuSettings::save(); - }, _ghostModeToggle->lifetime()); Core::App().settings().systemDarkModeValue(