2022-03-25 14:13:30 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
|
|
|
the official desktop application for the Telegram messaging service.
|
|
|
|
|
|
|
|
For license and copyright information please follow this link:
|
|
|
|
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "base/object_ptr.h"
|
2022-05-11 14:55:04 +00:00
|
|
|
#include "base/weak_ptr.h"
|
2022-06-03 16:07:33 +00:00
|
|
|
#include "base/flags.h"
|
2022-03-25 14:13:30 +00:00
|
|
|
|
|
|
|
namespace Ui {
|
|
|
|
class BoxContent;
|
|
|
|
class RpWidget;
|
|
|
|
class SeparatePanel;
|
|
|
|
} // namespace Ui
|
|
|
|
|
|
|
|
namespace Webview {
|
|
|
|
struct Available;
|
2022-04-12 15:48:32 +00:00
|
|
|
struct ThemeParams;
|
2022-03-25 14:13:30 +00:00
|
|
|
} // namespace Webview
|
|
|
|
|
|
|
|
namespace Ui::BotWebView {
|
|
|
|
|
2022-04-04 11:28:38 +00:00
|
|
|
struct MainButtonArgs {
|
2022-04-07 12:16:43 +00:00
|
|
|
bool isActive = false;
|
2022-04-04 11:28:38 +00:00
|
|
|
bool isVisible = false;
|
|
|
|
bool isProgressVisible = false;
|
|
|
|
QString text;
|
|
|
|
};
|
|
|
|
|
2022-06-03 16:07:33 +00:00
|
|
|
enum class MenuButton {
|
|
|
|
None = 0x00,
|
|
|
|
Settings = 0x01,
|
|
|
|
OpenBot = 0x02,
|
|
|
|
RemoveFromMenu = 0x04,
|
|
|
|
};
|
|
|
|
inline constexpr bool is_flag_type(MenuButton) { return true; }
|
|
|
|
using MenuButtons = base::flags<MenuButton>;
|
|
|
|
|
2022-05-11 14:55:04 +00:00
|
|
|
class Panel final : public base::has_weak_ptr {
|
2022-03-25 14:13:30 +00:00
|
|
|
public:
|
2022-03-28 14:02:54 +00:00
|
|
|
Panel(
|
|
|
|
const QString &userDataPath,
|
2022-03-29 10:34:57 +00:00
|
|
|
rpl::producer<QString> title,
|
2022-04-05 17:14:59 +00:00
|
|
|
Fn<bool(QString)> handleLocalUri,
|
2022-05-11 14:55:04 +00:00
|
|
|
Fn<void(QString)> handleInvoice,
|
2022-03-28 14:02:54 +00:00
|
|
|
Fn<void(QByteArray)> sendData,
|
2022-03-28 20:14:10 +00:00
|
|
|
Fn<void()> close,
|
2022-06-03 16:07:33 +00:00
|
|
|
MenuButtons menuButtons,
|
|
|
|
Fn<void(MenuButton)> handleMenuButton,
|
2022-04-12 15:48:32 +00:00
|
|
|
Fn<Webview::ThemeParams()> themeParams);
|
2022-03-25 14:13:30 +00:00
|
|
|
~Panel();
|
|
|
|
|
|
|
|
void requestActivate();
|
|
|
|
void toggleProgress(bool shown);
|
|
|
|
|
|
|
|
bool showWebview(
|
|
|
|
const QString &url,
|
2022-04-12 15:48:32 +00:00
|
|
|
const Webview::ThemeParams ¶ms,
|
2022-03-25 14:13:30 +00:00
|
|
|
rpl::producer<QString> bottomText);
|
|
|
|
|
|
|
|
void showBox(object_ptr<BoxContent> box);
|
|
|
|
void showToast(const TextWithEntities &text);
|
|
|
|
void showCriticalError(const TextWithEntities &text);
|
2022-03-29 14:14:11 +00:00
|
|
|
void showWebviewError(
|
|
|
|
const QString &text,
|
|
|
|
const Webview::Available &information);
|
2022-03-25 14:13:30 +00:00
|
|
|
|
2022-04-12 15:48:32 +00:00
|
|
|
void updateThemeParams(const Webview::ThemeParams ¶ms);
|
2022-03-28 20:14:10 +00:00
|
|
|
|
2022-05-11 14:55:04 +00:00
|
|
|
void hideForPayment();
|
|
|
|
void invoiceClosed(const QString &slug, const QString &status);
|
|
|
|
|
2022-03-25 14:13:30 +00:00
|
|
|
[[nodiscard]] rpl::lifetime &lifetime();
|
|
|
|
|
|
|
|
private:
|
2022-04-04 11:28:38 +00:00
|
|
|
class Button;
|
2022-03-25 14:13:30 +00:00
|
|
|
struct Progress;
|
|
|
|
struct WebviewWithLifetime;
|
|
|
|
|
|
|
|
bool createWebview();
|
|
|
|
void showWebviewProgress();
|
|
|
|
void hideWebviewProgress();
|
|
|
|
void setTitle(rpl::producer<QString> title);
|
2022-04-04 11:28:38 +00:00
|
|
|
void sendDataMessage(const QJsonValue &value);
|
|
|
|
void processMainButtonMessage(const QJsonValue &value);
|
2022-05-20 16:03:54 +00:00
|
|
|
void processBackButtonMessage(const QJsonValue &value);
|
2022-05-11 14:55:04 +00:00
|
|
|
void openTgLink(const QJsonValue &value);
|
2022-05-20 16:03:54 +00:00
|
|
|
void openExternalLink(const QJsonValue &value);
|
2022-05-11 14:55:04 +00:00
|
|
|
void openInvoice(const QJsonValue &value);
|
2022-04-04 11:28:38 +00:00
|
|
|
void createMainButton();
|
|
|
|
|
|
|
|
void postEvent(const QString &event, const QString &data = {});
|
2022-03-25 14:13:30 +00:00
|
|
|
|
|
|
|
[[nodiscard]] bool progressWithBackground() const;
|
|
|
|
[[nodiscard]] QRect progressRect() const;
|
|
|
|
void setupProgressGeometry();
|
|
|
|
|
|
|
|
QString _userDataPath;
|
2022-04-05 17:14:59 +00:00
|
|
|
Fn<bool(QString)> _handleLocalUri;
|
2022-05-11 14:55:04 +00:00
|
|
|
Fn<void(QString)> _handleInvoice;
|
2022-03-28 14:02:54 +00:00
|
|
|
Fn<void(QByteArray)> _sendData;
|
2022-03-25 14:13:30 +00:00
|
|
|
Fn<void()> _close;
|
2022-06-03 16:07:33 +00:00
|
|
|
MenuButtons _menuButtons = {};
|
|
|
|
Fn<void(MenuButton)> _handleMenuButton;
|
2022-03-25 14:13:30 +00:00
|
|
|
std::unique_ptr<SeparatePanel> _widget;
|
|
|
|
std::unique_ptr<WebviewWithLifetime> _webview;
|
|
|
|
std::unique_ptr<RpWidget> _webviewBottom;
|
2022-04-04 11:28:38 +00:00
|
|
|
QPointer<QWidget> _webviewParent;
|
|
|
|
std::unique_ptr<Button> _mainButton;
|
2022-05-26 09:08:11 +00:00
|
|
|
crl::time _mainButtonLastClick = 0;
|
2022-03-25 14:13:30 +00:00
|
|
|
std::unique_ptr<Progress> _progress;
|
2022-04-21 06:47:21 +00:00
|
|
|
rpl::event_stream<> _themeUpdateForced;
|
2022-04-04 11:28:38 +00:00
|
|
|
rpl::lifetime _fgLifetime;
|
|
|
|
rpl::lifetime _bgLifetime;
|
2022-03-25 14:13:30 +00:00
|
|
|
bool _webviewProgress = false;
|
2022-03-28 20:14:10 +00:00
|
|
|
bool _themeUpdateScheduled = false;
|
2022-05-11 14:55:04 +00:00
|
|
|
bool _hiddenForPayment = false;
|
2022-03-25 14:13:30 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
struct Args {
|
|
|
|
QString url;
|
|
|
|
QString userDataPath;
|
2022-03-29 10:34:57 +00:00
|
|
|
rpl::producer<QString> title;
|
|
|
|
rpl::producer<QString> bottom;
|
2022-04-05 17:14:59 +00:00
|
|
|
Fn<bool(QString)> handleLocalUri;
|
2022-05-11 14:55:04 +00:00
|
|
|
Fn<void(QString)> handleInvoice;
|
2022-03-28 14:02:54 +00:00
|
|
|
Fn<void(QByteArray)> sendData;
|
2022-03-25 14:13:30 +00:00
|
|
|
Fn<void()> close;
|
2022-06-03 16:07:33 +00:00
|
|
|
MenuButtons menuButtons;
|
|
|
|
Fn<void(MenuButton)> handleMenuButton;
|
2022-04-12 15:48:32 +00:00
|
|
|
Fn<Webview::ThemeParams()> themeParams;
|
2022-03-25 14:13:30 +00:00
|
|
|
};
|
|
|
|
[[nodiscard]] std::unique_ptr<Panel> Show(Args &&args);
|
|
|
|
|
|
|
|
} // namespace Ui::BotWebView
|