Open HTTP and HTTPS messages through the desktop URL handler

This commit is contained in:
evgeny committed 2026-10-04 19:05:08 +02:00
1 parent 01fa1bc552
commit a76ba87501
2 files changed
+18 -3

No files matched your search

+17 -2
View File
@@ -38,6 +38,8 @@ extern "C" {
#include <QClipboard>
#include <QStyle>
#include <QMessageBox>
#include <QDesktopServices>
#include <QUrl>
#include <QDebug>
#include <QFile>
#include <QTextStream>
@@ -550,7 +552,7 @@ void MainWindow::setupConnects() {
connect(m_accountList, &AccountList::pmRequested, this, &MainWindow::onPmRequested);
connect(m_accountList, &AccountList::inviteRequested, this, &MainWindow::onInviteToPmRequested);
connect(m_messageList, &MessageList::inviteRequested, this, &MainWindow::onInviteToPmRequested);
connect(m_messageList, &MessageList::inviteLinkActivated, this, &MainWindow::onInviteLinkActivated);
connect(m_messageList, &MessageList::linkActivated, this, &MainWindow::onMessageLinkActivated);
connect(m_messageList, &MessageList::readPositionChanged,
this, [this](const QString& channelId, qint64 lastReadMsgId) {
Q_UNUSED(lastReadMsgId);
@@ -695,7 +697,20 @@ void MainWindow::onInviteToPmRequested(const QString& source, quint64 peer, cons
}
}
void MainWindow::onInviteLinkActivated(const QString& link) {
void MainWindow::onMessageLinkActivated(const QString& link) {
if (!link.startsWith(QStringLiteral("utun://"))) {
const QUrl url(link, QUrl::StrictMode);
if (!url.isValid() || url.host().isEmpty() || (url.scheme() != "http" && url.scheme() != "https")) {
GUI_ERROR("message link: invalid web address bytes=%d", (int)link.size());
QMessageBox::warning(this, tr("Ссылка"), tr("Некорректная ссылка.")); return;
}
if (!QDesktopServices::openUrl(url)) {
GUI_ERROR("message link: external open failed scheme=%s host=%s", qPrintable(url.scheme()), qPrintable(url.host()));
QMessageBox::warning(this, tr("Ссылка"), tr("Не удалось открыть ссылку. Проверьте наличие браузера.")); return;
}
GUI_INFO("message link: external open requested scheme=%s host=%s", qPrintable(url.scheme()), qPrintable(url.host()));
return;
}
const auto invite = decodeInviteLink(link);
if (!invite.error.isEmpty()) {
GUI_ERROR("invite link: invalid error=%s", qPrintable(invite.error));