mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Initial tonsite:// show in IV window.
This commit is contained in:
parent
3eeb01be61
commit
2dcf40817e
5 changed files with 177 additions and 10 deletions
|
@ -238,6 +238,9 @@ bool UiIntegration::handleUrlClick(
|
||||||
} else if (local.startsWith(u"tg://"_q, Qt::CaseInsensitive)) {
|
} else if (local.startsWith(u"tg://"_q, Qt::CaseInsensitive)) {
|
||||||
Core::App().openLocalUrl(local, context);
|
Core::App().openLocalUrl(local, context);
|
||||||
return true;
|
return true;
|
||||||
|
} else if (local.startsWith(u"tonsite://"_q, Qt::CaseInsensitive)) {
|
||||||
|
Core::App().iv().showTonSite(url, context);
|
||||||
|
return true;
|
||||||
} else if (local.startsWith(u"internal:"_q, Qt::CaseInsensitive)) {
|
} else if (local.startsWith(u"internal:"_q, Qt::CaseInsensitive)) {
|
||||||
Core::App().openInternalUrl(local, context);
|
Core::App().openInternalUrl(local, context);
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -251,6 +251,26 @@ void Controller::update(Prepared page) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Controller::showTonSite(
|
||||||
|
const Webview::StorageId &storageId,
|
||||||
|
QString uri) {
|
||||||
|
auto part = uri.mid(u"tonsite://"_q.size());
|
||||||
|
part = part.replace('-', "-h");
|
||||||
|
part = part.replace('.', "-d");
|
||||||
|
const auto url = "https://" + part + ".magic.org";
|
||||||
|
if (!_webview) {
|
||||||
|
createWebview(storageId);
|
||||||
|
}
|
||||||
|
if (_webview && _webview->widget()) {
|
||||||
|
_webview->navigate(url);
|
||||||
|
activate();
|
||||||
|
} else {
|
||||||
|
_events.fire({ Event::Type::Close });
|
||||||
|
}
|
||||||
|
_subtitleText = uri;
|
||||||
|
_menuToggle->hide();
|
||||||
|
}
|
||||||
|
|
||||||
QByteArray Controller::fillInChannelValuesScript(
|
QByteArray Controller::fillInChannelValuesScript(
|
||||||
base::flat_map<QByteArray, rpl::producer<bool>> inChannelValues) {
|
base::flat_map<QByteArray, rpl::producer<bool>> inChannelValues) {
|
||||||
auto result = QByteArray();
|
auto result = QByteArray();
|
||||||
|
|
|
@ -76,6 +76,8 @@ public:
|
||||||
base::flat_map<QByteArray, rpl::producer<bool>> inChannelValues);
|
base::flat_map<QByteArray, rpl::producer<bool>> inChannelValues);
|
||||||
void update(Prepared page);
|
void update(Prepared page);
|
||||||
|
|
||||||
|
void showTonSite(const Webview::StorageId &storageId, QString uri);
|
||||||
|
|
||||||
[[nodiscard]] bool active() const;
|
[[nodiscard]] bool active() const;
|
||||||
void showJoinedTooltip();
|
void showJoinedTooltip();
|
||||||
void minimize();
|
void minimize();
|
||||||
|
|
|
@ -171,6 +171,39 @@ private:
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class TonSite final : public base::has_weak_ptr {
|
||||||
|
public:
|
||||||
|
TonSite(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(
|
Shown::Shown(
|
||||||
not_null<Delegate*> delegate,
|
not_null<Delegate*> delegate,
|
||||||
not_null<Main::Session*> session,
|
not_null<Main::Session*> session,
|
||||||
|
@ -742,6 +775,50 @@ void Shown::minimize() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TonSite::TonSite(not_null<Delegate*> delegate, QString uri)
|
||||||
|
: _delegate(delegate)
|
||||||
|
, _uri(uri) {
|
||||||
|
showWindowed();
|
||||||
|
}
|
||||||
|
|
||||||
|
void TonSite::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 TonSite::showWindowed() {
|
||||||
|
if (!_controller) {
|
||||||
|
createController();
|
||||||
|
}
|
||||||
|
|
||||||
|
_controller->showTonSite(
|
||||||
|
{},//_session->local().resolveStorageIdOther(),
|
||||||
|
_uri);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool TonSite::active() const {
|
||||||
|
return _controller && _controller->active();
|
||||||
|
}
|
||||||
|
|
||||||
|
void TonSite::moveTo(QString uri) {
|
||||||
|
_controller->showTonSite({}, uri);
|
||||||
|
}
|
||||||
|
|
||||||
|
void TonSite::minimize() {
|
||||||
|
if (_controller) {
|
||||||
|
_controller->minimize();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Instance::Instance(not_null<Delegate*> delegate) : _delegate(delegate) {
|
Instance::Instance(not_null<Delegate*> delegate) : _delegate(delegate) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -785,6 +862,7 @@ void Instance::show(
|
||||||
const auto lower = event.url.toLower();
|
const auto lower = event.url.toLower();
|
||||||
const auto urlChecked = lower.startsWith("http://")
|
const auto urlChecked = lower.startsWith("http://")
|
||||||
|| lower.startsWith("https://");
|
|| lower.startsWith("https://");
|
||||||
|
const auto tonsite = lower.startsWith("tonsite://");
|
||||||
switch (event.type) {
|
switch (event.type) {
|
||||||
case Type::Close:
|
case Type::Close:
|
||||||
_shown = nullptr;
|
_shown = nullptr;
|
||||||
|
@ -801,8 +879,10 @@ void Instance::show(
|
||||||
case Type::OpenLinkExternal:
|
case Type::OpenLinkExternal:
|
||||||
if (urlChecked) {
|
if (urlChecked) {
|
||||||
File::OpenUrl(event.url);
|
File::OpenUrl(event.url);
|
||||||
|
closeAll();
|
||||||
|
} else if (tonsite) {
|
||||||
|
showTonSite(event.url);
|
||||||
}
|
}
|
||||||
closeAll();
|
|
||||||
break;
|
break;
|
||||||
case Type::OpenMedia:
|
case Type::OpenMedia:
|
||||||
if (const auto window = Core::App().activeWindow()) {
|
if (const auto window = Core::App().activeWindow()) {
|
||||||
|
@ -840,7 +920,10 @@ void Instance::show(
|
||||||
break;
|
break;
|
||||||
case Type::OpenPage:
|
case Type::OpenPage:
|
||||||
case Type::OpenLink: {
|
case Type::OpenLink: {
|
||||||
if (!urlChecked) {
|
if (tonsite) {
|
||||||
|
showTonSite(event.url);
|
||||||
|
break;
|
||||||
|
} else if (!urlChecked) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
const auto session = _shownSession;
|
const auto session = _shownSession;
|
||||||
|
@ -990,6 +1073,52 @@ void Instance::openWithIvPreferred(
|
||||||
}).send();
|
}).send();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Instance::showTonSite(
|
||||||
|
const QString &uri,
|
||||||
|
QVariant context) {
|
||||||
|
if (Platform::IsMac()) {
|
||||||
|
// Otherwise IV is not visible under the media viewer.
|
||||||
|
Core::App().hideMediaView();
|
||||||
|
}
|
||||||
|
if (_tonSite) {
|
||||||
|
_tonSite->moveTo(uri);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_tonSite = std::make_unique<TonSite>(_delegate, uri);
|
||||||
|
_tonSite->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://");
|
||||||
|
const auto tonsite = lower.startsWith("tonsite://");
|
||||||
|
switch (event.type) {
|
||||||
|
case Type::Close:
|
||||||
|
_tonSite = nullptr;
|
||||||
|
break;
|
||||||
|
case Type::Quit:
|
||||||
|
Shortcuts::Launch(Shortcuts::Command::Quit);
|
||||||
|
break;
|
||||||
|
case Type::OpenLinkExternal:
|
||||||
|
if (urlChecked) {
|
||||||
|
File::OpenUrl(event.url);
|
||||||
|
closeAll();
|
||||||
|
} else if (tonsite) {
|
||||||
|
showTonSite(event.url);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case Type::OpenPage:
|
||||||
|
case Type::OpenLink:
|
||||||
|
if (urlChecked) {
|
||||||
|
File::OpenUrl(event.url);
|
||||||
|
closeAll();
|
||||||
|
} else if (tonsite) {
|
||||||
|
showTonSite(event.url);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}, _tonSite->lifetime());
|
||||||
|
}
|
||||||
|
|
||||||
void Instance::requestFull(
|
void Instance::requestFull(
|
||||||
not_null<Main::Session*> session,
|
not_null<Main::Session*> session,
|
||||||
const QString &id) {
|
const QString &id) {
|
||||||
|
@ -1085,23 +1214,30 @@ bool Instance::hasActiveWindow(not_null<Main::Session*> session) const {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Instance::closeActive() {
|
bool Instance::closeActive() {
|
||||||
if (!_shown || !_shown->active()) {
|
if (_shown && _shown->active()) {
|
||||||
return false;
|
_shown = nullptr;
|
||||||
|
return true;
|
||||||
|
} else if (_tonSite && _tonSite->active()) {
|
||||||
|
_tonSite = nullptr;
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
_shown = nullptr;
|
return false;
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Instance::minimizeActive() {
|
bool Instance::minimizeActive() {
|
||||||
if (!_shown || !_shown->active()) {
|
if (_shown && _shown->active()) {
|
||||||
return false;
|
_shown->minimize();
|
||||||
|
return true;
|
||||||
|
} else if (_tonSite && _tonSite->active()) {
|
||||||
|
_tonSite->minimize();
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
_shown->minimize();
|
return false;
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Instance::closeAll() {
|
void Instance::closeAll() {
|
||||||
_shown = nullptr;
|
_shown = nullptr;
|
||||||
|
_tonSite = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PreferForUri(const QString &uri) {
|
bool PreferForUri(const QString &uri) {
|
||||||
|
|
|
@ -22,6 +22,7 @@ namespace Iv {
|
||||||
|
|
||||||
class Data;
|
class Data;
|
||||||
class Shown;
|
class Shown;
|
||||||
|
class TonSite;
|
||||||
|
|
||||||
class Instance final {
|
class Instance final {
|
||||||
public:
|
public:
|
||||||
|
@ -50,6 +51,10 @@ public:
|
||||||
QString uri,
|
QString uri,
|
||||||
QVariant context = {});
|
QVariant context = {});
|
||||||
|
|
||||||
|
void showTonSite(
|
||||||
|
const QString &uri,
|
||||||
|
QVariant context = {});
|
||||||
|
|
||||||
[[nodiscard]] bool hasActiveWindow(
|
[[nodiscard]] bool hasActiveWindow(
|
||||||
not_null<Main::Session*> session) const;
|
not_null<Main::Session*> session) const;
|
||||||
|
|
||||||
|
@ -97,6 +102,7 @@ private:
|
||||||
QString _ivRequestUri;
|
QString _ivRequestUri;
|
||||||
mtpRequestId _ivRequestId = 0;
|
mtpRequestId _ivRequestId = 0;
|
||||||
|
|
||||||
|
std::unique_ptr<TonSite> _tonSite;
|
||||||
|
|
||||||
rpl::lifetime _lifetime;
|
rpl::lifetime _lifetime;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue