chore: redirect from experimental to settings

This commit is contained in:
AlexeyZavar
2026-04-07 21:44:18 +03:00
parent 9fc2ed338d
commit ae8de84828
11 changed files with 121 additions and 62 deletions
+5 -5
View File
@@ -777,9 +777,9 @@ void AyuSettings::setShowAutoDeleteButtonInMessageField(bool val) {
save();
}
void AyuSettings::setShowCocoonAiButtonInMessageField(bool val) {
if (_showCocoonAiButtonInMessageField.current() == val) return;
_showCocoonAiButtonInMessageField = val;
void AyuSettings::setShowAiEditorButtonInMessageField(bool val) {
if (_showAiEditorButtonInMessageField.current() == val) return;
_showAiEditorButtonInMessageField = val;
save();
}
@@ -1063,7 +1063,7 @@ void to_json(nlohmann::json &j, const AyuSettings &s) {
{"showEmojiButtonInMessageField", s._showEmojiButtonInMessageField.current()},
{"showMicrophoneButtonInMessageField", s._showMicrophoneButtonInMessageField.current()},
{"showAutoDeleteButtonInMessageField", s._showAutoDeleteButtonInMessageField.current()},
{"showCocoonAiButtonInMessageField", s._showCocoonAiButtonInMessageField.current()},
{"showAiEditorButtonInMessageField", s._showAiEditorButtonInMessageField.current()},
{"showAttachPopup", s._showAttachPopup.current()},
{"showEmojiPopup", s._showEmojiPopup.current()},
{"showMyProfileInDrawer", s._showMyProfileInDrawer.current()},
@@ -1162,7 +1162,7 @@ void from_json(const nlohmann::json &j, AyuSettings &s) {
s._showEmojiButtonInMessageField = j.value("showEmojiButtonInMessageField", defaults._showEmojiButtonInMessageField.current());
s._showMicrophoneButtonInMessageField = j.value("showMicrophoneButtonInMessageField", defaults._showMicrophoneButtonInMessageField.current());
s._showAutoDeleteButtonInMessageField = j.value("showAutoDeleteButtonInMessageField", defaults._showAutoDeleteButtonInMessageField.current());
s._showCocoonAiButtonInMessageField = j.value("showCocoonAiButtonInMessageField", defaults._showCocoonAiButtonInMessageField.current());
s._showAiEditorButtonInMessageField = j.value("showAiEditorButtonInMessageField", defaults._showAiEditorButtonInMessageField.current());
s._showAttachPopup = j.value("showAttachPopup", defaults._showAttachPopup.current());
s._showEmojiPopup = j.value("showEmojiPopup", defaults._showEmojiPopup.current());
s._showMyProfileInDrawer = j.value("showMyProfileInDrawer", defaults._showMyProfileInDrawer.current());
+5 -5
View File
@@ -292,7 +292,7 @@ public:
[[nodiscard]] bool showEmojiButtonInMessageField() const { return _showEmojiButtonInMessageField.current(); }
[[nodiscard]] bool showMicrophoneButtonInMessageField() const { return _showMicrophoneButtonInMessageField.current(); }
[[nodiscard]] bool showAutoDeleteButtonInMessageField() const { return _showAutoDeleteButtonInMessageField.current(); }
[[nodiscard]] bool showCocoonAiButtonInMessageField() const { return _showCocoonAiButtonInMessageField.current(); }
[[nodiscard]] bool showAiEditorButtonInMessageField() const { return _showAiEditorButtonInMessageField.current(); }
[[nodiscard]] bool showAttachPopup() const { return _showAttachPopup.current(); }
[[nodiscard]] bool showEmojiPopup() const { return _showEmojiPopup.current(); }
[[nodiscard]] bool showMyProfileInDrawer() const { return _showMyProfileInDrawer.current(); }
@@ -375,7 +375,7 @@ public:
void setShowEmojiButtonInMessageField(bool val);
void setShowMicrophoneButtonInMessageField(bool val);
void setShowAutoDeleteButtonInMessageField(bool val);
void setShowCocoonAiButtonInMessageField(bool val);
void setShowAiEditorButtonInMessageField(bool val);
void setShowAttachPopup(bool val);
void setShowEmojiPopup(bool val);
void setShowMyProfileInDrawer(bool val);
@@ -506,8 +506,8 @@ public:
[[nodiscard]] rpl::producer<bool> showMicrophoneButtonInMessageFieldChanges() const { return _showMicrophoneButtonInMessageField.changes(); }
[[nodiscard]] rpl::producer<bool> showAutoDeleteButtonInMessageFieldValue() const { return _showAutoDeleteButtonInMessageField.value(); }
[[nodiscard]] rpl::producer<bool> showAutoDeleteButtonInMessageFieldChanges() const { return _showAutoDeleteButtonInMessageField.changes(); }
[[nodiscard]] rpl::producer<bool> showCocoonAiButtonInMessageFieldValue() const { return _showCocoonAiButtonInMessageField.value(); }
[[nodiscard]] rpl::producer<bool> showCocoonAiButtonInMessageFieldChanges() const { return _showCocoonAiButtonInMessageField.changes(); }
[[nodiscard]] rpl::producer<bool> showAiEditorButtonInMessageFieldValue() const { return _showAiEditorButtonInMessageField.value(); }
[[nodiscard]] rpl::producer<bool> showAiEditorButtonInMessageFieldChanges() const { return _showAiEditorButtonInMessageField.changes(); }
[[nodiscard]] rpl::producer<bool> showAttachPopupValue() const { return _showAttachPopup.value(); }
[[nodiscard]] rpl::producer<bool> showAttachPopupChanges() const { return _showAttachPopup.changes(); }
[[nodiscard]] rpl::producer<bool> showEmojiPopupValue() const { return _showEmojiPopup.value(); }
@@ -633,7 +633,7 @@ private:
rpl::variable<bool> _showEmojiButtonInMessageField = true;
rpl::variable<bool> _showMicrophoneButtonInMessageField = true;
rpl::variable<bool> _showAutoDeleteButtonInMessageField = true;
rpl::variable<bool> _showCocoonAiButtonInMessageField = true;
rpl::variable<bool> _showAiEditorButtonInMessageField = true;
rpl::variable<bool> _showAttachPopup = true;
rpl::variable<bool> _showEmojiPopup = true;
rpl::variable<bool> _showMyProfileInDrawer = true;
@@ -414,10 +414,10 @@ void BuildMessageFieldElements(SectionBuilder &builder, AyuSectionBuilder &ayu)
.icon = { &st::messageFieldVoiceIcon },
});
ayu.addSettingToggle({
.id = u"ayu/showCocoonAiButtonInMessageField"_q,
.id = u"ayu/showAiEditorButtonInMessageField"_q,
.title = tr::lng_ai_compose_title(),
.getter = &AyuSettings::showCocoonAiButtonInMessageField,
.setter = &AyuSettings::setShowCocoonAiButtonInMessageField,
.getter = &AyuSettings::showAiEditorButtonInMessageField,
.setter = &AyuSettings::setShowAiEditorButtonInMessageField,
.icon = { &st::messageFieldCocoonAiIcon },
});
@@ -81,7 +81,6 @@ base::options::toggle OptionUnlimitedRecentStickers({
.id = kOptionUnlimitedRecentStickers,
.name = "Unlimited recent stickers",
.description = "Display as much recent stickers as the server provides",
.scope = static_cast<base::options::details::ScopeFlag>(0)
});
[[nodiscard]] bool SetInMyList(Data::StickersSetFlags flags) {
@@ -30,7 +30,6 @@ base::options::toggle TabbedPanelShowOnClick({
.id = kOptionTabbedPanelShowOnClick,
.name = "Show tabbed panel by click",
.description = "Show Emoji / Stickers / GIFs panel only after a click.",
.scope = static_cast<base::options::details::ScopeFlag>(0),
});
} // namespace
@@ -38,7 +37,7 @@ base::options::toggle TabbedPanelShowOnClick({
const char kOptionTabbedPanelShowOnClick[] = "tabbed-panel-show-on-click";
bool ShowPanelOnClick() {
return TabbedPanelShowOnClick.value();
return !AyuSettings::getInstance().showEmojiPopup();
}
TabbedPanel::TabbedPanel(
@@ -487,7 +486,7 @@ void TabbedPanel::showStarted() {
bool TabbedPanel::eventFilter(QObject *obj, QEvent *e) {
const auto &settings = AyuSettings::getInstance();
if (TabbedPanelShowOnClick.value() || !settings.showEmojiPopup()) {
if (!settings.showEmojiPopup()) {
return false;
} else if (e->type() == QEvent::Enter) {
otherEnter();
@@ -833,7 +833,7 @@ HistoryWidget::HistoryWidget(
AyuSettings::getInstance().showEmojiButtonInMessageFieldChanges() | rpl::to_empty,
AyuSettings::getInstance().showMicrophoneButtonInMessageFieldChanges() | rpl::to_empty,
AyuSettings::getInstance().showAutoDeleteButtonInMessageFieldChanges() | rpl::to_empty,
AyuSettings::getInstance().showCocoonAiButtonInMessageFieldChanges() | rpl::to_empty,
AyuSettings::getInstance().showAiEditorButtonInMessageFieldChanges() | rpl::to_empty,
AyuSettings::getInstance().showAttachPopupChanges() | rpl::to_empty,
AyuSettings::getInstance().showEmojiPopupChanges() | rpl::to_empty,
AyuSettings::getInstance().channelBottomButtonChanges() | rpl::to_empty,
@@ -2239,7 +2239,7 @@ void ComposeControls::init() {
AyuSettings::getInstance().showEmojiButtonInMessageFieldChanges() | rpl::to_empty,
AyuSettings::getInstance().showMicrophoneButtonInMessageFieldChanges() | rpl::to_empty,
AyuSettings::getInstance().showAutoDeleteButtonInMessageFieldChanges() | rpl::to_empty,
AyuSettings::getInstance().showCocoonAiButtonInMessageFieldChanges() | rpl::to_empty,
AyuSettings::getInstance().showAiEditorButtonInMessageFieldChanges() | rpl::to_empty,
AyuSettings::getInstance().showAttachPopupChanges() | rpl::to_empty,
AyuSettings::getInstance().showEmojiPopupChanges() | rpl::to_empty,
AyuSettings::getInstance().channelBottomButtonChanges() | rpl::to_empty,
@@ -127,7 +127,6 @@ base::options::toggle ShowPeerIdBelowAbout({
.name = "Show Peer IDs in Profile",
.description = "Show peer IDs from API below their Bio / Description."
" Add contact IDs to exported data.",
.scope = static_cast<base::options::details::ScopeFlag>(0),
});
base::options::toggle ShowChannelJoinedBelowAbout({
@@ -222,26 +221,11 @@ base::options::toggle ShowChannelJoinedBelowAbout({
return AboutValue(
peer
) | rpl::map([=](TextWithEntities &&value) {
if (ShowPeerIdBelowAbout.value()) {
using namespace Ui::Text;
if (!value.empty()) {
value.append("\n\n");
}
value.append(Italic(u"id: "_q));
const auto raw = peer->id.value & PeerId::kChatTypeMask;
value.append(Link(
Italic(Lang::FormatCountDecimal(raw)),
"internal:~peer_id~:copy:" + QString::number(raw)));
}
if (ShowChannelJoinedBelowAbout.value()) {
if (const auto channel = peer->asChannel()) {
if (!channel->amCreator() && channel->inviteDate) {
if (!value.empty()) {
if (ShowPeerIdBelowAbout.value()) {
value.append("\n");
} else {
value.append("\n\n");
}
value.append("\n\n");
}
using namespace Ui::Text;
value.append((channel->isMegagroup()
@@ -50,6 +50,11 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include <QtCore/QJsonDocument>
#include <QtGui/QGuiApplication>
// AyuGram includes
#include "ayu/ui/settings/settings_main.h"
#include "settings/settings_builder.h"
namespace Settings {
namespace {
@@ -60,6 +65,11 @@ struct DecodeOptionsResult {
QString json;
};
struct ResolvedReferrer {
QString controlId;
Type section = AyuMain::Id();
};
[[nodiscard]] QString EncodeOptionsToText(const QString &json) {
const auto flags = QByteArray::Base64UrlEncoding
| QByteArray::OmitTrailingEquals;
@@ -96,8 +106,52 @@ struct DecodeOptionsResult {
return result;
}
[[nodiscard]] ResolvedReferrer ResolveReferrer(
const QString &controlId,
not_null<Main::Session*> session) {
const auto &registry = Builder::SearchRegistry::Instance();
const auto entries = registry.collectAll(session);
for (const auto &entry : entries) {
if (!entry.section) {
continue;
}
if (entry.id == controlId) {
return {
.controlId = entry.id,
.section = entry.section,
};
}
if (entry.altIds.contains(controlId)) {
return {
.controlId = entry.id,
.section = entry.section,
};
}
}
return {
.controlId = controlId,
};
}
[[nodiscard]] QString OptionReferrer(const base::options::option<bool> &option) {
const auto &id = option.id();
if (id == u"tabbed-panel-show-on-click"_q) {
return u"ayu/showEmojiPopup"_q;
} else if (id == u"show-peer-id-below-about"_q) {
return u"ayu/showPeerId"_q;
} else if (id == u"use-small-msg-bubble-radius"_q) {
return u"ayu/messageBubbleRadius"_q;
} else if (id == u"unlimited-recent-stickers"_q) {
return u"ayu/recentStickersCount"_q;
} else if (id == u"hide-ai-button"_q) {
return u"ayu/showAiEditorButtonInMessageField"_q;
}
return QString();
}
void AddOption(
not_null<Window::Controller*> window,
not_null<Window::SessionController*> controller,
not_null<Ui::VerticalLayout*> container,
base::options::option<bool> &option,
rpl::producer<> resetClicks,
@@ -114,15 +168,34 @@ void AddOption(
toggles->fire_copy(option.value());
}, lifetime);
const auto button = container->add(object_ptr<Button>(
container,
rpl::single(name),
(option.relevant()
? st::settingsButtonNoIcon
: st::settingsOptionDisabled)
))->toggleOn(toggles->events_starting_with(option.value()));
const auto referrer = OptionReferrer(option);
Button *button = nullptr;
if (!referrer.isEmpty()) {
button = container->add(object_ptr<Button>(
container,
rpl::single(name),
st::settingsButtonNoIcon));
button->addClickHandler([=] {
const auto resolved = ResolveReferrer(
referrer,
&controller->session());
controller->setHighlightControlId(resolved.controlId);
controller->showSettings(resolved.section);
window->activate();
});
} else {
button = container->add(object_ptr<Button>(
container,
rpl::single(name),
(option.relevant()
? st::settingsButtonNoIcon
: st::settingsOptionDisabled)
))->toggleOn(toggles->events_starting_with(option.value()));
}
const auto restarter = (option.relevant() && option.restartRequired())
const auto restarter = (referrer.isEmpty()
&& option.relevant()
&& option.restartRequired())
? button->lifetime().make_state<base::Timer>()
: nullptr;
if (restarter) {
@@ -135,19 +208,21 @@ void AddOption(
}));
});
}
button->toggledChanges(
) | rpl::on_next([=, &option](bool toggled) {
if (!option.relevant() && toggled != option.defaultValue()) {
toggles->fire_copy(option.defaultValue());
window->showToast(
tr::lng_settings_experimental_irrelevant(tr::now));
return;
}
option.set(toggled);
if (restarter) {
restarter->callOnce(st::settingsButtonNoIcon.toggle.duration);
}
}, container->lifetime());
if (referrer.isEmpty()) {
button->toggledChanges(
) | rpl::on_next([=, &option](bool toggled) {
if (!option.relevant() && toggled != option.defaultValue()) {
toggles->fire_copy(option.defaultValue());
window->showToast(
tr::lng_settings_experimental_irrelevant(tr::now));
return;
}
option.set(toggled);
if (restarter) {
restarter->callOnce(st::settingsButtonNoIcon.toggle.duration);
}
}, container->lifetime());
}
const auto &description = option.description();
if (!description.isEmpty()) {
@@ -159,6 +234,7 @@ void AddOption(
void SetupExperimental(
not_null<Window::Controller*> window,
not_null<Window::SessionController*> controller,
not_null<Ui::VerticalLayout*> container,
rpl::producer<> reloadOptionsRequests) {
Ui::AddSkip(container, st::settingsCheckboxesSkip);
@@ -196,6 +272,7 @@ void SetupExperimental(
const auto addToggle = [&](const char name[]) {
AddOption(
window,
controller,
container,
base::options::lookup<bool>(name),
(reset
@@ -204,13 +281,13 @@ void SetupExperimental(
rpl::duplicate(reloadOptionsRequests));
};
// addToggle(ChatHelpers::kOptionTabbedPanelShowOnClick);
addToggle(ChatHelpers::kOptionTabbedPanelShowOnClick);
addToggle(Dialogs::kOptionForumHideChatsList);
addToggle(Dialogs::Ui::kOptionDialogsMuteIcon);
addToggle(Core::kOptionFractionalScalingEnabled);
addToggle(Core::kOptionHighDpiDownscale);
addToggle(Window::kOptionViewProfileInChatsListContextMenu);
// addToggle(Info::Profile::kOptionShowPeerIdBelowAbout);
addToggle(Info::Profile::kOptionShowPeerIdBelowAbout);
addToggle(Info::Profile::kOptionShowChannelJoinedBelowAbout);
addToggle(Ui::kOptionUseSmallMsgBubbleRadius);
addToggle(Media::Player::kOptionDisableAutoplayNext);
@@ -290,6 +367,7 @@ void Experimental::setupContent() {
SetupExperimental(
&controller()->window(),
controller(),
content,
_reloadOptionsRequests.events());
@@ -51,7 +51,6 @@ base::options::toggle UseSmallMsgBubbleRadius({
.id = kOptionUseSmallMsgBubbleRadius,
.name = "Use small message bubble radius",
.description = "Makes most message bubbles square-ish.",
.scope = static_cast<base::options::details::ScopeFlag>(0),
.restartRequired = true,
});
@@ -35,7 +35,7 @@ base::options::toggle HideAiButtonOption({
bool HasEnoughLinesForAi(
not_null<Main::Session*> session,
not_null<Ui::InputField*> field) {
if (!AyuSettings::getInstance().showCocoonAiButtonInMessageField()
if (!AyuSettings::getInstance().showAiEditorButtonInMessageField()
|| session->appConfig().aiComposeStyles().empty()) {
return false;
}
@@ -120,7 +120,7 @@ auto SetupCaptionAiButton(SetupCaptionAiButtonArgs &&args)
field->heightChanges() | rpl::to_empty,
field->changes() | rpl::to_empty,
field->shownValue() | rpl::to_empty,
AyuSettings::getInstance().showCocoonAiButtonInMessageFieldChanges()
AyuSettings::getInstance().showAiEditorButtonInMessageFieldChanges()
| rpl::to_empty
) | rpl::on_next([=] {
updateVisibility();