mirror of
https://github.com/Nheko-Reborn/nheko.git
synced 2024-11-22 19:08:58 +03:00
Fix crash when receiving matrix uri
It seems like handling the message in a blocking manner is a no-go. I have no idea how to fix that, so just use a queued connection for now... (ASAN does not cooperate and just hides the crash D:) fixes #842
This commit is contained in:
parent
88521caf0d
commit
09aded2bc8
3 changed files with 20 additions and 13 deletions
|
@ -1252,10 +1252,10 @@ mxidFromSegments(QStringRef sigil, QStringRef mxid)
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
ChatPage::handleMatrixUri(const QByteArray &uri)
|
ChatPage::handleMatrixUri(QString uri)
|
||||||
{
|
{
|
||||||
nhlog::ui()->info("Received uri! {}", uri.toStdString());
|
nhlog::ui()->info("Received uri! {}", uri.toStdString());
|
||||||
QUrl uri_{QString::fromUtf8(uri)};
|
QUrl uri_{uri};
|
||||||
|
|
||||||
// Convert matrix.to URIs to proper format
|
// Convert matrix.to URIs to proper format
|
||||||
if (uri_.scheme() == "https" && uri_.host() == "matrix.to") {
|
if (uri_.scheme() == "https" && uri_.host() == "matrix.to") {
|
||||||
|
@ -1324,7 +1324,8 @@ ChatPage::handleMatrixUri(const QByteArray &uri)
|
||||||
std::vector<std::string> vias;
|
std::vector<std::string> vias;
|
||||||
QString action;
|
QString action;
|
||||||
|
|
||||||
for (QString item : uri_.query(QUrl::ComponentFormattingOption::FullyEncoded).split('&')) {
|
for (QString item :
|
||||||
|
uri_.query(QUrl::ComponentFormattingOption::FullyEncoded).split('&', Qt::SkipEmptyParts)) {
|
||||||
nhlog::ui()->info("item: {}", item.toStdString());
|
nhlog::ui()->info("item: {}", item.toStdString());
|
||||||
|
|
||||||
if (item.startsWith("action=")) {
|
if (item.startsWith("action=")) {
|
||||||
|
|
|
@ -78,7 +78,7 @@ public:
|
||||||
QString currentRoom() const;
|
QString currentRoom() const;
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
bool handleMatrixUri(const QByteArray &uri);
|
bool handleMatrixUri(QString uri);
|
||||||
bool handleMatrixUri(const QUrl &uri);
|
bool handleMatrixUri(const QUrl &uri);
|
||||||
|
|
||||||
void startChat(QString userid);
|
void startChat(QString userid);
|
||||||
|
|
24
src/main.cpp
24
src/main.cpp
|
@ -277,22 +277,28 @@ main(int argc, char *argv[])
|
||||||
w.activateWindow();
|
w.activateWindow();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// It seems like handling the message in a blocking manner is a no-go. I have no idea how to
|
||||||
|
// fix that, so just use a queued connection for now... (ASAN does not cooperate and just
|
||||||
|
// hides the crash D:)
|
||||||
QObject::connect(
|
QObject::connect(
|
||||||
&app,
|
&app,
|
||||||
&SingleApplication::receivedMessage,
|
&SingleApplication::receivedMessage,
|
||||||
ChatPage::instance(),
|
ChatPage::instance(),
|
||||||
[&](quint32, QByteArray message) { ChatPage::instance()->handleMatrixUri(message); });
|
[&](quint32, QByteArray message) {
|
||||||
|
QString m = QString::fromUtf8(message);
|
||||||
|
ChatPage::instance()->handleMatrixUri(m);
|
||||||
|
},
|
||||||
|
Qt::QueuedConnection);
|
||||||
|
|
||||||
QMetaObject::Connection uriConnection;
|
QMetaObject::Connection uriConnection;
|
||||||
if (app.isPrimary() && !matrixUri.isEmpty()) {
|
if (app.isPrimary() && !matrixUri.isEmpty()) {
|
||||||
uriConnection =
|
uriConnection = QObject::connect(ChatPage::instance(),
|
||||||
QObject::connect(ChatPage::instance(),
|
&ChatPage::contentLoaded,
|
||||||
&ChatPage::contentLoaded,
|
ChatPage::instance(),
|
||||||
ChatPage::instance(),
|
[&uriConnection, matrixUri]() {
|
||||||
[&uriConnection, matrixUri]() {
|
ChatPage::instance()->handleMatrixUri(matrixUri);
|
||||||
ChatPage::instance()->handleMatrixUri(matrixUri.toUtf8());
|
QObject::disconnect(uriConnection);
|
||||||
QObject::disconnect(uriConnection);
|
});
|
||||||
});
|
|
||||||
}
|
}
|
||||||
QDesktopServices::setUrlHandler("matrix", ChatPage::instance(), "handleMatrixUri");
|
QDesktopServices::setUrlHandler("matrix", ChatPage::instance(), "handleMatrixUri");
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue