Correctly check webview init success.

Also correctly init recreated webview bottom bar.

Fixes #27481, fixes #27479.
This commit is contained in:
John Preston 2024-02-16 12:13:41 +04:00
parent 137155afd8
commit 9f7ee3cafd
2 changed files with 36 additions and 27 deletions

View File

@ -494,6 +494,7 @@ bool Panel::showWebview(
const QString &url,
const Webview::ThemeParams &params,
rpl::producer<QString> 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<FlatLabel>(
_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 &params) {
auto outer = base::make_unique_q<RpWidget>(_widget.get());
const auto container = outer.get();
_widget->showInner(std::move(outer));
_webviewParent = container;
void Panel::createWebviewBottom() {
_webviewBottom = std::make_unique<RpWidget>(_widget.get());
const auto bottom = _webviewBottom.get();
bottom->show();
const auto &padding = st::paymentsPanelPadding;
const auto label = CreateChild<FlatLabel>(
_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 &params) {
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 &params) {
auto outer = base::make_unique_q<RpWidget>(_widget.get());
const auto container = outer.get();
_widget->showInner(std::move(outer));
_webviewParent = container;
createWebviewBottom();
container->show();
_webview = std::make_unique<WebviewWithLifetime>(
container,
Webview::WindowConfig{
@ -592,6 +598,7 @@ bool Panel::createWebview(const Webview::ThemeParams &params) {
});
const auto raw = &_webview->window;
const auto bottom = _webviewBottom.get();
QObject::connect(container, &QObject::destroyed, [=] {
if (_webview && &_webview->window == raw) {
base::take(_webview);

View File

@ -106,6 +106,7 @@ private:
struct WebviewWithLifetime;
bool createWebview(const Webview::ThemeParams &params);
void createWebviewBottom();
void showWebviewProgress();
void hideWebviewProgress();
void setTitle(rpl::producer<QString> title);
@ -150,6 +151,7 @@ private:
std::unique_ptr<SeparatePanel> _widget;
std::unique_ptr<WebviewWithLifetime> _webview;
std::unique_ptr<RpWidget> _webviewBottom;
rpl::variable<QString> _bottomText;
QPointer<QWidget> _webviewParent;
std::unique_ptr<Button> _mainButton;
mutable crl::time _mainButtonLastClick = 0;