Skip to content

Commit

Permalink
just send from the form, no need for delegation
Browse files Browse the repository at this point in the history
  • Loading branch information
armcknight committed Nov 15, 2024
1 parent 678ee5a commit 16fc970
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 51 deletions.
17 changes: 2 additions & 15 deletions Sources/Sentry/SentryUserFeedbackIntegration.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

#if TARGET_OS_IOS && SENTRY_HAS_UIKIT

@interface SentryUserFeedbackIntegration() <SentryUserFeedbackIntegrationDriverDelegate>
@interface SentryUserFeedbackIntegration()

@end

Expand All @@ -18,23 +18,10 @@ @implementation SentryUserFeedbackIntegration {
- (BOOL)installWithOptions:(SentryOptions *)options
{
_driver = [[SentryUserFeedbackIntegrationDriver alloc]
initWithConfiguration:options.userFeedbackConfiguration delegate:self];
initWithConfiguration:options.userFeedbackConfiguration];
return YES;
}

#pragma mark - SentryUserFeedbackIntegrationDriverDelegate

- (void)captureFeedbackWithMessage:(NSString * _Nonnull)message name:(NSString * _Nullable)name email:(NSString * _Nullable)email hints:(NSDictionary<NSString *,id> * _Nullable)hints {
NSError *error = [[NSError alloc] initWithDomain:@"user-feedback" code:1 userInfo:nil];
SentryId *eventId = [SentrySDK captureError:error];
// SentryId *eventId = [[SentryId alloc] init];
SentryUserFeedback *uf = [[SentryUserFeedback alloc] initWithEventId:eventId];
uf.name = name;
uf.comments = message;
uf.email = email;
[SentrySDK captureUserFeedback:uf];
}

@end

#endif // TARGET_OS_IOS && SENTRY_HAS_UIKIT
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ import UIKit

@available(iOS 13.0, *)
protocol SentryUserFeedbackFormDelegate: NSObjectProtocol {
func cancelled()
func captureFeedback(message: String, name: String?, email: String?, hints: [String: Any]?)
func finished()
}

@available(iOS 13.0, *)
Expand Down Expand Up @@ -109,11 +108,21 @@ class SentryUserFeedbackForm: UIViewController {
}

func submitFeedbackButtonTapped() {
delegate?.captureFeedback(message: messageTextView.text, name: fullNameTextField.text, email: emailTextField.text, hints: nil)
guard let name = fullNameTextField.text, let email = emailTextField.text else {
return
}
let error = NSError(domain: "user-feedback", code: 1)
let eventId = SentrySDK.capture(error: error)
let uf = UserFeedback(eventId: eventId)
uf.name = name
uf.email = email
uf.comments = messageTextView.text
SentrySDK.capture(userFeedback: uf)
delegate?.finished()
}

func cancelButtonTapped() {
delegate?.cancelled()
delegate?.finished()
}

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

@objc public protocol SentryUserFeedbackIntegrationDriverDelegate: NSObjectProtocol {
func captureFeedback(message: String, name: String?, email: String?, hints: [String: Any]?)
}

/**
* 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.
Expand All @@ -16,11 +12,9 @@ import UIKit
class SentryUserFeedbackIntegrationDriver: NSObject {
let configuration: SentryUserFeedbackConfiguration
private var window: SentryUserFeedbackWidget.Window?
weak var delegate: (any SentryUserFeedbackIntegrationDriverDelegate)?

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

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

Expand Down Expand Up @@ -86,11 +80,4 @@ class SentryUserFeedbackIntegrationDriver: NSObject {
}
}

@available(iOS 13.0, *)
extension SentryUserFeedbackIntegrationDriver: SentryUserFeedbackWidget.Delegate {
func captureFeedback(message: String, name: String?, email: String?, hints: [String : Any]?) {
self.delegate?.captureFeedback(message: message, name: name, email: email, hints: hints)
}
}

#endif // os(iOS) && !SENTRY_NO_UIKIT
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,6 @@ var displayingForm = false

@available(iOS 13.0, *)
struct SentryUserFeedbackWidget {

protocol Delegate: NSObjectProtocol {
func captureFeedback(message: String, name: String?, email: String?, hints: [String: Any]?)
}

class Window: UIWindow {
class RootViewController: UIViewController, SentryUserFeedbackFormDelegate, UIAdaptivePresentationControllerDelegate {
let defaultWidgetSpacing: CGFloat = 8
Expand All @@ -25,11 +20,8 @@ struct SentryUserFeedbackWidget {

let config: SentryUserFeedbackConfiguration

weak var delegate: (any Delegate)?

init(config: SentryUserFeedbackConfiguration, delegate: any Delegate) {
init(config: SentryUserFeedbackConfiguration) {
self.config = config
self.delegate = delegate
super.init(nibName: nil, bundle: nil)
view.addSubview(button)

Expand Down Expand Up @@ -74,13 +66,8 @@ struct SentryUserFeedbackWidget {

// MARK: SentryUserFeedbackFormDelegate

func cancelled() {
closeForm()
}

func captureFeedback(message: String, name: String?, email: String?, hints: [String : Any]?) {
func finished() {
closeForm()
self.delegate?.captureFeedback(message: message, name: name, email: email, hints: hints)
}

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

init(config: SentryUserFeedbackConfiguration, delegate: Delegate) {
init(config: SentryUserFeedbackConfiguration) {
super.init(frame: UIScreen.main.bounds)
rootViewController = RootViewController(config: config, delegate: delegate)
rootViewController = RootViewController(config: config)
windowLevel = config.widgetConfig.windowLevel
}

Expand Down

0 comments on commit 16fc970

Please sign in to comment.