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