Support separate webview storages.

This commit is contained in:
John Preston
2024-04-25 15:34:00 +04:00
parent 471831bcd6
commit c6d034174b
17 changed files with 138 additions and 40 deletions

View File

@@ -292,12 +292,12 @@ void Controller::initControls() {
}
void Controller::show(
const QString &dataPath,
const Webview::StorageId &storageId,
Prepared page,
base::flat_map<QByteArray, rpl::producer<bool>> inChannelValues) {
page.script = fillInChannelValuesScript(std::move(inChannelValues));
InvokeQueued(_container, [=, page = std::move(page)]() mutable {
showInWindow(dataPath, std::move(page));
showInWindow(storageId, std::move(page));
});
}
@@ -389,7 +389,7 @@ void Controller::createWindow() {
window->show();
}
void Controller::createWebview(const QString &dataPath) {
void Controller::createWebview(const Webview::StorageId &storageId) {
Expects(!_webview);
const auto window = _window.get();
@@ -397,7 +397,7 @@ void Controller::createWebview(const QString &dataPath) {
_container,
Webview::WindowConfig{
.opaqueBg = st::windowBg->c,
.userDataPath = dataPath,
.storageId = storageId,
});
const auto raw = _webview.get();
@@ -558,7 +558,9 @@ void Controller::createWebview(const QString &dataPath) {
raw->init(R"()");
}
void Controller::showInWindow(const QString &dataPath, Prepared page) {
void Controller::showInWindow(
const Webview::StorageId &storageId,
Prepared page) {
Expects(_container != nullptr);
const auto url = page.url;
@@ -571,7 +573,7 @@ void Controller::showInWindow(const QString &dataPath, Prepared page) {
const auto index = i->second;
_index = index;
if (!_webview) {
createWebview(dataPath);
createWebview(storageId);
if (_webview && _webview->widget()) {
auto id = u"iv/page%1.html"_q.arg(index);
if (!_hash.isEmpty()) {

View File

@@ -13,6 +13,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "iv/iv_delegate.h"
#include "ui/effects/animations.h"
#include "ui/text/text.h"
#include "webview/webview_common.h"
class Painter;
@@ -69,7 +70,7 @@ public:
};
void show(
const QString &dataPath,
const Webview::StorageId &storageId,
Prepared page,
base::flat_map<QByteArray, rpl::producer<bool>> inChannelValues);
void update(Prepared page);
@@ -90,11 +91,11 @@ public:
private:
void createWindow();
void createWebview(const QString &dataPath);
void createWebview(const Webview::StorageId &storageId);
[[nodiscard]] QByteArray navigateScript(int index, const QString &hash);
[[nodiscard]] QByteArray reloadScript(int index);
void showInWindow(const QString &dataPath, Prepared page);
void showInWindow(const Webview::StorageId &storageId, Prepared page);
[[nodiscard]] QByteArray fillInChannelValuesScript(
base::flat_map<QByteArray, rpl::producer<bool>> inChannelValues);
[[nodiscard]] QByteArray toggleInChannelScript(

View File

@@ -31,13 +31,12 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "lang/lang_keys.h"
#include "lottie/lottie_common.h" // Lottie::ReadContent.
#include "main/main_account.h"
#include "main/main_domain.h"
#include "main/main_session.h"
#include "main/session/session_show.h"
#include "media/streaming/media_streaming_loader.h"
#include "media/view/media_view_open_common.h"
#include "storage/file_download.h"
#include "storage/storage_domain.h"
#include "storage/storage_account.h"
#include "ui/boxes/confirm_box.h"
#include "ui/layers/layer_widget.h"
#include "ui/text/text_utilities.h"
@@ -348,9 +347,8 @@ void Shown::showWindowed(Prepared result) {
createController();
}
const auto domain = &_session->domain();
_controller->show(
domain->local().webviewDataPath(),
_session->local().resolveStorageIdOther(),
std::move(result),
base::duplicate(_inChannelValues));
}