Skip to content

Commit abafa5d

Browse files
authored
ref: Create redact options wrapper for Swift (#6474)
1 parent e0e5391 commit abafa5d

File tree

3 files changed

+66
-8
lines changed

3 files changed

+66
-8
lines changed

Sources/Sentry/SentryDependencyContainer.m

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
#import "SentryDefaultThreadInspector.h"
44
#import "SentryDelayedFramesTracker.h"
5+
#import "SentryDependencyContainerSwiftHelper.h"
56
#import "SentryInternalCDefines.h"
67
#import "SentryInternalDefines.h"
78
#import "SentryLogC.h"
@@ -59,6 +60,9 @@ @interface SentryFileManager () <SentryFileManagerProtocol>
5960
@end
6061

6162
#if SENTRY_HAS_UIKIT
63+
@interface SentryDefaultRedactOptions () <SentryRedactOptions>
64+
@end
65+
6266
@interface SentryWatchdogTerminationScopeObserver () <SentryScopeObserver>
6367
@end
6468

@@ -272,21 +276,23 @@ - (nonnull SentryScreenshotSource *)screenshotSource SENTRY_THREAD_SANITIZER_DOU
272276
if (_screenshotSource == nil) {
273277
// The options could be null here, but this is a general issue in the dependency
274278
// container and will be fixed in a future refactoring.
275-
SentryViewScreenshotOptions *_Nonnull options = SENTRY_UNWRAP_NULLABLE(
276-
SentryViewScreenshotOptions, SentrySDKInternal.options.screenshot);
279+
SentryOptions *_Nonnull options
280+
= SENTRY_UNWRAP_NULLABLE(SentryOptions, SentrySDKInternal.options);
277281

278282
id<SentryViewRenderer> viewRenderer;
279-
if (options.enableViewRendererV2) {
283+
if ([SentryDependencyContainerSwiftHelper viewRendererV2Enabled:options]) {
280284
viewRenderer = [[SentryViewRendererV2 alloc]
281-
initWithEnableFastViewRendering:options.enableFastViewRendering];
285+
initWithEnableFastViewRendering:[SentryDependencyContainerSwiftHelper
286+
fastViewRenderingEnabled:options]];
282287
} else {
283288
viewRenderer = [[SentryDefaultViewRenderer alloc] init];
284289
}
285290

286-
SentryViewPhotographer *photographer =
287-
[[SentryViewPhotographer alloc] initWithRenderer:viewRenderer
288-
redactOptions:options
289-
enableMaskRendererV2:options.enableViewRendererV2];
291+
SentryViewPhotographer *photographer = [[SentryViewPhotographer alloc]
292+
initWithRenderer:viewRenderer
293+
redactOptions:[SentryDependencyContainerSwiftHelper redactOptions:options]
294+
enableMaskRendererV2:[SentryDependencyContainerSwiftHelper
295+
viewRendererV2Enabled:options]];
290296
_screenshotSource = [[SentryScreenshotSource alloc] initWithPhotographer:photographer];
291297
}
292298

Sources/Sentry/SentryDependencyContainerSwiftHelper.m

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,24 @@
66
#import "SentrySDK+Private.h"
77
#import "SentrySwift.h"
88

9+
@implementation SentryDefaultRedactOptions
10+
- (instancetype)initWithMaskAllText:(BOOL)maskAllText
11+
maskAllImages:(BOOL)maskAllImages
12+
maskedViewClasses:(NSArray<Class> *)maskedViewClasses
13+
unmaskedViewClasses:(NSArray<Class> *)unmaskedViewClasses
14+
{
15+
if (self = [super init]) {
16+
_maskAllText = maskAllText;
17+
_maskAllImages = maskAllImages;
18+
_maskedViewClasses = maskedViewClasses;
19+
_unmaskedViewClasses = unmaskedViewClasses;
20+
return self;
21+
}
22+
return nil;
23+
}
24+
25+
@end
26+
927
@implementation SentryDependencyContainerSwiftHelper
1028

1129
#if SENTRY_HAS_UIKIT
@@ -15,6 +33,25 @@ @implementation SentryDependencyContainerSwiftHelper
1533
return [SentryDependencyContainer.sharedInstance.application getWindows];
1634
}
1735

36+
+ (BOOL)fastViewRenderingEnabled:(SentryOptions *)options
37+
{
38+
return options.screenshot.enableFastViewRendering;
39+
}
40+
41+
+ (BOOL)viewRendererV2Enabled:(SentryOptions *)options
42+
{
43+
return options.screenshot.enableViewRendererV2;
44+
}
45+
46+
+ (SentryDefaultRedactOptions *)redactOptions:(SentryOptions *)options
47+
{
48+
return [[SentryDefaultRedactOptions alloc]
49+
initWithMaskAllText:options.screenshot.maskAllText
50+
maskAllImages:options.screenshot.maskAllImages
51+
maskedViewClasses:options.screenshot.maskedViewClasses
52+
unmaskedViewClasses:options.screenshot.unmaskedViewClasses];
53+
}
54+
1855
#endif // SENTRY_HAS_UIKIT
1956

2057
+ (SentryDispatchQueueWrapper *)dispatchQueueWrapper

Sources/Sentry/include/SentryDependencyContainerSwiftHelper.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,19 @@
1212
@class SentryCrash;
1313
@class SentryNSProcessInfoWrapper;
1414
@class SentryDispatchQueueWrapper;
15+
@class SentryOptions;
1516

1617
NS_ASSUME_NONNULL_BEGIN
1718

19+
@interface SentryDefaultRedactOptions : NSObject
20+
21+
@property (nonatomic) BOOL maskAllText;
22+
@property (nonatomic) BOOL maskAllImages;
23+
@property (nonatomic) NSArray<Class> *maskedViewClasses;
24+
@property (nonatomic) NSArray<Class> *unmaskedViewClasses;
25+
26+
@end
27+
1828
// Some Swift code needs to access Sentry types that we don’t want to completely
1929
// expose to Swift. This class is exposed to Swift
2030
// and bridges some functionality from without importing large amounts of the
@@ -25,6 +35,11 @@ NS_ASSUME_NONNULL_BEGIN
2535

2636
+ (nullable NSArray<UIWindow *> *)windows;
2737

38+
// Since SentryOptions is in ObjC, Swift code can't see the SentryViewScreenshotOptions property
39+
+ (BOOL)fastViewRenderingEnabled:(SentryOptions *)options;
40+
+ (BOOL)viewRendererV2Enabled:(SentryOptions *)options;
41+
+ (SentryDefaultRedactOptions *)redactOptions:(SentryOptions *)options;
42+
2843
#endif // SENTRY_HAS_UIKIT
2944

3045
+ (SentryDispatchQueueWrapper *)dispatchQueueWrapper;

0 commit comments

Comments
 (0)