Skip to content

Commit

Permalink
fix(feedback): bubble up feedback capture to objc layer (#4659)
Browse files Browse the repository at this point in the history
  • Loading branch information
armcknight authored Dec 23, 2024
1 parent e79c9fa commit eeb4214
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 14 deletions.
14 changes: 13 additions & 1 deletion Sources/Sentry/SentryUserFeedbackIntegration.m
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
#import "SentryUserFeedbackIntegration.h"
#import "SentryOptions+Private.h"
#import "SentrySDK+Private.h"
#import "SentrySwift.h"

#if TARGET_OS_IOS && SENTRY_HAS_UIKIT

@interface SentryUserFeedbackIntegration () <SentryUserFeedbackIntegrationDriverDelegate>
@end

@implementation SentryUserFeedbackIntegration {
SentryUserFeedbackIntegrationDriver *_driver;
}
Expand All @@ -15,10 +19,18 @@ - (BOOL)installWithOptions:(SentryOptions *)options
}

_driver = [[SentryUserFeedbackIntegrationDriver alloc]
initWithConfiguration:options.userFeedbackConfiguration];
initWithConfiguration:options.userFeedbackConfiguration
delegate:self];

Check warning on line 23 in Sources/Sentry/SentryUserFeedbackIntegration.m

View check run for this annotation

Codecov / codecov/patch

Sources/Sentry/SentryUserFeedbackIntegration.m#L22-L23

Added lines #L22 - L23 were not covered by tests
return YES;
}

// MARK: SentryUserFeedbackIntegrationDriverDelegate

- (void)captureWithFeedback:(SentryFeedback *)feedback
{
[SentrySDK captureFeedback:feedback];
}

Check warning on line 32 in Sources/Sentry/SentryUserFeedbackIntegration.m

View check run for this annotation

Codecov / codecov/patch

Sources/Sentry/SentryUserFeedbackIntegration.m#L31-L32

Added lines #L31 - L32 were not covered by tests

@end

#endif // TARGET_OS_IOS && SENTRY_HAS_UIKIT
2 changes: 0 additions & 2 deletions Sources/Sentry/include/SentryPrivate.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
#import "SentryDispatchQueueWrapper.h"
#import "SentryNSDataUtils.h"
#import "SentryRandom.h"
#import "SentrySDK+Private.h"
#import "SentryScope+Private.h"
#import "SentryTime.h"
#import "SentryUserAccess.h"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import UIKit

@available(iOS 13.0, *)
protocol SentryUserFeedbackFormDelegate: NSObjectProtocol {
func finished()
func finished(with feedback: SentryFeedback?)
}

@available(iOS 13.0, *)
Expand Down Expand Up @@ -136,12 +136,11 @@ class SentryUserFeedbackForm: UIViewController {

let feedback = SentryFeedback(message: messageTextView.text, name: fullNameTextField.text, email: emailTextField.text, screenshot: screenshotImageView.image?.pngData())
SentryLog.log(message: "Sending user feedback", andLevel: .debug)
SentrySDK.capture(feedback: feedback)
delegate?.finished()
delegate?.finished(with: feedback)

Check warning on line 139 in Sources/Swift/Integrations/UserFeedback/SentryUserFeedbackForm.swift

View check run for this annotation

Codecov / codecov/patch

Sources/Swift/Integrations/UserFeedback/SentryUserFeedbackForm.swift#L138-L139

Added lines #L138 - L139 were not covered by tests
}

func cancelButtonTapped() {
delegate?.finished()
delegate?.finished(with: nil)

Check warning on line 143 in Sources/Swift/Integrations/UserFeedback/SentryUserFeedbackForm.swift

View check run for this annotation

Codecov / codecov/patch

Sources/Swift/Integrations/UserFeedback/SentryUserFeedbackForm.swift#L143

Added line #L143 was not covered by tests
}

// MARK: Layout
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,25 @@ import Foundation
@_implementationOnly import _SentryPrivate
import UIKit

@available(iOS 13.0, *) @objc
protocol SentryUserFeedbackIntegrationDriverDelegate: NSObjectProtocol {
func capture(feedback: SentryFeedback)
}

/**
* An integration managing a workflow for end users to report feedback via Sentry.
* - note: The default method to show the feedback form is via a floating widget placed in the bottom trailing corner of the screen. See the configuration classes for alternative options.
*/
@available(iOS 13.0, *)
@objcMembers
class SentryUserFeedbackIntegrationDriver: NSObject {
class SentryUserFeedbackIntegrationDriver: NSObject, SentryUserFeedbackWidgetDelegate {
let configuration: SentryUserFeedbackConfiguration
private var window: SentryUserFeedbackWidget.Window?
weak var delegate: (any SentryUserFeedbackIntegrationDriverDelegate)?

public init(configuration: SentryUserFeedbackConfiguration) {
public init(configuration: SentryUserFeedbackConfiguration, delegate: any SentryUserFeedbackIntegrationDriverDelegate) {
self.configuration = configuration
self.delegate = delegate

Check warning on line 24 in Sources/Swift/Integrations/UserFeedback/SentryUserFeedbackIntegrationDriver.swift

View check run for this annotation

Codecov / codecov/patch

Sources/Swift/Integrations/UserFeedback/SentryUserFeedbackIntegrationDriver.swift#L24

Added line #L24 was not covered by tests
super.init()

if let widgetConfigBuilder = configuration.configureWidget {
Expand Down Expand Up @@ -49,7 +56,7 @@ class SentryUserFeedbackIntegrationDriver: NSObject {
* If `SentryUserFeedbackConfiguration.autoInject` is `false`, this must be called explicitly.
*/
func createWidget() {
window = SentryUserFeedbackWidget.Window(config: configuration)
window = SentryUserFeedbackWidget.Window(config: configuration, delegate: self)

Check warning on line 59 in Sources/Swift/Integrations/UserFeedback/SentryUserFeedbackIntegrationDriver.swift

View check run for this annotation

Codecov / codecov/patch

Sources/Swift/Integrations/UserFeedback/SentryUserFeedbackIntegrationDriver.swift#L59

Added line #L59 was not covered by tests
window?.isHidden = false
}

Expand Down Expand Up @@ -78,6 +85,12 @@ class SentryUserFeedbackIntegrationDriver: NSObject {
SentryLog.warning("Invalid widget location specified: \(config.location). Must specify either one edge or one corner of the screen rect to place the widget.")
}
}

// MARK: SentryUserFeedbackWidgetDelegate

func capture(feedback: SentryFeedback) {
delegate?.capture(feedback: feedback)
}

Check warning on line 93 in Sources/Swift/Integrations/UserFeedback/SentryUserFeedbackIntegrationDriver.swift

View check run for this annotation

Codecov / codecov/patch

Sources/Swift/Integrations/UserFeedback/SentryUserFeedbackIntegrationDriver.swift#L92-L93

Added lines #L92 - L93 were not covered by tests
}

#endif // os(iOS) && !SENTRY_NO_UIKIT
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ import UIKit

var displayingForm = false

protocol SentryUserFeedbackWidgetDelegate: NSObjectProtocol {
func capture(feedback: SentryFeedback)
}

@available(iOS 13.0, *)
struct SentryUserFeedbackWidget {
class Window: UIWindow {
Expand All @@ -22,8 +26,11 @@ struct SentryUserFeedbackWidget {

let config: SentryUserFeedbackConfiguration

init(config: SentryUserFeedbackConfiguration) {
weak var delegate: (any SentryUserFeedbackWidgetDelegate)?

init(config: SentryUserFeedbackConfiguration, delegate: any SentryUserFeedbackWidgetDelegate) {
self.config = config
self.delegate = delegate

Check warning on line 33 in Sources/Swift/Integrations/UserFeedback/SentryUserFeedbackWidget.swift

View check run for this annotation

Codecov / codecov/patch

Sources/Swift/Integrations/UserFeedback/SentryUserFeedbackWidget.swift#L33

Added line #L33 was not covered by tests
super.init(nibName: nil, bundle: nil)
view.addSubview(button)

Expand Down Expand Up @@ -68,8 +75,12 @@ struct SentryUserFeedbackWidget {

// MARK: SentryUserFeedbackFormDelegate

func finished() {
func finished(with feedback: SentryFeedback?) {
closeForm()

Check warning on line 80 in Sources/Swift/Integrations/UserFeedback/SentryUserFeedbackWidget.swift

View check run for this annotation

Codecov / codecov/patch

Sources/Swift/Integrations/UserFeedback/SentryUserFeedbackWidget.swift#L80

Added line #L80 was not covered by tests
if let feedback = feedback {
delegate?.capture(feedback: feedback)

Check warning on line 82 in Sources/Swift/Integrations/UserFeedback/SentryUserFeedbackWidget.swift

View check run for this annotation

Codecov / codecov/patch

Sources/Swift/Integrations/UserFeedback/SentryUserFeedbackWidget.swift#L82

Added line #L82 was not covered by tests
}
}

// MARK: UIAdaptivePresentationControllerDelegate
Expand All @@ -79,9 +90,9 @@ struct SentryUserFeedbackWidget {
}
}

init(config: SentryUserFeedbackConfiguration) {
init(config: SentryUserFeedbackConfiguration, delegate: any SentryUserFeedbackWidgetDelegate) {
super.init(frame: UIScreen.main.bounds)
rootViewController = RootViewController(config: config)
rootViewController = RootViewController(config: config, delegate: delegate)

Check warning on line 95 in Sources/Swift/Integrations/UserFeedback/SentryUserFeedbackWidget.swift

View check run for this annotation

Codecov / codecov/patch

Sources/Swift/Integrations/UserFeedback/SentryUserFeedbackWidget.swift#L95

Added line #L95 was not covered by tests
windowLevel = config.widgetConfig.windowLevel
}

Expand Down

0 comments on commit eeb4214

Please sign in to comment.