From 315ed7436fab68d97a94c397536a5856ddbd16f6 Mon Sep 17 00:00:00 2001 From: Mathieu Pellerin Date: Mon, 30 Oct 2023 19:43:02 +0700 Subject: [PATCH] Refine manual log submission --- src/core/appinterface.cpp | 4 +-- src/core/appinterface.h | 2 +- src/core/layerobserver.cpp | 2 +- src/qml/MessageLog.qml | 68 +++++++++++++++++++++++++++++++++-- src/sentry/sentry_classic.cpp | 14 ++++++-- src/sentry/sentry_cocoa.mm | 2 +- src/sentry/sentry_wrapper.h | 2 +- 7 files changed, 82 insertions(+), 12 deletions(-) diff --git a/src/core/appinterface.cpp b/src/core/appinterface.cpp index 93f7ad7eaf..05a1763a8f 100644 --- a/src/core/appinterface.cpp +++ b/src/core/appinterface.cpp @@ -169,10 +169,10 @@ void AppInterface::logRuntimeProfiler() #endif } -void AppInterface::sendLog( const QString &message ) +void AppInterface::sendLog( const QString &message, const QString &cloudUser ) { #if WITH_SENTRY - sentry_wrapper::capture_event( message.toUtf8().constData() ); + sentry_wrapper::capture_event( message.toUtf8().constData(), cloudUser.toUtf8().constData() ); #endif } diff --git a/src/core/appinterface.h b/src/core/appinterface.h index 8e9de05052..49b8bf19a5 100644 --- a/src/core/appinterface.h +++ b/src/core/appinterface.h @@ -76,7 +76,7 @@ class AppInterface : public QObject /** * Sends a logs reporting through to sentry when enabled. */ - Q_INVOKABLE void sendLog( const QString &message ); + Q_INVOKABLE void sendLog( const QString &message, const QString &cloudUser ); /** * Initalizes sentry connection. diff --git a/src/core/layerobserver.cpp b/src/core/layerobserver.cpp index 0c3812d927..d8e5f1ad73 100644 --- a/src/core/layerobserver.cpp +++ b/src/core/layerobserver.cpp @@ -271,7 +271,7 @@ void LayerObserver::onEditingStopped() if ( vl->source().contains( QStringLiteral( "data.gpkg" ) ) && mLocalAndSourcePkAttrAreEqual ) { - AppInterface::instance()->sendLog( QStringLiteral( "Called LayerObserver::onEditingStopped!" ) ); + AppInterface::instance()->sendLog( QStringLiteral( "Called LayerObserver::onEditingStopped!" ), QString() ); mLocalAndSourcePkAttrAreEqual = false; } diff --git a/src/qml/MessageLog.qml b/src/qml/MessageLog.qml index f023b16cbc..9568021526 100644 --- a/src/qml/MessageLog.qml +++ b/src/qml/MessageLog.qml @@ -143,16 +143,78 @@ Page { QfButton { id: submitLog Layout.fillWidth: true - text: qsTr( 'Send application log' ) + text: qsTr("Send application log") visible: qfieldSettings.enableInfoCollection && platformUtilities.capabilities & PlatformUtilities.SentryFramework onClicked: { - iface.sendLog("Manual log submission") - displayToast(qsTr("Your application log is being sent")) + applicationLogDialog.open() } } } + Dialog { + id: applicationLogDialog + title: qsTr("Send application log") + focus: true + font: Theme.defaultFont + + x: ( mainWindow.width - width ) / 2 + y: ( mainWindow.height - height - 80 ) / 2 + + onAboutToShow: { + appliationLogInput.text = '' + } + + Column { + width: childrenRect.width + height: childrenRect.height + spacing: 10 + + TextMetrics { + id: applicationLogLabelMetrics + font: applicationLogLabel.font + text: applicationLogLabel.text + } + + Label { + id: applicationLogLabel + width: mainWindow.width - 60 < applicationLogLabelMetrics.width ? mainWindow.width - 60 : applicationLogLabelMetrics.width + text: qsTr("this will send a log of your current session to the development team. You only need to do this when you are asked for it.") + wrapMode: Text.WordWrap + font: Theme.defaultFont + color: Theme.mainTextColor + } + + QfTextField { + id: appliationLogInput + width: applicationLogLabel.width + placeholderText: qsTr("Type optional details") + } + + CheckBox { + id: includeCloudInformationCheckBox + width: applicationLogLabel.width + topPadding: 5 + bottomPadding: 5 + text: qsTr('Include cloud user details') + font: Theme.defaultFont + visible: cloudConnection.status === QFieldCloudConnection.LoggedIn + checked: cloudConnection.status === QFieldCloudConnection.LoggedIn + indicator.height: 16 + indicator.width: 16 + indicator.implicitHeight: 24 + indicator.implicitWidth: 24 + } + } + + standardButtons: Dialog.Ok | Dialog.Cancel + onAccepted: { + var applicationLogMessage = appliationLogInput.text.trim() + iface.sendLog(applicationLogMessage != '' ? applicationLogMessage : 'Manual log submission', includeCloudInformationCheckBox.checked ? cloudConnection.username : '') + displayToast(qsTr("Your application log is being sent")) + } + } + Connections { target: model diff --git a/src/sentry/sentry_classic.cpp b/src/sentry/sentry_classic.cpp index 1d6e0da77b..a64d2bd218 100644 --- a/src/sentry/sentry_classic.cpp +++ b/src/sentry/sentry_classic.cpp @@ -184,11 +184,19 @@ namespace sentry_wrapper sentry_close(); } - void capture_event( const char *message ) + void capture_event( const char *message, const char *cloudUser ) { - sentry_capture_event( sentry_value_new_message_event( + sentry_value_t event = sentry_value_new_message_event( SENTRY_LEVEL_INFO, "custom", - message ) ); + message ); + + sentry_value_t cloud = sentry_value_new_object(); + sentry_value_set_by_key( cloud, "user", sentry_value_new_string( cloudUser ) ); + sentry_value_t contexts = sentry_value_new_object(); + sentry_value_set_by_key( contexts, "cloud", cloud ); + sentry_value_set_by_key( event, "contexts", contexts ); + + sentry_capture_event( event ); } } // namespace sentry_wrapper diff --git a/src/sentry/sentry_cocoa.mm b/src/sentry/sentry_cocoa.mm index 172e533115..75294f8f39 100644 --- a/src/sentry/sentry_cocoa.mm +++ b/src/sentry/sentry_cocoa.mm @@ -58,7 +58,7 @@ void install_message_handler() { originalMessageHandler = qInstallMessageHandler(qfMessageHandler); } -void capture_event(const char *message) { +void capture_event(const char *message, const char *cloudUser) { SentryId *eventId = [SentrySDK captureMessage:[NSString stringWithUTF8String:message]]; #if 0 diff --git a/src/sentry/sentry_wrapper.h b/src/sentry/sentry_wrapper.h index 08009fe68f..39b57b462b 100644 --- a/src/sentry/sentry_wrapper.h +++ b/src/sentry/sentry_wrapper.h @@ -19,5 +19,5 @@ namespace sentry_wrapper void init(); void close(); void install_message_handler(); - void capture_event( const char *message ); + void capture_event( const char *message, const char *cloudUser ); } // namespace sentry_wrapper