Skip to content

Commit

Permalink
Merge pull request #4714 from opengisch/backport-4710-to-release-3_0
Browse files Browse the repository at this point in the history
  • Loading branch information
suricactus committed Nov 2, 2023
2 parents 0362648 + a457d0d commit a6d3f1c
Show file tree
Hide file tree
Showing 7 changed files with 82 additions and 12 deletions.
4 changes: 2 additions & 2 deletions src/core/appinterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,10 +170,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
}

Expand Down
2 changes: 1 addition & 1 deletion src/core/appinterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion src/core/layerobserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
68 changes: 65 additions & 3 deletions src/qml/MessageLog.qml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
14 changes: 11 additions & 3 deletions src/sentry/sentry_classic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion src/sentry/sentry_cocoa.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/sentry/sentry_wrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

1 comment on commit a6d3f1c

@qfield-fairy
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.