mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Correctly check webview init success.
Also correctly init recreated webview bottom bar. Fixes #27481, fixes #27479.
This commit is contained in:
parent
137155afd8
commit
9f7ee3cafd
2 changed files with 36 additions and 27 deletions
|
@ -494,6 +494,7 @@ bool Panel::showWebview(
|
||||||
const QString &url,
|
const QString &url,
|
||||||
const Webview::ThemeParams ¶ms,
|
const Webview::ThemeParams ¶ms,
|
||||||
rpl::producer<QString> bottomText) {
|
rpl::producer<QString> bottomText) {
|
||||||
|
_bottomText = std::move(bottomText);
|
||||||
if (!_webview && !createWebview(params)) {
|
if (!_webview && !createWebview(params)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -503,24 +504,6 @@ bool Panel::showWebview(
|
||||||
updateThemeParams(params);
|
updateThemeParams(params);
|
||||||
_webview->window.navigate(url);
|
_webview->window.navigate(url);
|
||||||
_widget->setBackAllowed(allowBack);
|
_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) {
|
_widget->setMenuAllowed([=](const Ui::Menu::MenuCallback &callback) {
|
||||||
if (_hasSettingsButton) {
|
if (_hasSettingsButton) {
|
||||||
callback(tr::lng_bot_settings(tr::now), [=] {
|
callback(tr::lng_bot_settings(tr::now), [=] {
|
||||||
|
@ -533,7 +516,7 @@ bool Panel::showWebview(
|
||||||
}, &st::menuIconLeave);
|
}, &st::menuIconLeave);
|
||||||
}
|
}
|
||||||
callback(tr::lng_bot_reload_page(tr::now), [=] {
|
callback(tr::lng_bot_reload_page(tr::now), [=] {
|
||||||
if (_webview) {
|
if (_webview && _webview->window.widget()) {
|
||||||
_webview->window.reload();
|
_webview->window.reload();
|
||||||
} else if (const auto params = _delegate->botThemeParams()
|
} else if (const auto params = _delegate->botThemeParams()
|
||||||
; createWebview(params)) {
|
; createWebview(params)) {
|
||||||
|
@ -562,16 +545,28 @@ bool Panel::showWebview(
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Panel::createWebview(const Webview::ThemeParams ¶ms) {
|
void Panel::createWebviewBottom() {
|
||||||
auto outer = base::make_unique_q<RpWidget>(_widget.get());
|
|
||||||
const auto container = outer.get();
|
|
||||||
_widget->showInner(std::move(outer));
|
|
||||||
_webviewParent = container;
|
|
||||||
|
|
||||||
_webviewBottom = std::make_unique<RpWidget>(_widget.get());
|
_webviewBottom = std::make_unique<RpWidget>(_widget.get());
|
||||||
const auto bottom = _webviewBottom.get();
|
const auto bottom = _webviewBottom.get();
|
||||||
bottom->show();
|
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(
|
bottom->heightValue(
|
||||||
) | rpl::start_with_next([=](int height) {
|
) | rpl::start_with_next([=](int height) {
|
||||||
const auto inner = _widget->innerGeometry();
|
const auto inner = _widget->innerGeometry();
|
||||||
|
@ -579,11 +574,22 @@ bool Panel::createWebview(const Webview::ThemeParams ¶ms) {
|
||||||
height = _mainButton->height();
|
height = _mainButton->height();
|
||||||
}
|
}
|
||||||
bottom->move(inner.x(), inner.y() + inner.height() - 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->resizeToWidth(inner.width());
|
||||||
}, bottom->lifetime());
|
}, bottom->lifetime());
|
||||||
container->show();
|
}
|
||||||
|
|
||||||
|
bool Panel::createWebview(const Webview::ThemeParams ¶ms) {
|
||||||
|
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>(
|
_webview = std::make_unique<WebviewWithLifetime>(
|
||||||
container,
|
container,
|
||||||
Webview::WindowConfig{
|
Webview::WindowConfig{
|
||||||
|
@ -592,6 +598,7 @@ bool Panel::createWebview(const Webview::ThemeParams ¶ms) {
|
||||||
});
|
});
|
||||||
const auto raw = &_webview->window;
|
const auto raw = &_webview->window;
|
||||||
|
|
||||||
|
const auto bottom = _webviewBottom.get();
|
||||||
QObject::connect(container, &QObject::destroyed, [=] {
|
QObject::connect(container, &QObject::destroyed, [=] {
|
||||||
if (_webview && &_webview->window == raw) {
|
if (_webview && &_webview->window == raw) {
|
||||||
base::take(_webview);
|
base::take(_webview);
|
||||||
|
|
|
@ -106,6 +106,7 @@ private:
|
||||||
struct WebviewWithLifetime;
|
struct WebviewWithLifetime;
|
||||||
|
|
||||||
bool createWebview(const Webview::ThemeParams ¶ms);
|
bool createWebview(const Webview::ThemeParams ¶ms);
|
||||||
|
void createWebviewBottom();
|
||||||
void showWebviewProgress();
|
void showWebviewProgress();
|
||||||
void hideWebviewProgress();
|
void hideWebviewProgress();
|
||||||
void setTitle(rpl::producer<QString> title);
|
void setTitle(rpl::producer<QString> title);
|
||||||
|
@ -150,6 +151,7 @@ private:
|
||||||
std::unique_ptr<SeparatePanel> _widget;
|
std::unique_ptr<SeparatePanel> _widget;
|
||||||
std::unique_ptr<WebviewWithLifetime> _webview;
|
std::unique_ptr<WebviewWithLifetime> _webview;
|
||||||
std::unique_ptr<RpWidget> _webviewBottom;
|
std::unique_ptr<RpWidget> _webviewBottom;
|
||||||
|
rpl::variable<QString> _bottomText;
|
||||||
QPointer<QWidget> _webviewParent;
|
QPointer<QWidget> _webviewParent;
|
||||||
std::unique_ptr<Button> _mainButton;
|
std::unique_ptr<Button> _mainButton;
|
||||||
mutable crl::time _mainButtonLastClick = 0;
|
mutable crl::time _mainButtonLastClick = 0;
|
||||||
|
|
Loading…
Add table
Reference in a new issue