Skip to content

Commit

Permalink
Merge branch 'dev' of https://github.com/TDesktop-x64/tdesktop into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
c0re100 committed Jan 10, 2025
2 parents 75aedfe + f806b5c commit b1f5d59
Show file tree
Hide file tree
Showing 6 changed files with 161 additions and 12 deletions.
20 changes: 10 additions & 10 deletions Telegram/SourceFiles/history/history_inner_widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2833,11 +2833,11 @@ void HistoryInner::showContextMenu(QContextMenuEvent *e, bool showFromTouch) {
}, &st::menuIconBlock);
}
}
//if (item && item->id > 0 && isUponSelected != 2 && isUponSelected != -2) {
// _menu->addAction(tr::lng_context_view_as_json(tr::now), [=] {
// HistoryView::ViewAsJSON(controller, itemId);
// }, &st::menuIconLink);
//}
if (item && item->id > 0 && isUponSelected != 2 && isUponSelected != -2) {
_menu->addAction(tr::lng_context_view_as_json(tr::now), [=] {
HistoryView::ViewAsJSON(controller, itemId);
}, &st::menuIconLink);
}
} else { // maybe cursor on some text history item?
const auto albumPartItem = _dragStateItem;
const auto item = [&] {
Expand Down Expand Up @@ -3172,11 +3172,11 @@ void HistoryInner::showContextMenu(QContextMenuEvent *e, bool showFromTouch) {
} else if (Element::Moused()) {
addSelectMessageAction(Element::Moused()->data());
}
//if (item && item->id > 0 && isUponSelected != 2 && isUponSelected != -2) {
// _menu->addAction(tr::lng_context_view_as_json(tr::now), [=] {
// HistoryView::ViewAsJSON(controller, itemId);
// }, &st::menuIconLink);
//}
if (item && item->id > 0 && isUponSelected != 2 && isUponSelected != -2) {
_menu->addAction(tr::lng_context_view_as_json(tr::now), [=] {
HistoryView::ViewAsJSON(controller, itemId);
}, &st::menuIconLink);
}
}

if (_dragStateItem) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ For license and copyright information please follow this link:
#include "main/main_session.h"
#include "main/main_session_settings.h"
#include "spellcheck/spellcheck_types.h"
#include "iv/iv_instance.h"
#include "facades.h"
#include "apiwrap.h"
#include "styles/style_chat.h"
Expand Down Expand Up @@ -1572,7 +1573,7 @@ void ViewAsJSON(
}
item->history()->session().api().exportMessageAsBase64(item,
crl::guard(show, [=](const QString& base64) {
File::OpenUrl(u"https://tlv.kokkoro.eu.org/#l=%1&m=%2&td=1"_q.arg(MTP::details::kCurrentLayer).arg(base64));
Core::App().iv().showTLViewer(MTP::details::kCurrentLayer, base64);
}),
crl::guard(show, [=] {
show->showToast(u"error"_q);
Expand Down
19 changes: 18 additions & 1 deletion Telegram/SourceFiles/iv/iv_controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -567,6 +567,22 @@ void Controller::showTonSite(
_menuToggle->hide();
}

void Controller::showTLViewer(
const Webview::StorageId& storageId,
QString url) {
if (!_webview) {
createWebview(storageId);
}
if (_webview && _webview->widget()) {
_webview->navigate(url);
activate();
}
_url = url;
_subtitleText = tr::lng_context_view_as_json(tr::now);
_windowTitleText = _subtitleText.value();
_menuToggle->hide();
}

QByteArray Controller::fillInChannelValuesScript(
base::flat_map<QByteArray, rpl::producer<bool>> inChannelValues) {
auto result = QByteArray();
Expand Down Expand Up @@ -721,7 +737,8 @@ void Controller::createWebview(const Webview::StorageId &storageId) {

raw->setNavigationStartHandler([=](const QString &uri, bool newWindow) {
if (uri.startsWith(u"http://desktop-app-resource/"_q)
|| QUrl(uri).host().toLower().endsWith(u".magic.org"_q)) {
|| QUrl(uri).host().toLower().endsWith(u".magic.org"_q)
|| uri.startsWith(Iv::kTLViewerUrl.utf16())) {
return true;
}
_events.fire({ .type = Event::Type::OpenLink, .url = uri });
Expand Down
5 changes: 5 additions & 0 deletions Telegram/SourceFiles/iv/iv_controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ For license and copyright information please follow this link:
*/
#pragma once

#include "base/const_string.h"
#include "base/invoke_queued.h"
#include "base/object_ptr.h"
#include "base/unique_qptr.h"
Expand Down Expand Up @@ -34,6 +35,8 @@ class FadeWrapScaled;

namespace Iv {

constexpr auto kTLViewerUrl = "https://tdesktop-x64.github.io/tlv/"_cs;

struct Prepared;

struct ShareBoxResult {
Expand Down Expand Up @@ -79,6 +82,8 @@ class Controller final {
[[nodiscard]] static bool IsGoodTonSiteUrl(const QString &uri);
void showTonSite(const Webview::StorageId &storageId, QString uri);

void showTLViewer(const Webview::StorageId& storageId, QString uri);

[[nodiscard]] bool active() const;
void showJoinedTooltip();
void minimize();
Expand Down
121 changes: 121 additions & 0 deletions Telegram/SourceFiles/iv/iv_instance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,39 @@ class TonSite final : public base::has_weak_ptr {

};

class TLViewer final : public base::has_weak_ptr {
public:
TLViewer(not_null<Delegate*> delegate, QString uri);

[[nodiscard]] bool active() const;

void moveTo(QString uri);

void minimize();

[[nodiscard]] rpl::producer<Controller::Event> events() const {
return _events.events();
}

[[nodiscard]] rpl::lifetime& lifetime() {
return _lifetime;
}

private:
void createController();

void showWindowed();

const not_null<Delegate*> _delegate;
QString _uri;
std::unique_ptr<Controller> _controller;

rpl::event_stream<Controller::Event> _events;

rpl::lifetime _lifetime;

};

Shown::Shown(
not_null<Delegate*> delegate,
not_null<Main::Session*> session,
Expand Down Expand Up @@ -820,6 +853,48 @@ void TonSite::minimize() {
}
}

TLViewer::TLViewer(not_null<Delegate*> delegate, QString uri)
: _delegate(delegate)
, _uri(uri) {
showWindowed();
}

void TLViewer::createController() {
Expects(!_controller);

const auto showShareBox = [=](ShareBoxDescriptor&& descriptor) {
return ShareBoxResult();
};
_controller = std::make_unique<Controller>(
_delegate,
std::move(showShareBox));

_controller->events(
) | rpl::start_to_stream(_events, _controller->lifetime());
}

void TLViewer::showWindowed() {
if (!_controller) {
createController();
}

_controller->showTLViewer(Storage::TonSiteStorageId(), _uri);
}

bool TLViewer::active() const {
return _controller && _controller->active();
}

void TLViewer::moveTo(QString uri) {
_controller->showTLViewer({}, uri);
}

void TLViewer::minimize() {
if (_controller) {
_controller->minimize();
}
}

Instance::Instance(not_null<Delegate*> delegate) : _delegate(delegate) {
}

Expand Down Expand Up @@ -1122,6 +1197,45 @@ void Instance::showTonSite(
}, _tonSite->lifetime());
}

void Instance::showTLViewer(int32 layer, const QString& object) {
if (Platform::IsMac()) {
// Otherwise IV is not visible under the media viewer.
Core::App().hideMediaView();
}
auto uri = QString("%1#m=%2&l=%3&td=1").arg(Iv::kTLViewerUrl.data()).arg(object).arg(layer);
if (_tlv) {
_tlv->moveTo(uri);
return;
}
_tlv = std::make_unique<TLViewer>(_delegate, uri);
_tlv->events() | rpl::start_with_next([=](Controller::Event event) {
using Type = Controller::Event::Type;
const auto lower = event.url.toLower();
const auto urlChecked = lower.startsWith("http://")
|| lower.startsWith("https://");
switch (event.type) {
case Type::Close:
_tlv = nullptr;
break;
case Type::Quit:
Shortcuts::Launch(Shortcuts::Command::Quit);
break;
case Type::OpenLinkExternal:
if (urlChecked) {
File::OpenUrl(event.url);
closeAll();
}
break;
case Type::OpenPage:
case Type::OpenLink:
if (urlChecked) {
UrlClickHandler::Open(event.url);
}
break;
}
}, _tlv->lifetime());
}

void Instance::requestFull(
not_null<Main::Session*> session,
const QString &id) {
Expand Down Expand Up @@ -1223,6 +1337,9 @@ bool Instance::closeActive() {
} else if (_tonSite && _tonSite->active()) {
_tonSite = nullptr;
return true;
} else if (_tlv && _tlv->active()) {
_tlv = nullptr;
return true;
}
return false;
}
Expand All @@ -1234,13 +1351,17 @@ bool Instance::minimizeActive() {
} else if (_tonSite && _tonSite->active()) {
_tonSite->minimize();
return true;
} else if (_tlv && _tlv->active()) {
_tlv->minimize();
return true;
}
return false;
}

void Instance::closeAll() {
_shown = nullptr;
_tonSite = nullptr;
_tlv = nullptr;
}

bool PreferForUri(const QString &uri) {
Expand Down
5 changes: 5 additions & 0 deletions Telegram/SourceFiles/iv/iv_instance.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ namespace Iv {
class Data;
class Shown;
class TonSite;
class TLViewer;

class Instance final {
public:
Expand Down Expand Up @@ -55,6 +56,8 @@ class Instance final {
const QString &uri,
QVariant context = {});

void showTLViewer(int32 layer, const QString& object);

[[nodiscard]] bool hasActiveWindow(
not_null<Main::Session*> session) const;

Expand Down Expand Up @@ -104,6 +107,8 @@ class Instance final {

std::unique_ptr<TonSite> _tonSite;

std::unique_ptr<TLViewer> _tlv;

rpl::lifetime _lifetime;

};
Expand Down

0 comments on commit b1f5d59

Please sign in to comment.