Don't close webview after 'web_app_open_tg_link'.

This commit is contained in:
John Preston 2023-10-06 17:18:44 +04:00
parent e59a60b3b5
commit 7f9461820b
4 changed files with 10 additions and 7 deletions

View file

@ -555,14 +555,16 @@ Webview::ThemeParams AttachWebView::botThemeParams() {
return Window::Theme::WebViewParams(); return Window::Theme::WebViewParams();
} }
bool AttachWebView::botHandleLocalUri(QString uri) { bool AttachWebView::botHandleLocalUri(QString uri, bool keepOpen) {
const auto local = Core::TryConvertUrlToLocal(uri); const auto local = Core::TryConvertUrlToLocal(uri);
if (uri == local || Core::InternalPassportLink(local)) { if (uri == local || Core::InternalPassportLink(local)) {
return local.startsWith(u"tg://"_q); return local.startsWith(u"tg://"_q);
} else if (!local.startsWith(u"tg://"_q, Qt::CaseInsensitive)) { } else if (!local.startsWith(u"tg://"_q, Qt::CaseInsensitive)) {
return false; return false;
} }
botClose(); if (!keepOpen) {
botClose();
}
crl::on_main([=, shownUrl = _lastShownUrl] { crl::on_main([=, shownUrl = _lastShownUrl] {
const auto variant = QVariant::fromValue(ClickHandlerContext{ const auto variant = QVariant::fromValue(ClickHandlerContext{
.attachBotWebviewUrl = shownUrl, .attachBotWebviewUrl = shownUrl,

View file

@ -159,7 +159,7 @@ private:
Webview::ThemeParams botThemeParams() override; Webview::ThemeParams botThemeParams() override;
bool botHandleLocalUri(QString uri) override; bool botHandleLocalUri(QString uri, bool keepOpen) override;
void botHandleInvoice(QString slug) override; void botHandleInvoice(QString slug) override;
void botHandleMenuButton(Ui::BotWebView::MenuButton button) override; void botHandleMenuButton(Ui::BotWebView::MenuButton button) override;
void botSendData(QByteArray data) override; void botSendData(QByteArray data) override;

View file

@ -658,7 +658,7 @@ bool Panel::createWebview(const Webview::ThemeParams &params) {
}); });
raw->setNavigationStartHandler([=](const QString &uri, bool newWindow) { raw->setNavigationStartHandler([=](const QString &uri, bool newWindow) {
if (_delegate->botHandleLocalUri(uri)) { if (_delegate->botHandleLocalUri(uri, false)) {
return false; return false;
} else if (newWindow) { } else if (newWindow) {
return true; return true;
@ -743,16 +743,17 @@ void Panel::switchInlineQueryMessage(const QJsonObject &args) {
void Panel::openTgLink(const QJsonObject &args) { void Panel::openTgLink(const QJsonObject &args) {
if (args.isEmpty()) { if (args.isEmpty()) {
LOG(("BotWebView Error: Bad arguments in 'web_app_open_tg_link'."));
_delegate->botClose(); _delegate->botClose();
return; return;
} }
const auto path = args["path_full"].toString(); const auto path = args["path_full"].toString();
if (path.isEmpty()) { if (path.isEmpty()) {
LOG(("BotWebView Error: Bad 'path_full' in openTgLink.")); LOG(("BotWebView Error: Bad 'path_full' in 'web_app_open_tg_link'."));
_delegate->botClose(); _delegate->botClose();
return; return;
} }
_delegate->botHandleLocalUri("https://t.me" + path); _delegate->botHandleLocalUri("https://t.me" + path, true);
} }
void Panel::openExternalLink(const QJsonObject &args) { void Panel::openExternalLink(const QJsonObject &args) {

View file

@ -54,7 +54,7 @@ struct CustomMethodRequest {
class Delegate { class Delegate {
public: public:
virtual Webview::ThemeParams botThemeParams() = 0; virtual Webview::ThemeParams botThemeParams() = 0;
virtual bool botHandleLocalUri(QString uri) = 0; virtual bool botHandleLocalUri(QString uri, bool keepOpen) = 0;
virtual void botHandleInvoice(QString slug) = 0; virtual void botHandleInvoice(QString slug) = 0;
virtual void botHandleMenuButton(MenuButton button) = 0; virtual void botHandleMenuButton(MenuButton button) = 0;
virtual void botSendData(QByteArray data) = 0; virtual void botSendData(QByteArray data) = 0;