feat: webview settings

This commit is contained in:
AlexeyZavar 2024-07-01 22:47:39 +03:00
parent dbb234097c
commit 27d3721646
7 changed files with 119 additions and 9 deletions

View file

@ -5472,6 +5472,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
"ayu_ContextMenuElementsHeader" = "Context Menu Elements"; "ayu_ContextMenuElementsHeader" = "Context Menu Elements";
"ayu_DrawerElementsHeader" = "Drawer Elements"; "ayu_DrawerElementsHeader" = "Drawer Elements";
"ayu_TrayElementsHeader" = "Tray Elements"; "ayu_TrayElementsHeader" = "Tray Elements";
"ayu_SettingsSpoofWebviewAsAndroid" = "Spoof Client as Android";
"ayu_SettingsBiggerWindow" = "Bigger Window";
"ayu_SettingsIncreaseWebviewHeight" = "Increase Content Height";
"ayu_SettingsIncreaseWebviewWidth" = "Increase Content Width";
"ayu_ExportDataTitle" = "Export AyuGram Database?"; "ayu_ExportDataTitle" = "Export AyuGram Database?";
"ayu_ExportDataDescription" = "It will be exported to the public folder, to Saved Attachments."; "ayu_ExportDataDescription" = "It will be exported to the public folder, to Saved Attachments.";
"ayu_ExportDataConfirm" = "Yes, export"; "ayu_ExportDataConfirm" = "Yes, export";
@ -5667,10 +5671,12 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
"ayu_MessageShotShowReactions" = "Show reactions"; "ayu_MessageShotShowReactions" = "Show reactions";
"ayu_MessageShotShowColorfulReplies" = "Show colorful replies"; "ayu_MessageShotShowColorfulReplies" = "Show colorful replies";
"ayu_SendAsSticker" = "Send as Sticker"; "ayu_SendAsSticker" = "Send as Sticker";
"ayu_AyuForwardStatusForwarding" = "Forwarding messages…"; "ayu_AyuForwardStatusPreparing" = "Forwarding messages";
"ayu_AyuForwardStatusLoadingMedia" = "Loading media…"; "ayu_AyuForwardStatusLoadingMedia" = "Loading media";
"ayu_AyuForwardForwardingDescription" = "Please keep this window open while AyuGram is forwarding your messages."; "ayu_AyuForwardStatusForwarding" = "Forwarding messages";
"ayu_AyuForwardLoadingMediaDescription" = "Please keep this window open while AyuGram is downloading media from your messages."; "ayu_AyuForwardStatusFinished" = "Done";
"ayu_AyuForwardStatusSentCount" = "sent %1$d of %2$d";
"ayu_AyuForwardStatusChunkCount" = "chunk %1$d of %2$d";
"ayu_ExpireMediaContextMenuText" = "Burn"; "ayu_ExpireMediaContextMenuText" = "Burn";
"ayu_ExpiringVoiceMessageNote" = "This voice message can be played as many times as you want."; "ayu_ExpiringVoiceMessageNote" = "This voice message can be played as many times as you want.";
"ayu_ExpiringVideoMessageNote" = "This video message can be played as many times as you want."; "ayu_ExpiringVideoMessageNote" = "This video message can be played as many times as you want.";

View file

@ -214,6 +214,10 @@ AyuGramSettings::AyuGramSettings() {
collapseSimilarChannels = true; collapseSimilarChannels = true;
hideSimilarChannels = false; hideSimilarChannels = false;
spoofWebviewAsAndroid = false;
increaseWebviewHeight = false;
increaseWebviewWidth = false;
disableNotificationsDelay = false; disableNotificationsDelay = false;
localPremium = false; localPremium = false;
@ -341,6 +345,18 @@ void AyuGramSettings::set_hideSimilarChannels(bool val) {
hideSimilarChannels = val; hideSimilarChannels = val;
} }
void AyuGramSettings::set_spoofWebviewAsAndroid(bool val) {
spoofWebviewAsAndroid = val;
}
void AyuGramSettings::set_increaseWebviewHeight(bool val) {
increaseWebviewHeight = val;
}
void AyuGramSettings::set_increaseWebviewWidth(bool val) {
increaseWebviewWidth = val;
}
void AyuGramSettings::set_disableNotificationsDelay(bool val) { void AyuGramSettings::set_disableNotificationsDelay(bool val) {
disableNotificationsDelay = val; disableNotificationsDelay = val;
} }

View file

@ -37,6 +37,10 @@ public:
bool collapseSimilarChannels; bool collapseSimilarChannels;
bool hideSimilarChannels; bool hideSimilarChannels;
bool spoofWebviewAsAndroid;
bool increaseWebviewHeight;
bool increaseWebviewWidth;
bool disableNotificationsDelay; bool disableNotificationsDelay;
bool localPremium; bool localPremium;
@ -95,6 +99,10 @@ public:
void set_collapseSimilarChannels(bool val); void set_collapseSimilarChannels(bool val);
void set_hideSimilarChannels(bool val); void set_hideSimilarChannels(bool val);
void set_spoofWebviewAsAndroid(bool val);
void set_increaseWebviewHeight(bool val);
void set_increaseWebviewWidth(bool val);
void set_disableNotificationsDelay(bool val); void set_disableNotificationsDelay(bool val);
void set_localPremium(bool val); void set_localPremium(bool val);
@ -149,6 +157,9 @@ NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT(
disableCustomBackgrounds, disableCustomBackgrounds,
collapseSimilarChannels, collapseSimilarChannels,
hideSimilarChannels, hideSimilarChannels,
spoofWebviewAsAndroid,
increaseWebviewHeight,
increaseWebviewWidth,
disableNotificationsDelay, disableNotificationsDelay,
localPremium, localPremium,
appIcon, appIcon,

View file

@ -27,6 +27,9 @@ recentStickersLimitPadding: margins(22px, 4px, 22px, 8px);
imageViewPadding: margins(22px, 10px, 22px, 10px); imageViewPadding: margins(22px, 10px, 22px, 10px);
imageViewInnerPadding: margins(16px, 16px, 16px, 16px); imageViewInnerPadding: margins(16px, 16px, 16px, 16px);
botWebViewPanelHeightIncreased: 782px;
botWebViewPanelWidthIncreased: 512px;
stickerRoundingSize: 5px; stickerRoundingSize: 5px;
messageShotPadding: 4px; messageShotPadding: 4px;

View file

@ -1249,6 +1249,50 @@ void SetupNerdSettings(not_null<Ui::VerticalLayout*> container, not_null<Window:
container->lifetime()); container->lifetime());
} }
void SetupWebviewSettings(not_null<Ui::VerticalLayout*> container) {
auto settings = &AyuSettings::getInstance();
AddSubsectionTitle(container, rpl::single(QString("Webview")));
AddButtonWithIcon(
container,
tr::ayu_SettingsSpoofWebviewAsAndroid(),
st::settingsButtonNoIcon
)->toggleOn(
rpl::single(settings->spoofWebviewAsAndroid)
)->toggledValue(
) | rpl::filter(
[=](bool enabled)
{
return (enabled != settings->spoofWebviewAsAndroid);
}) | start_with_next(
[=](bool enabled)
{
settings->set_spoofWebviewAsAndroid(enabled);
AyuSettings::save();
},
container->lifetime());
std::vector checkboxes = {
NestedEntry{
tr::ayu_SettingsIncreaseWebviewHeight(tr::now), settings->increaseWebviewHeight, [=](bool enabled)
{
settings->set_increaseWebviewHeight(enabled);
AyuSettings::save();
}
},
NestedEntry{
tr::ayu_SettingsIncreaseWebviewWidth(tr::now), settings->increaseWebviewWidth, [=](bool enabled)
{
settings->set_increaseWebviewWidth(enabled);
AyuSettings::save();
}
}
};
AddCollapsibleToggle(container, tr::ayu_SettingsBiggerWindow(), checkboxes, false);
}
void SetupCustomization(not_null<Ui::VerticalLayout*> container, void SetupCustomization(not_null<Ui::VerticalLayout*> container,
not_null<Window::SessionController*> controller) { not_null<Window::SessionController*> controller) {
AddSubsectionTitle(container, tr::ayu_CustomizationHeader()); AddSubsectionTitle(container, tr::ayu_CustomizationHeader());
@ -1318,6 +1362,12 @@ void SetupAyuGramSettings(not_null<Ui::VerticalLayout*> container,
AddSkip(container); AddSkip(container);
AddDividerText(container, tr::ayu_SettingsCustomizationHint()); AddDividerText(container, tr::ayu_SettingsCustomizationHint());
AddSkip(container);
SetupWebviewSettings(container);
AddSkip(container);
AddDivider(container);
AddSkip(container); AddSkip(container);
SetupSendConfirmations(container); SetupSendConfirmations(container);
AddSkip(container); AddSkip(container);

View file

@ -59,6 +59,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include <QSvgRenderer> #include <QSvgRenderer>
// AyuGram includes
#include "ayu/ayu_settings.h"
namespace InlineBots { namespace InlineBots {
namespace { namespace {
@ -431,6 +435,11 @@ void BotAction::handleKeyPress(not_null<QKeyEvent*> e) {
} }
} }
QString WebviewPlatform() {
const auto settings = &AyuSettings::getInstance();
return settings->spoofWebviewAsAndroid ? "android" : "tdesktop";
}
} // namespace } // namespace
MenuBotIcon::MenuBotIcon( MenuBotIcon::MenuBotIcon(
@ -901,7 +910,7 @@ void AttachWebView::request(const WebViewButton &button) {
MTP_bytes(button.url), MTP_bytes(button.url),
MTP_string(_startCommand), MTP_string(_startCommand),
MTP_dataJSON(MTP_bytes(Window::Theme::WebViewParams().json)), MTP_dataJSON(MTP_bytes(Window::Theme::WebViewParams().json)),
MTP_string("tdesktop"), MTP_string(WebviewPlatform()),
action.mtpReplyTo(), action.mtpReplyTo(),
(action.options.sendAs (action.options.sendAs
? action.options.sendAs->input ? action.options.sendAs->input
@ -1222,7 +1231,7 @@ void AttachWebView::requestSimple(const WebViewButton &button) {
MTP_bytes(button.url), MTP_bytes(button.url),
MTP_string(button.startCommand), MTP_string(button.startCommand),
MTP_dataJSON(MTP_bytes(Window::Theme::WebViewParams().json)), MTP_dataJSON(MTP_bytes(Window::Theme::WebViewParams().json)),
MTP_string("tdesktop") MTP_string(WebviewPlatform())
)).done([=](const MTPWebViewResult &result) { )).done([=](const MTPWebViewResult &result) {
_requestId = 0; _requestId = 0;
const auto &data = result.data(); const auto &data = result.data();
@ -1300,7 +1309,7 @@ void AttachWebView::requestMenu(
MTP_string(url), MTP_string(url),
MTPstring(), // start_param MTPstring(), // start_param
MTP_dataJSON(MTP_bytes(Window::Theme::WebViewParams().json)), MTP_dataJSON(MTP_bytes(Window::Theme::WebViewParams().json)),
MTP_string("tdesktop"), MTP_string(WebviewPlatform()),
action.mtpReplyTo(), action.mtpReplyTo(),
(action.options.sendAs (action.options.sendAs
? action.options.sendAs->input ? action.options.sendAs->input
@ -1430,7 +1439,7 @@ void AttachWebView::requestAppView(bool allowWrite) {
MTP_inputBotAppID(MTP_long(app->id), MTP_long(app->accessHash)), MTP_inputBotAppID(MTP_long(app->id), MTP_long(app->accessHash)),
MTP_string(_startCommand), MTP_string(_startCommand),
MTP_dataJSON(MTP_bytes(Window::Theme::WebViewParams().json)), MTP_dataJSON(MTP_bytes(Window::Theme::WebViewParams().json)),
MTP_string("tdesktop") MTP_string(WebviewPlatform())
)).done([=](const MTPWebViewResult &result) { )).done([=](const MTPWebViewResult &result) {
_requestId = 0; _requestId = 0;
const auto &data = result.data(); const auto &data = result.data();

View file

@ -35,6 +35,11 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include <QtGui/QGuiApplication> #include <QtGui/QGuiApplication>
#include <QtGui/QClipboard> #include <QtGui/QClipboard>
// AyuGram includes
#include "ayu/ayu_settings.h"
#include "styles/style_ayu_styles.h"
namespace Ui::BotWebView { namespace Ui::BotWebView {
namespace { namespace {
@ -324,7 +329,17 @@ Panel::Panel(
, _widget(std::make_unique<SeparatePanel>()) , _widget(std::make_unique<SeparatePanel>())
, _allowClipboardRead(allowClipboardRead) { , _allowClipboardRead(allowClipboardRead) {
_widget->setWindowFlag(Qt::WindowStaysOnTopHint, false); _widget->setWindowFlag(Qt::WindowStaysOnTopHint, false);
_widget->setInnerSize(st::botWebViewPanelSize);
const auto settings = &AyuSettings::getInstance();
auto size = QSize(st::botWebViewPanelSize);
if (settings->increaseWebviewHeight) {
size.setHeight(st::botWebViewPanelHeightIncreased);
}
if (settings->increaseWebviewWidth) {
size.setWidth(st::botWebViewPanelWidthIncreased);
}
_widget->setInnerSize(size);
_widget->closeRequests( _widget->closeRequests(
) | rpl::start_with_next([=] { ) | rpl::start_with_next([=] {