Use lib_webview implementation on Windows.
This commit is contained in:
parent
21228783da
commit
35610da750
|
@ -35,6 +35,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "styles/style_chat.h"
|
#include "styles/style_chat.h"
|
||||||
|
|
||||||
#include "webview/webview_embed.h"
|
#include "webview/webview_embed.h"
|
||||||
|
#include "webview/webview_interface.h"
|
||||||
|
#include "core/local_url_handlers.h"
|
||||||
#include "ui/widgets/window.h"
|
#include "ui/widgets/window.h"
|
||||||
#include "ui/toast/toast.h"
|
#include "ui/toast/toast.h"
|
||||||
#include <QJsonDocument>
|
#include <QJsonDocument>
|
||||||
|
@ -66,38 +68,42 @@ void GetPaymentForm(not_null<const HistoryItem*> msg) {
|
||||||
}, window->lifetime());
|
}, window->lifetime());
|
||||||
|
|
||||||
const auto body = window->body();
|
const auto body = window->body();
|
||||||
|
body->paintRequest(
|
||||||
|
) | rpl::start_with_next([=](QRect clip) {
|
||||||
|
QPainter(body).fillRect(clip, st::windowBg);
|
||||||
|
}, body->lifetime());
|
||||||
|
|
||||||
const auto webview = Ui::CreateChild<Webview::Window>(
|
const auto webview = Ui::CreateChild<Webview::Window>(
|
||||||
window,
|
window,
|
||||||
window);
|
window);
|
||||||
|
if (!webview->widget()) {
|
||||||
|
delete window;
|
||||||
|
Ui::show(Box<InformBox>(
|
||||||
|
tr::lng_payments_not_supported(tr::now)));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
body->geometryValue(
|
body->geometryValue(
|
||||||
) | rpl::start_with_next([=](QRect geometry) {
|
) | rpl::start_with_next([=](QRect geometry) {
|
||||||
webview->widget()->setGeometry(geometry);
|
webview->widget()->setGeometry(geometry);
|
||||||
}, body->lifetime());
|
}, body->lifetime());
|
||||||
|
|
||||||
webview->bind("buy_callback", [=](const QByteArray &result) {
|
webview->setMessageHandler([=](const QJsonDocument &message) {
|
||||||
auto error = QJsonParseError{ 0, QJsonParseError::NoError };
|
if (!message.isArray()) {
|
||||||
const auto typeAndArguments = QJsonDocument::fromJson(
|
|
||||||
result,
|
|
||||||
&error);
|
|
||||||
if (error.error != QJsonParseError::NoError) {
|
|
||||||
LOG(("Payments Error: "
|
LOG(("Payments Error: "
|
||||||
"Failed to parse buy_callback result, error: %1."
|
|
||||||
).arg(error.errorString()));
|
|
||||||
return;
|
|
||||||
} else if (!typeAndArguments.isArray()) {
|
|
||||||
LOG(("API Error: "
|
|
||||||
"Not an array received in buy_callback arguments."));
|
"Not an array received in buy_callback arguments."));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const auto list = typeAndArguments.array();
|
const auto list = message.array();
|
||||||
if (list.at(0).toString() != "payment_form_submit") {
|
if (list.at(0).toString() != "payment_form_submit") {
|
||||||
return;
|
return;
|
||||||
} else if (!list.at(1).isString()) {
|
} else if (!list.at(1).isString()) {
|
||||||
LOG(("API Error: "
|
LOG(("Payments Error: "
|
||||||
"Not a string received in buy_callback result."));
|
"Not a string received in buy_callback result."));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
auto error = QJsonParseError();
|
||||||
const auto document = QJsonDocument::fromJson(
|
const auto document = QJsonDocument::fromJson(
|
||||||
list.at(1).toString().toUtf8(),
|
list.at(1).toString().toUtf8(),
|
||||||
&error);
|
&error);
|
||||||
|
@ -107,7 +113,7 @@ void GetPaymentForm(not_null<const HistoryItem*> msg) {
|
||||||
).arg(error.errorString()));
|
).arg(error.errorString()));
|
||||||
return;
|
return;
|
||||||
} else if (!document.isObject()) {
|
} else if (!document.isObject()) {
|
||||||
LOG(("API Error: "
|
LOG(("Payments Error: "
|
||||||
"Not an object decoded in buy_callback result."));
|
"Not an object decoded in buy_callback result."));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -115,7 +121,7 @@ void GetPaymentForm(not_null<const HistoryItem*> msg) {
|
||||||
const auto title = root.value("title").toString();
|
const auto title = root.value("title").toString();
|
||||||
const auto credentials = root.value("credentials");
|
const auto credentials = root.value("credentials");
|
||||||
if (!credentials.isObject()) {
|
if (!credentials.isObject()) {
|
||||||
LOG(("API Error: "
|
LOG(("Payments Error: "
|
||||||
"Not an object received in payment credentials."));
|
"Not an object received in payment credentials."));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -145,15 +151,21 @@ void GetPaymentForm(not_null<const HistoryItem*> msg) {
|
||||||
}).send();
|
}).send();
|
||||||
});
|
});
|
||||||
|
|
||||||
webview->init("(function(){"
|
webview->setNavigationHandler([=](const QString &uri) {
|
||||||
"window.TelegramWebviewProxy = {"
|
if (Core::TryConvertUrlToLocal(uri) != uri) {
|
||||||
"postEvent: function(eventType, eventData) {"
|
window->deleteLater();
|
||||||
"if (window.buy_callback) {"
|
App::wnd()->activate();
|
||||||
"window.buy_callback(eventType, eventData);"
|
}
|
||||||
"}"
|
});
|
||||||
"}"
|
|
||||||
"};"
|
webview->init(R"(
|
||||||
"}());");
|
window.TelegramWebviewProxy = {
|
||||||
|
postEvent: function(eventType, eventData) {
|
||||||
|
if (window.external && window.external.invoke) {
|
||||||
|
window.external.invoke(JSON.stringify([eventType, eventData]));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};)");
|
||||||
|
|
||||||
const auto &data = result.c_payments_paymentForm();
|
const auto &data = result.c_payments_paymentForm();
|
||||||
webview->navigate(qs(data.vurl()));
|
webview->navigate(qs(data.vurl()));
|
||||||
|
@ -252,8 +264,12 @@ void activateBotCommand(
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
case ButtonType::Buy: {
|
case ButtonType::Buy: {
|
||||||
Api::GetPaymentForm(msg);
|
if (Webview::Supported()) {
|
||||||
//Ui::show(Box<InformBox>(tr::lng_payments_not_supported(tr::now)));
|
Api::GetPaymentForm(msg);
|
||||||
|
} else {
|
||||||
|
Ui::show(Box<InformBox>(
|
||||||
|
tr::lng_payments_not_supported(tr::now)));
|
||||||
|
}
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
case ButtonType::Url: {
|
case ButtonType::Url: {
|
||||||
|
|
|
@ -27,6 +27,7 @@ You will require **api_id** and **api_hash** to access the Telegram API servers.
|
||||||
* Download **CMake** installer from [https://cmake.org/download/](https://cmake.org/download/) and install to ***BuildPath*\\ThirdParty\\cmake**
|
* Download **CMake** installer from [https://cmake.org/download/](https://cmake.org/download/) and install to ***BuildPath*\\ThirdParty\\cmake**
|
||||||
* Download **Ninja** executable from [https://github.com/ninja-build/ninja/releases/download/v1.7.2/ninja-win.zip](https://github.com/ninja-build/ninja/releases/download/v1.7.2/ninja-win.zip) and unpack to ***BuildPath*\\ThirdParty\\Ninja**
|
* Download **Ninja** executable from [https://github.com/ninja-build/ninja/releases/download/v1.7.2/ninja-win.zip](https://github.com/ninja-build/ninja/releases/download/v1.7.2/ninja-win.zip) and unpack to ***BuildPath*\\ThirdParty\\Ninja**
|
||||||
* Download **Git** installer from [https://git-scm.com/download/win](https://git-scm.com/download/win) and install it.
|
* Download **Git** installer from [https://git-scm.com/download/win](https://git-scm.com/download/win) and install it.
|
||||||
|
* Download **NuGet** executable from [https://dist.nuget.org/win-x86-commandline/latest/nuget.exe](https://www.nuget.org/downloads) and put to ***BuildPath*\\ThirdParty\\NuGet**
|
||||||
|
|
||||||
Open **x64 Native Tools Command Prompt for VS 2019.bat**, go to ***BuildPath*** and run
|
Open **x64 Native Tools Command Prompt for VS 2019.bat**, go to ***BuildPath*** and run
|
||||||
|
|
||||||
|
@ -49,6 +50,7 @@ Add **GYP** and **Ninja** to your PATH:
|
||||||
* Press **Edit**
|
* Press **Edit**
|
||||||
* Add ***BuildPath*\\ThirdParty\\gyp** value
|
* Add ***BuildPath*\\ThirdParty\\gyp** value
|
||||||
* Add ***BuildPath*\\ThirdParty\\Ninja** value
|
* Add ***BuildPath*\\ThirdParty\\Ninja** value
|
||||||
|
* Add ***BuildPath*\\ThirdParty\\NuGet** value
|
||||||
|
|
||||||
## Clone source code and prepare libraries
|
## Clone source code and prepare libraries
|
||||||
|
|
||||||
|
|
|
@ -27,6 +27,7 @@ You will require **api_id** and **api_hash** to access the Telegram API servers.
|
||||||
* Download **CMake** installer from [https://cmake.org/download/](https://cmake.org/download/) and install to ***BuildPath*\\ThirdParty\\cmake**
|
* Download **CMake** installer from [https://cmake.org/download/](https://cmake.org/download/) and install to ***BuildPath*\\ThirdParty\\cmake**
|
||||||
* Download **Ninja** executable from [https://github.com/ninja-build/ninja/releases/download/v1.7.2/ninja-win.zip](https://github.com/ninja-build/ninja/releases/download/v1.7.2/ninja-win.zip) and unpack to ***BuildPath*\\ThirdParty\\Ninja**
|
* Download **Ninja** executable from [https://github.com/ninja-build/ninja/releases/download/v1.7.2/ninja-win.zip](https://github.com/ninja-build/ninja/releases/download/v1.7.2/ninja-win.zip) and unpack to ***BuildPath*\\ThirdParty\\Ninja**
|
||||||
* Download **Git** installer from [https://git-scm.com/download/win](https://git-scm.com/download/win) and install it.
|
* Download **Git** installer from [https://git-scm.com/download/win](https://git-scm.com/download/win) and install it.
|
||||||
|
* Download **NuGet** executable from [https://dist.nuget.org/win-x86-commandline/latest/nuget.exe](https://www.nuget.org/downloads) and put to ***BuildPath*\\ThirdParty\\NuGet**
|
||||||
|
|
||||||
Open **x86 Native Tools Command Prompt for VS 2019.bat**, go to ***BuildPath*** and run
|
Open **x86 Native Tools Command Prompt for VS 2019.bat**, go to ***BuildPath*** and run
|
||||||
|
|
||||||
|
@ -49,6 +50,7 @@ Add **GYP** and **Ninja** to your PATH:
|
||||||
* Press **Edit**
|
* Press **Edit**
|
||||||
* Add ***BuildPath*\\ThirdParty\\gyp** value
|
* Add ***BuildPath*\\ThirdParty\\gyp** value
|
||||||
* Add ***BuildPath*\\ThirdParty\\Ninja** value
|
* Add ***BuildPath*\\ThirdParty\\Ninja** value
|
||||||
|
* Add ***BuildPath*\\ThirdParty\\NuGet** value
|
||||||
|
|
||||||
## Clone source code and prepare libraries
|
## Clone source code and prepare libraries
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue