Skip to content

Commit

Permalink
device wrapper not available for tvOS
Browse files Browse the repository at this point in the history
  • Loading branch information
armcknight committed Aug 29, 2023
1 parent bc99782 commit 896737a
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 19 deletions.
9 changes: 7 additions & 2 deletions Sources/Sentry/SentryDependencyContainer.m
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,14 @@
#if SENTRY_HAS_UIKIT
# import "SentryFramesTracker.h"
# import "SentryUIApplication.h"
# import "SentryUIDeviceWrapper.h"
# import <SentryScreenshot.h>
# import <SentryViewHierarchy.h>
#endif // SENTRY_HAS_UIKIT

#if TARGET_OS_IOS
# import "SentryUIDeviceWrapper.h"
#endif // TARGET_OS_IOS

@implementation SentryDependencyContainer

static SentryDependencyContainer *instance;
Expand Down Expand Up @@ -154,7 +157,7 @@ - (SentryBinaryImageCache *)binaryImageCache
return _binaryImageCache;
}

#if SENTRY_HAS_UIKIT
#if TARGET_OS_IOS
- (SentryUIDeviceWrapper *)uiDeviceWrapper
{
if (_uiDeviceWrapper == nil) {
Expand All @@ -166,7 +169,9 @@ - (SentryUIDeviceWrapper *)uiDeviceWrapper
}
return _uiDeviceWrapper;
}
#endif // TARGET_OS_IOS

#if SENTRY_HAS_UIKIT
- (SentryScreenshot *)screenshot
{
if (_screenshot == nil) {
Expand Down
12 changes: 9 additions & 3 deletions Sources/Sentry/include/HybridPublic/SentryDependencyContainer.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,12 @@
@class SentryFramesTracker;
@class SentryScreenshot;
@class SentryUIApplication;
@class SentryUIDeviceWrapper;
@class SentryViewHierarchy;
#endif
#endif // SENTRY_HAS_UIKIT

#if TARGET_OS_IOS
@class SentryUIDeviceWrapper;
#endif // TARGET_OS_IOS

NS_ASSUME_NONNULL_BEGIN

Expand Down Expand Up @@ -63,8 +66,11 @@ SENTRY_NO_INIT
@property (nonatomic, strong) SentryScreenshot *screenshot;
@property (nonatomic, strong) SentryViewHierarchy *viewHierarchy;
@property (nonatomic, strong) SentryUIApplication *application;
#endif // SENTRY_HAS_UIKIT

#if TARGET_OS_IOS
@property (nonatomic, strong) SentryUIDeviceWrapper *uiDeviceWrapper;
#endif
#endif // TARGET_OS_IOS

- (SentryANRTracker *)getANRTracker:(NSTimeInterval)timeout;

Expand Down
12 changes: 6 additions & 6 deletions Tests/SentryTests/Helper/SentryExtraContextProviderTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ final class SentryExtraContextProviderTests: XCTestCase {

private class Fixture {
let crashWrapper = TestSentryCrashWrapper.sharedInstance()
#if os(iOS) || os(tvOS) || targetEnvironment(macCatalyst)
#if os(iOS) || targetEnvironment(macCatalyst)
let deviceWrapper = TestSentryUIDeviceWrapper()
#endif // os(iOS) || os(tvOS) || targetEnvironment(macCatalyst)
#endif // os(iOS) || targetEnvironment(macCatalyst)
let processWrapper = TestSentryNSProcessInfoWrapper()

func getSut() -> SentryExtraContextProvider {
#if os(iOS) || os(tvOS) || targetEnvironment(macCatalyst)
#if os(iOS) || targetEnvironment(macCatalyst)
SentryDependencyContainer.sharedInstance().uiDeviceWrapper = deviceWrapper
#endif // os(iOS) || os(tvOS) || targetEnvironment(macCatalyst)
#endif // os(iOS) || targetEnvironment(macCatalyst)
return SentryExtraContextProvider(
crashWrapper: crashWrapper,
processInfoWrapper: processWrapper)
Expand Down Expand Up @@ -43,7 +43,7 @@ final class SentryExtraContextProviderTests: XCTestCase {
}

func testExtraDeviceInfo() {
#if os(iOS)
#if os(iOS) || targetEnvironment(macCatalyst)
let sut = fixture.getSut()
fixture.deviceWrapper.internalOrientation = .landscapeLeft
fixture.deviceWrapper.internalBatteryState = .full
Expand All @@ -55,7 +55,7 @@ final class SentryExtraContextProviderTests: XCTestCase {
XCTAssertEqual(device?["orientation"] as? String, "landscape")
XCTAssertEqual(device?["charging"] as? Bool, false)
XCTAssertEqual(device?["battery_level"] as? UInt, 44)
#endif
#endif // os(iOS) || targetEnvironment(macCatalyst)
}

func testExtraProcessInfo() {
Expand Down
12 changes: 6 additions & 6 deletions Tests/SentryTests/SentryClientTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ class SentryClientTest: XCTestCase {
let trace = SentryTracer(transactionContext: TransactionContext(name: "SomeTransaction", operation: "SomeOperation"), hub: nil)
let transaction: Transaction
let crashWrapper = TestSentryCrashWrapper.sharedInstance()
#if os(iOS) || os(tvOS) || targetEnvironment(macCatalyst)
#if os(iOS) || targetEnvironment(macCatalyst)
let deviceWrapper = TestSentryUIDeviceWrapper()
#endif // os(iOS) || os(tvOS) || targetEnvironment(macCatalyst)
#endif // os(iOS) || targetEnvironment(macCatalyst)
let processWrapper = TestSentryNSProcessInfoWrapper()
let extraContentProvider: SentryExtraContextProvider
let locale = Locale(identifier: "en_US")
Expand Down Expand Up @@ -65,9 +65,9 @@ class SentryClientTest: XCTestCase {
crashWrapper.internalAppMemorySize = 234_567
crashWrapper.internalFreeStorageSize = 345_678

#if os(iOS) || os(tvOS) || targetEnvironment(macCatalyst)
#if os(iOS) || targetEnvironment(macCatalyst)
SentryDependencyContainer.sharedInstance().uiDeviceWrapper = deviceWrapper
#endif // os(iOS) || os(tvOS) || targetEnvironment(macCatalyst)
#endif // os(iOS) || targetEnvironment(macCatalyst)

extraContentProvider = SentryExtraContextProvider(crashWrapper: crashWrapper, processInfoWrapper: processWrapper)
}
Expand Down Expand Up @@ -714,7 +714,7 @@ class SentryClientTest: XCTestCase {
}

func testCaptureEvent_DeviceProperties_OtherValues() {
#if os(iOS)
#if os(iOS) || targetEnvironment(macCatalyst)
fixture.deviceWrapper.internalOrientation = .landscapeLeft
fixture.deviceWrapper.internalBatteryState = .full

Expand All @@ -727,7 +727,7 @@ class SentryClientTest: XCTestCase {
let charging = actual.context?["device"]?["charging"] as? Bool
XCTAssertEqual(charging, false)
}
#endif
#endif // os(iOS) || targetEnvironment(macCatalyst)
}

func testCaptureEvent_AddCurrentCulture() {
Expand Down
4 changes: 2 additions & 2 deletions Tests/SentryTests/SentryCrash/TestSentryUIDeviceWrapper.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Sentry

#if os(iOS) || os(tvOS) || targetEnvironment(macCatalyst)
#if os(iOS) || targetEnvironment(macCatalyst)
class TestSentryUIDeviceWrapper: SentryUIDeviceWrapper {
var internalOrientation = UIDeviceOrientation.portrait
var internalIsBatteryMonitoringEnabled = true
Expand All @@ -23,4 +23,4 @@ class TestSentryUIDeviceWrapper: SentryUIDeviceWrapper {
return internalBatteryState
}
}
#endif // os(iOS) || os(tvOS) || targetEnvironment(macCatalyst)
#endif // os(iOS) || targetEnvironment(macCatalyst)

0 comments on commit 896737a

Please sign in to comment.