mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Better support for web_app_open_link.
This commit is contained in:
parent
be16a7725c
commit
b1dd3b2a19
2 changed files with 36 additions and 1 deletions
|
@ -33,6 +33,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
namespace Ui::BotWebView {
|
namespace Ui::BotWebView {
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
|
constexpr auto kProcessClickTimeout = crl::time(1000);
|
||||||
constexpr auto kProgressDuration = crl::time(200);
|
constexpr auto kProgressDuration = crl::time(200);
|
||||||
constexpr auto kProgressOpacity = 0.3;
|
constexpr auto kProgressOpacity = 0.3;
|
||||||
constexpr auto kLightnessThreshold = 128;
|
constexpr auto kLightnessThreshold = 128;
|
||||||
|
@ -86,6 +87,30 @@ constexpr auto kLightnessDelta = 32;
|
||||||
alpha);
|
alpha);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] QString EncodeForJs(const QString &text) {
|
||||||
|
auto result = QString();
|
||||||
|
for (auto ch = text.data(), e = ch + text.size(); ch != e; ++ch) {
|
||||||
|
const auto code = ch->unicode();
|
||||||
|
const auto hex = [&](int value) {
|
||||||
|
const auto v = value & 0x0F;
|
||||||
|
return QChar((v < 10) ? ('0' + v) : 'A' + (v - 10));
|
||||||
|
};
|
||||||
|
if (code >= 32 && code < 128) {
|
||||||
|
if (code == '\\' || code == '"' || code == '\'') {
|
||||||
|
result += QChar('\\');
|
||||||
|
}
|
||||||
|
result += *ch;
|
||||||
|
} else {
|
||||||
|
result += u"\\u"_q
|
||||||
|
+ hex(code >> 12)
|
||||||
|
+ hex(code >> 8)
|
||||||
|
+ hex(code >> 4)
|
||||||
|
+ hex(code);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
class Panel::Button final : public RippleButton {
|
class Panel::Button final : public RippleButton {
|
||||||
|
@ -667,7 +692,15 @@ void Panel::openExternalLink(const QJsonValue &value) {
|
||||||
_close();
|
_close();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
QDesktopServices::openUrl(url);
|
const auto now = crl::now();
|
||||||
|
if (_mainButtonLastClick
|
||||||
|
&& _mainButtonLastClick + kProcessClickTimeout >= now) {
|
||||||
|
_mainButtonLastClick = 0;
|
||||||
|
QDesktopServices::openUrl(url);
|
||||||
|
} else {
|
||||||
|
const auto string = EncodeForJs(url);
|
||||||
|
_webview->window.eval(("window.open(\"" + string + "\");").toUtf8());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Panel::openInvoice(const QJsonValue &value) {
|
void Panel::openInvoice(const QJsonValue &value) {
|
||||||
|
@ -747,6 +780,7 @@ void Panel::createMainButton() {
|
||||||
button->setClickedCallback([=] {
|
button->setClickedCallback([=] {
|
||||||
if (!button->isDisabled()) {
|
if (!button->isDisabled()) {
|
||||||
postEvent("main_button_pressed");
|
postEvent("main_button_pressed");
|
||||||
|
_mainButtonLastClick = crl::now();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
button->hide();
|
button->hide();
|
||||||
|
|
|
@ -97,6 +97,7 @@ private:
|
||||||
std::unique_ptr<RpWidget> _webviewBottom;
|
std::unique_ptr<RpWidget> _webviewBottom;
|
||||||
QPointer<QWidget> _webviewParent;
|
QPointer<QWidget> _webviewParent;
|
||||||
std::unique_ptr<Button> _mainButton;
|
std::unique_ptr<Button> _mainButton;
|
||||||
|
crl::time _mainButtonLastClick = 0;
|
||||||
std::unique_ptr<Progress> _progress;
|
std::unique_ptr<Progress> _progress;
|
||||||
rpl::event_stream<> _themeUpdateForced;
|
rpl::event_stream<> _themeUpdateForced;
|
||||||
rpl::lifetime _fgLifetime;
|
rpl::lifetime _fgLifetime;
|
||||||
|
|
Loading…
Add table
Reference in a new issue