mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Fix miniapp downloads in fullscreen.
This commit is contained in:
parent
762592daff
commit
06b85442f8
4 changed files with 63 additions and 52 deletions
|
@ -392,6 +392,7 @@ void DownloadFileBox(not_null<Ui::GenericBox*> box, DownloadBoxArgs args) {
|
||||||
const auto done = std::move(args.done);
|
const auto done = std::move(args.done);
|
||||||
const auto name = args.name;
|
const auto name = args.name;
|
||||||
const auto session = args.session;
|
const auto session = args.session;
|
||||||
|
const auto chosen = std::make_shared<bool>();
|
||||||
box->addButton(tr::lng_bot_download_file_button(), [=] {
|
box->addButton(tr::lng_bot_download_file_button(), [=] {
|
||||||
const auto path = FileNameForSave(
|
const auto path = FileNameForSave(
|
||||||
session,
|
session,
|
||||||
|
@ -402,14 +403,19 @@ void DownloadFileBox(not_null<Ui::GenericBox*> box, DownloadBoxArgs args) {
|
||||||
false,
|
false,
|
||||||
QDir());
|
QDir());
|
||||||
if (!path.isEmpty()) {
|
if (!path.isEmpty()) {
|
||||||
|
*chosen = true;
|
||||||
box->closeBox();
|
box->closeBox();
|
||||||
done(path);
|
done(path);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
box->addButton(tr::lng_cancel(), [=] {
|
box->addButton(tr::lng_cancel(), [=] {
|
||||||
box->closeBox();
|
box->closeBox();
|
||||||
done(QString());
|
|
||||||
});
|
});
|
||||||
|
box->boxClosing() | rpl::start_with_next([=] {
|
||||||
|
if (!*chosen) {
|
||||||
|
done(QString());
|
||||||
|
}
|
||||||
|
}, box->lifetime());
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace InlineBots
|
} // namespace InlineBots
|
||||||
|
|
|
@ -9,6 +9,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
|
|
||||||
#include "core/file_utilities.h"
|
#include "core/file_utilities.h"
|
||||||
#include "ui/boxes/confirm_box.h"
|
#include "ui/boxes/confirm_box.h"
|
||||||
|
#include "ui/chat/attach/attach_bot_downloads.h"
|
||||||
#include "ui/effects/radial_animation.h"
|
#include "ui/effects/radial_animation.h"
|
||||||
#include "ui/effects/ripple_animation.h"
|
#include "ui/effects/ripple_animation.h"
|
||||||
#include "ui/layers/box_content.h"
|
#include "ui/layers/box_content.h"
|
||||||
|
@ -430,9 +431,7 @@ Panel::Panel(Args &&args)
|
||||||
setTitle(std::move(args.title));
|
setTitle(std::move(args.title));
|
||||||
_widget->setTitleBadge(std::move(args.titleBadge));
|
_widget->setTitleBadge(std::move(args.titleBadge));
|
||||||
|
|
||||||
if (showWebview(args.url, params, std::move(args.bottom))) {
|
if (!showWebview(std::move(args), params)) {
|
||||||
setupDownloadsProgress(rpl::duplicate(args.downloadsProgress));
|
|
||||||
} else {
|
|
||||||
const auto available = Webview::Availability();
|
const auto available = Webview::Availability();
|
||||||
if (available.error != Webview::Available::Error::None) {
|
if (available.error != Webview::Available::Error::None) {
|
||||||
showWebviewError(tr::lng_bot_no_webview(tr::now), available);
|
showWebviewError(tr::lng_bot_no_webview(tr::now), available);
|
||||||
|
@ -448,35 +447,38 @@ Panel::~Panel() {
|
||||||
_widget = nullptr;
|
_widget = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Panel::setupDownloadsProgress(rpl::producer<DownloadsProgress> progress) {
|
void Panel::setupDownloadsProgress(
|
||||||
Expects(_menuToggle != nullptr);
|
not_null<RpWidget*> button,
|
||||||
|
rpl::producer<DownloadsProgress> progress,
|
||||||
const auto widget = Ui::CreateChild<RpWidget>(_menuToggle.data());
|
bool fullscreen) {
|
||||||
|
const auto widget = Ui::CreateChild<RpWidget>(button.get());
|
||||||
widget->show();
|
widget->show();
|
||||||
widget->setAttribute(Qt::WA_TransparentForMouseEvents);
|
widget->setAttribute(Qt::WA_TransparentForMouseEvents);
|
||||||
|
|
||||||
_menuToggle->sizeValue() | rpl::start_with_next([=](QSize size) {
|
button->sizeValue() | rpl::start_with_next([=](QSize size) {
|
||||||
widget->setGeometry(QRect(QPoint(), size));
|
widget->setGeometry(QRect(QPoint(), size));
|
||||||
}, widget->lifetime());
|
}, widget->lifetime());
|
||||||
|
|
||||||
struct State {
|
struct State {
|
||||||
State(QWidget *parent, Fn<float64()> progress)
|
State(QWidget *parent)
|
||||||
: animation([=](crl::time now) {
|
: animation([=](crl::time now) {
|
||||||
const auto updated = animation.update(progress(), false, now);
|
const auto total = progress.total;
|
||||||
|
const auto current = total
|
||||||
|
? (progress.ready / float64(total))
|
||||||
|
: 0.;
|
||||||
|
const auto updated = animation.update(current, false, now);
|
||||||
if (!anim::Disabled() || updated) {
|
if (!anim::Disabled() || updated) {
|
||||||
parent->update();
|
parent->update();
|
||||||
}
|
}
|
||||||
}) {
|
}) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DownloadsProgress progress;
|
||||||
RadialAnimation animation;
|
RadialAnimation animation;
|
||||||
Animations::Simple fade;
|
Animations::Simple fade;
|
||||||
bool shown = false;
|
bool shown = false;
|
||||||
};
|
};
|
||||||
const auto state = widget->lifetime().make_state<State>(widget, [=] {
|
const auto state = widget->lifetime().make_state<State>(widget);
|
||||||
const auto total = _downloadsProgress.total;
|
|
||||||
return total ? (_downloadsProgress.ready / float64(total)) : 0.;
|
|
||||||
});
|
|
||||||
std::move(
|
std::move(
|
||||||
progress
|
progress
|
||||||
) | rpl::start_with_next([=](DownloadsProgress progress) {
|
) | rpl::start_with_next([=](DownloadsProgress progress) {
|
||||||
|
@ -492,9 +494,9 @@ void Panel::setupDownloadsProgress(rpl::producer<DownloadsProgress> progress) {
|
||||||
widget->update();
|
widget->update();
|
||||||
if (!state->shown
|
if (!state->shown
|
||||||
&& !state->fade.animating()
|
&& !state->fade.animating()
|
||||||
&& (!_downloadsProgress.total
|
&& (!state->progress.total
|
||||||
|| (_downloadsProgress.ready
|
|| (state->progress.ready
|
||||||
== _downloadsProgress.total))) {
|
== state->progress.total))) {
|
||||||
state->animation.stop();
|
state->animation.stop();
|
||||||
}
|
}
|
||||||
}, shown ? 0. : 2., shown ? 2. : 0., st::radialDuration * 2);
|
}, shown ? 0. : 2., shown ? 2. : 0., st::radialDuration * 2);
|
||||||
|
@ -504,14 +506,13 @@ void Panel::setupDownloadsProgress(rpl::producer<DownloadsProgress> progress) {
|
||||||
state->animation.start(0.);
|
state->animation.start(0.);
|
||||||
}
|
}
|
||||||
toggle(true);
|
toggle(true);
|
||||||
} else if ((_downloadsProgress.total && !progress.total)
|
} else if ((state->progress.total && !progress.total)
|
||||||
|| (_downloadsProgress.ready < _downloadsProgress.total
|
|| (state->progress.ready < state->progress.total
|
||||||
&& progress.ready == progress.total)) {
|
&& progress.ready == progress.total)) {
|
||||||
state->animation.update(1., false, crl::now());
|
state->animation.update(1., false, crl::now());
|
||||||
toggle(false);
|
toggle(false);
|
||||||
}
|
}
|
||||||
_downloadsProgress = progress;
|
state->progress = progress;
|
||||||
_downloadsUpdated.fire({});
|
|
||||||
}, widget->lifetime());
|
}, widget->lifetime());
|
||||||
|
|
||||||
widget->paintRequest() | rpl::start_with_next([=] {
|
widget->paintRequest() | rpl::start_with_next([=] {
|
||||||
|
@ -525,10 +526,14 @@ void Panel::setupDownloadsProgress(rpl::producer<DownloadsProgress> progress) {
|
||||||
auto p = QPainter(widget);
|
auto p = QPainter(widget);
|
||||||
p.setOpacity(opacity);
|
p.setOpacity(opacity);
|
||||||
const auto palette = _widget->titleOverridePalette();
|
const auto palette = _widget->titleOverridePalette();
|
||||||
const auto color = palette
|
const auto color = fullscreen
|
||||||
|
? st::radialFg
|
||||||
|
: palette
|
||||||
? palette->boxTitleCloseFg()
|
? palette->boxTitleCloseFg()
|
||||||
: st::paymentsLoading.color;
|
: st::paymentsLoading.color;
|
||||||
const auto &st = st::separatePanelMenu;
|
const auto &st = fullscreen
|
||||||
|
? st::fullScreenPanelMenu
|
||||||
|
: st::separatePanelMenu;
|
||||||
const auto size = st.rippleAreaSize;
|
const auto size = st.rippleAreaSize;
|
||||||
const auto rect = QRect(st.rippleAreaPosition, QSize(size, size));
|
const auto rect = QRect(st.rippleAreaPosition, QSize(size, size));
|
||||||
const auto stroke = st::botWebViewRadialStroke;
|
const auto stroke = st::botWebViewRadialStroke;
|
||||||
|
@ -666,11 +671,8 @@ void Panel::hideWebviewProgress() {
|
||||||
toggleProgress(false);
|
toggleProgress(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Panel::showWebview(
|
bool Panel::showWebview(Args &&args, const Webview::ThemeParams ¶ms) {
|
||||||
const QString &url,
|
_bottomText = std::move(args.bottom);
|
||||||
const Webview::ThemeParams ¶ms,
|
|
||||||
rpl::producer<QString> bottomText) {
|
|
||||||
_bottomText = std::move(bottomText);
|
|
||||||
if (!_webview && !createWebview(params)) {
|
if (!_webview && !createWebview(params)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -678,10 +680,15 @@ bool Panel::showWebview(
|
||||||
showWebviewProgress();
|
showWebviewProgress();
|
||||||
_widget->hideLayer(anim::type::instant);
|
_widget->hideLayer(anim::type::instant);
|
||||||
updateThemeParams(params);
|
updateThemeParams(params);
|
||||||
|
const auto url = args.url;
|
||||||
_webview->window.navigate(url);
|
_webview->window.navigate(url);
|
||||||
_widget->setBackAllowed(allowBack);
|
_widget->setBackAllowed(allowBack);
|
||||||
|
|
||||||
_menuToggle = _widget->setMenuAllowed([=](
|
rpl::duplicate(args.downloadsProgress) | rpl::start_with_next([=] {
|
||||||
|
_downloadsUpdated.fire({});
|
||||||
|
}, lifetime());
|
||||||
|
|
||||||
|
_widget->setMenuAllowed([=](
|
||||||
const Ui::Menu::MenuCallback &callback) {
|
const Ui::Menu::MenuCallback &callback) {
|
||||||
auto list = _delegate->botDownloads(true);
|
auto list = _delegate->botDownloads(true);
|
||||||
if (!list.empty()) {
|
if (!list.empty()) {
|
||||||
|
@ -754,16 +761,15 @@ bool Panel::showWebview(
|
||||||
.isAttention = true,
|
.isAttention = true,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (_widget->isFullScreen()) {
|
}, [=, progress = std::move(args.downloadsProgress)](
|
||||||
callback(u"Close Full Screen"_q, [=] {
|
not_null<RpWidget*> button,
|
||||||
_fullscreen = false;
|
bool fullscreen) {
|
||||||
}, &st::menuIconPlayerWindowed);
|
setupDownloadsProgress(
|
||||||
} else {
|
button,
|
||||||
callback(u"Show Full Screen"_q, [=] {
|
rpl::duplicate(progress),
|
||||||
_fullscreen = true;
|
fullscreen);
|
||||||
}, &st::menuIconPlayerFullScreen);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -11,7 +11,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "base/object_ptr.h"
|
#include "base/object_ptr.h"
|
||||||
#include "base/weak_ptr.h"
|
#include "base/weak_ptr.h"
|
||||||
#include "base/flags.h"
|
#include "base/flags.h"
|
||||||
#include "ui/chat/attach/attach_bot_downloads.h"
|
|
||||||
#include "ui/rect_part.h"
|
#include "ui/rect_part.h"
|
||||||
#include "ui/round_rect.h"
|
#include "ui/round_rect.h"
|
||||||
#include "webview/webview_common.h"
|
#include "webview/webview_common.h"
|
||||||
|
@ -34,6 +33,10 @@ struct Available;
|
||||||
|
|
||||||
namespace Ui::BotWebView {
|
namespace Ui::BotWebView {
|
||||||
|
|
||||||
|
struct DownloadsProgress;
|
||||||
|
struct DownloadsEntry;
|
||||||
|
enum class DownloadsAction;
|
||||||
|
|
||||||
[[nodiscard]] TextWithEntities ErrorText(const Webview::Available &info);
|
[[nodiscard]] TextWithEntities ErrorText(const Webview::Available &info);
|
||||||
|
|
||||||
enum class MenuButton {
|
enum class MenuButton {
|
||||||
|
@ -75,9 +78,7 @@ public:
|
||||||
[[nodiscard]] virtual Webview::ThemeParams botThemeParams() = 0;
|
[[nodiscard]] virtual Webview::ThemeParams botThemeParams() = 0;
|
||||||
[[nodiscard]] virtual auto botDownloads(bool forceCheck = false)
|
[[nodiscard]] virtual auto botDownloads(bool forceCheck = false)
|
||||||
-> const std::vector<DownloadsEntry> & = 0;
|
-> const std::vector<DownloadsEntry> & = 0;
|
||||||
virtual void botDownloadsAction(
|
virtual void botDownloadsAction(uint32 id, DownloadsAction type) = 0;
|
||||||
uint32 id,
|
|
||||||
Ui::BotWebView::DownloadsAction type) = 0;
|
|
||||||
virtual bool botHandleLocalUri(QString uri, bool keepOpen) = 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;
|
||||||
|
@ -122,11 +123,6 @@ public:
|
||||||
void requestActivate();
|
void requestActivate();
|
||||||
void toggleProgress(bool shown);
|
void toggleProgress(bool shown);
|
||||||
|
|
||||||
bool showWebview(
|
|
||||||
const QString &url,
|
|
||||||
const Webview::ThemeParams ¶ms,
|
|
||||||
rpl::producer<QString> bottomText);
|
|
||||||
|
|
||||||
void showBox(object_ptr<BoxContent> box);
|
void showBox(object_ptr<BoxContent> box);
|
||||||
void showBox(
|
void showBox(
|
||||||
object_ptr<BoxContent> box,
|
object_ptr<BoxContent> box,
|
||||||
|
@ -152,11 +148,16 @@ private:
|
||||||
struct Progress;
|
struct Progress;
|
||||||
struct WebviewWithLifetime;
|
struct WebviewWithLifetime;
|
||||||
|
|
||||||
|
bool showWebview(Args &&args, const Webview::ThemeParams ¶ms);
|
||||||
|
|
||||||
bool createWebview(const Webview::ThemeParams ¶ms);
|
bool createWebview(const Webview::ThemeParams ¶ms);
|
||||||
void createWebviewBottom();
|
void createWebviewBottom();
|
||||||
void showWebviewProgress();
|
void showWebviewProgress();
|
||||||
void hideWebviewProgress();
|
void hideWebviewProgress();
|
||||||
void setupDownloadsProgress(rpl::producer<DownloadsProgress> progress);
|
void setupDownloadsProgress(
|
||||||
|
not_null<RpWidget*> button,
|
||||||
|
rpl::producer<DownloadsProgress> progress,
|
||||||
|
bool fullscreen);
|
||||||
void setTitle(rpl::producer<QString> title);
|
void setTitle(rpl::producer<QString> title);
|
||||||
void sendDataMessage(const QJsonObject &args);
|
void sendDataMessage(const QJsonObject &args);
|
||||||
void switchInlineQueryMessage(const QJsonObject &args);
|
void switchInlineQueryMessage(const QJsonObject &args);
|
||||||
|
@ -213,7 +214,6 @@ private:
|
||||||
bool _hasSettingsButton = false;
|
bool _hasSettingsButton = false;
|
||||||
MenuButtons _menuButtons = {};
|
MenuButtons _menuButtons = {};
|
||||||
std::unique_ptr<SeparatePanel> _widget;
|
std::unique_ptr<SeparatePanel> _widget;
|
||||||
QPointer<IconButton> _menuToggle;
|
|
||||||
std::unique_ptr<WebviewWithLifetime> _webview;
|
std::unique_ptr<WebviewWithLifetime> _webview;
|
||||||
std::unique_ptr<RpWidget> _webviewBottom;
|
std::unique_ptr<RpWidget> _webviewBottom;
|
||||||
rpl::variable<QString> _bottomText;
|
rpl::variable<QString> _bottomText;
|
||||||
|
@ -229,7 +229,6 @@ private:
|
||||||
rpl::lifetime _headerColorLifetime;
|
rpl::lifetime _headerColorLifetime;
|
||||||
rpl::lifetime _bodyColorLifetime;
|
rpl::lifetime _bodyColorLifetime;
|
||||||
rpl::lifetime _bottomBarColorLifetime;
|
rpl::lifetime _bottomBarColorLifetime;
|
||||||
DownloadsProgress _downloadsProgress;
|
|
||||||
rpl::event_stream<> _downloadsUpdated;
|
rpl::event_stream<> _downloadsUpdated;
|
||||||
rpl::variable<bool> _fullscreen = false;
|
rpl::variable<bool> _fullscreen = false;
|
||||||
bool _layerShown : 1 = false;
|
bool _layerShown : 1 = false;
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
Subproject commit 3b5ef7899e5edd544e37ecdf8b1e7e3ba0ca2dc0
|
Subproject commit 46c18e2c7e730c6304e8d813be4d5abc6fb364ad
|
Loading…
Add table
Reference in a new issue