mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-16 06:07:06 +02:00
Handle new 'web_app_setup_settings_button' event.
This commit is contained in:
parent
926aae6847
commit
e59a60b3b5
5 changed files with 13 additions and 16 deletions
|
@ -24,5 +24,4 @@ struct BotAppData {
|
|||
|
||||
uint64 accessHash = 0;
|
||||
uint64 hash = 0;
|
||||
bool hasSettings = false;
|
||||
};
|
||||
|
|
|
@ -117,7 +117,6 @@ constexpr auto kRefreshBotsTimeout = 60 * 60 * crl::time(1000);
|
|||
.inMainMenu = data.is_show_in_side_menu(),
|
||||
.inAttachMenu = data.is_show_in_attach_menu(),
|
||||
.disclaimerRequired = data.is_side_menu_disclaimer_needed(),
|
||||
.hasSettings = data.is_has_settings(),
|
||||
.requestWriteAccess = data.is_request_write_access(),
|
||||
} : std::optional<AttachWebViewBot>();
|
||||
});
|
||||
|
@ -1261,7 +1260,6 @@ void AttachWebView::requestApp(
|
|||
_bot->id,
|
||||
data.vapp());
|
||||
_app = received ? received : already;
|
||||
_app->hasSettings = data.is_has_settings();
|
||||
if (!_app) {
|
||||
cancel();
|
||||
showToast(tr::lng_username_app_not_found(tr::now));
|
||||
|
@ -1433,19 +1431,13 @@ void AttachWebView::show(
|
|||
_attachBots,
|
||||
not_null{ _bot },
|
||||
&AttachWebViewBot::user);
|
||||
const auto hasSettings = app
|
||||
? app->hasSettings
|
||||
: ((attached != end(_attachBots))
|
||||
&& !attached->inactive
|
||||
&& attached->hasSettings);
|
||||
const auto hasOpenBot = !_context
|
||||
|| (_bot != _context->action.history->peer)
|
||||
|| fromMainMenu;
|
||||
const auto hasRemoveFromMenu = !app
|
||||
&& (attached != end(_attachBots))
|
||||
&& (!attached->inactive || attached->inMainMenu);
|
||||
const auto buttons = (hasSettings ? Button::Settings : Button::None)
|
||||
| (hasOpenBot ? Button::OpenBot : Button::None)
|
||||
const auto buttons = (hasOpenBot ? Button::OpenBot : Button::None)
|
||||
| (!hasRemoveFromMenu
|
||||
? Button::None
|
||||
: attached->inMainMenu
|
||||
|
|
|
@ -66,7 +66,6 @@ struct AttachWebViewBot {
|
|||
bool inMainMenu : 1 = false;
|
||||
bool inAttachMenu : 1 = false;
|
||||
bool disclaimerRequired : 1 = false;
|
||||
bool hasSettings : 1 = false;
|
||||
bool requestWriteAccess : 1 = false;
|
||||
};
|
||||
|
||||
|
|
|
@ -522,7 +522,7 @@ bool Panel::showWebview(
|
|||
_webviewBottom->resize(_webviewBottom->width(), height);
|
||||
}
|
||||
_widget->setMenuAllowed([=](const Ui::Menu::MenuCallback &callback) {
|
||||
if (_menuButtons & MenuButton::Settings) {
|
||||
if (_hasSettingsButton) {
|
||||
callback(tr::lng_bot_settings(tr::now), [=] {
|
||||
postEvent("settings_button_pressed");
|
||||
}, &st::menuIconSettings);
|
||||
|
@ -628,6 +628,8 @@ bool Panel::createWebview(const Webview::ThemeParams ¶ms) {
|
|||
processMainButtonMessage(arguments);
|
||||
} else if (command == "web_app_setup_back_button") {
|
||||
processBackButtonMessage(arguments);
|
||||
} else if (command == "web_app_setup_settings_button") {
|
||||
processSettingsButtonMessage(arguments);
|
||||
} else if (command == "web_app_request_theme") {
|
||||
_themeUpdateForced.fire({});
|
||||
} else if (command == "web_app_request_viewport") {
|
||||
|
@ -1104,6 +1106,10 @@ void Panel::processBackButtonMessage(const QJsonObject &args) {
|
|||
_widget->setBackAllowed(args["is_visible"].toBool());
|
||||
}
|
||||
|
||||
void Panel::processSettingsButtonMessage(const QJsonObject &args) {
|
||||
_hasSettingsButton = args["is_visible"].toBool();
|
||||
}
|
||||
|
||||
void Panel::processHeaderColor(const QJsonObject &args) {
|
||||
if (const auto color = ParseColor(args["color"].toString())) {
|
||||
_widget->overrideTitleColor(color);
|
||||
|
|
|
@ -37,10 +37,9 @@ struct MainButtonArgs {
|
|||
|
||||
enum class MenuButton {
|
||||
None = 0x00,
|
||||
Settings = 0x01,
|
||||
OpenBot = 0x02,
|
||||
RemoveFromMenu = 0x04,
|
||||
RemoveFromMainMenu = 0x08,
|
||||
OpenBot = 0x01,
|
||||
RemoveFromMenu = 0x02,
|
||||
RemoveFromMainMenu = 0x04,
|
||||
};
|
||||
inline constexpr bool is_flag_type(MenuButton) { return true; }
|
||||
using MenuButtons = base::flags<MenuButton>;
|
||||
|
@ -114,6 +113,7 @@ private:
|
|||
void switchInlineQueryMessage(const QJsonObject &args);
|
||||
void processMainButtonMessage(const QJsonObject &args);
|
||||
void processBackButtonMessage(const QJsonObject &args);
|
||||
void processSettingsButtonMessage(const QJsonObject &args);
|
||||
void processHeaderColor(const QJsonObject &args);
|
||||
void openTgLink(const QJsonObject &args);
|
||||
void openExternalLink(const QJsonObject &args);
|
||||
|
@ -145,6 +145,7 @@ private:
|
|||
QString _userDataPath;
|
||||
const not_null<Delegate*> _delegate;
|
||||
bool _closeNeedConfirmation = false;
|
||||
bool _hasSettingsButton = false;
|
||||
MenuButtons _menuButtons = {};
|
||||
std::unique_ptr<SeparatePanel> _widget;
|
||||
std::unique_ptr<WebviewWithLifetime> _webview;
|
||||
|
|
Loading…
Add table
Reference in a new issue