diff --git a/CMakeLists.txt b/CMakeLists.txt index 7b9e96e4b..4c474daeb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -66,6 +66,8 @@ if (QT_KNOWN_POLICY_QTP0004) qt_policy(SET QTP0004 NEW) endif () +find_package(sentry REQUIRED) + find_package(KF6 ${KF_MIN_VERSION} COMPONENTS Kirigami I18n Notifications Config CoreAddons Sonnet ItemModels IconThemes ColorScheme) set_package_properties(KF6 PROPERTIES TYPE REQUIRED diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 562b452bd..cfda9d729 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -198,6 +198,8 @@ add_library(neochat STATIC models/pinnedmessagemodel.h models/commonroomsmodel.cpp models/commonroomsmodel.h + sentryintegration.cpp + sentryintegration.h ) set_source_files_properties(qml/OsmLocationPlugin.qml PROPERTIES @@ -298,6 +300,7 @@ ecm_add_qml_module(neochat URI org.kde.neochat GENERATE_PLUGIN_SOURCE qml/HoverLinkIndicator.qml qml/AvatarNotification.qml qml/ReasonDialog.qml + qml/SendLogsDialog.qml DEPENDENCIES QtCore QtQuick @@ -430,6 +433,7 @@ target_link_libraries(neochat PUBLIC cmark::cmark QCoro::Core QCoro::Network + sentry::sentry ) if (TARGET KF6::Crash) diff --git a/src/main.cpp b/src/main.cpp index bedf926d8..a2463a3af 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -50,6 +50,7 @@ #include "controller.h" #include "logger.h" #include "roommanager.h" +#include "sentryintegration.h" #include "sharehandler.h" #include "windowcontroller.h" @@ -174,6 +175,8 @@ int main(int argc, char *argv[]) KCrash::initialize(); #endif + Sentry::instance(); + initLogging(); Connection::setEncryptionDefault(true); diff --git a/src/qml/AccountMenu.qml b/src/qml/AccountMenu.qml index 886675fb4..de7e69dac 100644 --- a/src/qml/AccountMenu.qml +++ b/src/qml/AccountMenu.qml @@ -91,12 +91,21 @@ KirigamiComponents.ConvergentContextMenu { enabled: Controller.csSupported } + QQC2.Action { + text: i18nc("@action:inmenu", "Do Sentry Things") + onTriggered: root.window.pageStack.pushDialogLayer(Qt.createComponent("org.kde.neochat", "SendLogsDialog"), {}, { + title: i18nc("@title:window", "Send Logs") + }) + } + + QQC2.Action { text: i18n("Logout") icon.name: "im-kick-user" onTriggered: confirmLogoutDialogComponent.createObject(QQC2.ApplicationWindow.window.overlay).open() } + readonly property Component confirmLogoutDialogComponent: ConfirmLogoutDialog { connection: root.connection } diff --git a/src/qml/SendLogsDialog.qml b/src/qml/SendLogsDialog.qml new file mode 100644 index 000000000..b573620df --- /dev/null +++ b/src/qml/SendLogsDialog.qml @@ -0,0 +1,36 @@ +// SPDX-FileCopyrightText: 2025 Tobias Fella +// SPDX-License-Identifier: LGPL-2.0-or-later + +import QtQuick +import QtQuick.Controls as QQC2 +import QtQuick.Layouts + +import org.kde.kirigami as Kirigami +import org.kde.kirigamiaddons.formcard as FormCard + +import org.kde.neochat + +FormCard.FormCardPage { + id: root + + title: i18nc("@title:dialog", "Upload Logs") + + FormCard.FormTextDelegate { + text: i18nc("@info", "Uploading NeoChat's logs can help with finding bugs in the app. After uploading the logs, a token will be shown which identifies the file you have uploaded. Please add this token when creating a bug report for your problem. Uploaded logs are only accessible to KDE developers and will never contain secret data."); + textItem.wrapMode: Text.Wrap + } + + FormCard.FormTextAreaDelegate { + id: description + label: i18nc("@label", "Description") + placeholderText: i18nc("@info:placeholder", "Things are not working") + } + + QQC2.DialogButtonBox { + QQC2.Button { + text: i18nc("@action:button", "Upload") + //TODO icon + } + standardButtons: QQC2.DialogButtonBox.Cancel + } +} diff --git a/src/sentryintegration.cpp b/src/sentryintegration.cpp new file mode 100644 index 000000000..5d43f0639 --- /dev/null +++ b/src/sentryintegration.cpp @@ -0,0 +1,35 @@ +// SPDX-FileCopyrightText: 2025 Tobias Fella +// SPDX-License-Identifier: LGPL-2.0-or-later + +#include "sentryintegration.h" + +#include + +using namespace Qt::Literals::StringLiterals; + +Sentry &Sentry::instance() +{ + static Sentry _instance; + return _instance; +} + +Sentry::Sentry() + : QObject() +{ + QString dsn = QStringLiteral("https://%1@crash-reports.kde.org/%2").arg("296a68fe1cf24ee79fafad735365d8d6"_L1, "18"_L1); + auto options = sentry_options_new(); + sentry_options_set_dsn(options, dsn.toLatin1().data()); + sentry_options_set_release(options, "neochat@TESTING"); + sentry_options_set_debug(options, false); + sentry_options_add_attachment(options, "/home/tobias/.local/share/KDE/neochat/neochat.log.0"); + sentry_init(options); +} + +void Sentry::sendLogs() +{ + auto event = sentry_value_new_message_event(SENTRY_LEVEL_INFO, "custom", "It works!"); + auto uuid = sentry_capture_event(event); + auto str = (char *)malloc(37); + sentry_uuid_as_string(&uuid, str); + qWarning() << "sent logs" << str; +} diff --git a/src/sentryintegration.h b/src/sentryintegration.h new file mode 100644 index 000000000..6c5f48852 --- /dev/null +++ b/src/sentryintegration.h @@ -0,0 +1,28 @@ +// SPDX-FileCopyrightText: 2025 Tobias Fella +// SPDX-License-Identifier: LGPL-2.0-or-later + +#pragma once + +#include +#include +#include + +class Sentry : public QObject +{ + Q_OBJECT + QML_ELEMENT + QML_SINGLETON + +public: + static Sentry &instance(); + static Sentry *create(QQmlEngine *engine, QJSEngine *) + { + engine->setObjectOwnership(&instance(), QQmlEngine::CppOwnership); + return &instance(); + } + + Q_INVOKABLE void sendLogs(); + +private: + Sentry(); +};