Skip to content

Commit

Permalink
Handle webview crash
Browse files Browse the repository at this point in the history
  • Loading branch information
ilya-fedin authored and john-preston committed Dec 23, 2023
1 parent cb4fce2 commit d63ebbe
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 4 deletions.
9 changes: 8 additions & 1 deletion Telegram/SourceFiles/payments/ui/payments_panel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -567,10 +567,17 @@ bool Panel::createWebview(const Webview::ThemeParams &params) {
if (!raw->widget()) {
return false;
}
QObject::connect(raw->widget(), &QObject::destroyed, [=] {
crl::on_main(this, [=] {
showCriticalError({ "Error: WebView has crashed." });
});
});

container->geometryValue(
) | rpl::start_with_next([=](QRect geometry) {
raw->widget()->setGeometry(geometry);
if (raw->widget()) {
raw->widget()->setGeometry(geometry);
}
}, _webview->lifetime);

raw->setMessageHandler([=](const QJsonDocument &message) {
Expand Down
3 changes: 2 additions & 1 deletion Telegram/SourceFiles/payments/ui/payments_panel.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ For license and copyright information please follow this link:
#pragma once

#include "base/object_ptr.h"
#include "base/weak_ptr.h"

namespace Ui {
class Show;
Expand Down Expand Up @@ -39,7 +40,7 @@ struct PaymentMethodDetails;
struct PaymentMethodAdditional;
struct NativeMethodDetails;

class Panel final {
class Panel final : public base::has_weak_ptr {
public:
explicit Panel(not_null<PanelDelegate*> delegate);
~Panel();
Expand Down
9 changes: 8 additions & 1 deletion Telegram/SourceFiles/ui/chat/attach/attach_bot_webview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -603,10 +603,17 @@ bool Panel::createWebview(const Webview::ThemeParams &params) {
if (!raw->widget()) {
return false;
}
QObject::connect(raw->widget(), &QObject::destroyed, [=] {
crl::on_main(this, [=] {
showCriticalError({ "Error: WebView has crashed." });
});
});

container->geometryValue(
) | rpl::start_with_next([=](QRect geometry) {
raw->widget()->setGeometry(geometry);
if (raw->widget()) {
raw->widget()->setGeometry(geometry);
}
}, _webview->lifetime);

raw->setMessageHandler([=](const QJsonDocument &message) {
Expand Down
2 changes: 1 addition & 1 deletion Telegram/lib_webview

0 comments on commit d63ebbe

Please sign in to comment.