From 9f7ee3cafdc467da75286d9519bbdb75b7ab1e09 Mon Sep 17 00:00:00 2001 From: John Preston Date: Fri, 16 Feb 2024 12:13:41 +0400 Subject: [PATCH] Correctly check webview init success. Also correctly init recreated webview bottom bar. Fixes #27481, fixes #27479. --- .../ui/chat/attach/attach_bot_webview.cpp | 61 +++++++++++-------- .../ui/chat/attach/attach_bot_webview.h | 2 + 2 files changed, 36 insertions(+), 27 deletions(-) diff --git a/Telegram/SourceFiles/ui/chat/attach/attach_bot_webview.cpp b/Telegram/SourceFiles/ui/chat/attach/attach_bot_webview.cpp index ab84a81cd0..ed57fdf2bd 100644 --- a/Telegram/SourceFiles/ui/chat/attach/attach_bot_webview.cpp +++ b/Telegram/SourceFiles/ui/chat/attach/attach_bot_webview.cpp @@ -494,6 +494,7 @@ bool Panel::showWebview( const QString &url, const Webview::ThemeParams ¶ms, rpl::producer bottomText) { + _bottomText = std::move(bottomText); if (!_webview && !createWebview(params)) { return false; } @@ -503,24 +504,6 @@ bool Panel::showWebview( updateThemeParams(params); _webview->window.navigate(url); _widget->setBackAllowed(allowBack); - if (bottomText) { - const auto &padding = st::paymentsPanelPadding; - const auto label = CreateChild( - _webviewBottom.get(), - std::move(bottomText), - st::paymentsWebviewBottom); - const auto height = padding.top() - + label->heightNoMargins() - + padding.bottom(); - rpl::combine( - _webviewBottom->widthValue(), - label->widthValue() - ) | rpl::start_with_next([=](int outerWidth, int width) { - label->move((outerWidth - width) / 2, padding.top()); - }, label->lifetime()); - label->show(); - _webviewBottom->resize(_webviewBottom->width(), height); - } _widget->setMenuAllowed([=](const Ui::Menu::MenuCallback &callback) { if (_hasSettingsButton) { callback(tr::lng_bot_settings(tr::now), [=] { @@ -533,7 +516,7 @@ bool Panel::showWebview( }, &st::menuIconLeave); } callback(tr::lng_bot_reload_page(tr::now), [=] { - if (_webview) { + if (_webview && _webview->window.widget()) { _webview->window.reload(); } else if (const auto params = _delegate->botThemeParams() ; createWebview(params)) { @@ -562,16 +545,28 @@ bool Panel::showWebview( return true; } -bool Panel::createWebview(const Webview::ThemeParams ¶ms) { - auto outer = base::make_unique_q(_widget.get()); - const auto container = outer.get(); - _widget->showInner(std::move(outer)); - _webviewParent = container; - +void Panel::createWebviewBottom() { _webviewBottom = std::make_unique(_widget.get()); const auto bottom = _webviewBottom.get(); bottom->show(); + const auto &padding = st::paymentsPanelPadding; + const auto label = CreateChild( + _webviewBottom.get(), + _bottomText.value(), + st::paymentsWebviewBottom); + const auto height = padding.top() + + label->heightNoMargins() + + padding.bottom(); + rpl::combine( + _webviewBottom->widthValue(), + label->widthValue() + ) | rpl::start_with_next([=](int outerWidth, int width) { + label->move((outerWidth - width) / 2, padding.top()); + }, label->lifetime()); + label->show(); + _webviewBottom->resize(_webviewBottom->width(), height); + bottom->heightValue( ) | rpl::start_with_next([=](int height) { const auto inner = _widget->innerGeometry(); @@ -579,11 +574,22 @@ bool Panel::createWebview(const Webview::ThemeParams ¶ms) { height = _mainButton->height(); } bottom->move(inner.x(), inner.y() + inner.height() - height); - container->setFixedSize(inner.width(), inner.height() - height); + if (const auto container = _webviewParent.data()) { + container->setFixedSize(inner.width(), inner.height() - height); + } bottom->resizeToWidth(inner.width()); }, bottom->lifetime()); - container->show(); +} +bool Panel::createWebview(const Webview::ThemeParams ¶ms) { + auto outer = base::make_unique_q(_widget.get()); + const auto container = outer.get(); + _widget->showInner(std::move(outer)); + _webviewParent = container; + + createWebviewBottom(); + + container->show(); _webview = std::make_unique( container, Webview::WindowConfig{ @@ -592,6 +598,7 @@ bool Panel::createWebview(const Webview::ThemeParams ¶ms) { }); const auto raw = &_webview->window; + const auto bottom = _webviewBottom.get(); QObject::connect(container, &QObject::destroyed, [=] { if (_webview && &_webview->window == raw) { base::take(_webview); diff --git a/Telegram/SourceFiles/ui/chat/attach/attach_bot_webview.h b/Telegram/SourceFiles/ui/chat/attach/attach_bot_webview.h index 20a9a4f720..9c4be46d04 100644 --- a/Telegram/SourceFiles/ui/chat/attach/attach_bot_webview.h +++ b/Telegram/SourceFiles/ui/chat/attach/attach_bot_webview.h @@ -106,6 +106,7 @@ private: struct WebviewWithLifetime; bool createWebview(const Webview::ThemeParams ¶ms); + void createWebviewBottom(); void showWebviewProgress(); void hideWebviewProgress(); void setTitle(rpl::producer title); @@ -150,6 +151,7 @@ private: std::unique_ptr _widget; std::unique_ptr _webview; std::unique_ptr _webviewBottom; + rpl::variable _bottomText; QPointer _webviewParent; std::unique_ptr