Skip to content

Commit

Permalink
Gather more useful information for breadcrumbs about windows
Browse files Browse the repository at this point in the history
  • Loading branch information
kstenerud committed Nov 22, 2021
1 parent 7d40ac0 commit a0ebe99
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 3 deletions.
29 changes: 26 additions & 3 deletions Bugsnag/Breadcrumbs/BSGNotificationBreadcrumbs.m
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#import "BugsnagBreadcrumbs.h"
#import "BugsnagConfiguration+Private.h"
#import "BugsnagKeys.h"
#import "BSGUtils.h"

#if TARGET_OS_IOS || TARGET_OS_TV
#import "BSGUIKit.h"
Expand Down Expand Up @@ -263,19 +264,41 @@ - (void)addBreadcrumbForNotification:(NSNotification *)notification {
(defined(__TVOS_13_0) && __TV_OS_VERSION_MAX_ALLOWED >= __TVOS_13_0)
if (@available(iOS 13.0, tvOS 13.0, *)) {
if ([notification.name hasPrefix:@"UIScene"] && [notification.object isKindOfClass:UISCENE]) {
#define BSG_STRING_FROM_CLASS(__CLASS__) __CLASS__ ? NSStringFromClass((Class _Nonnull)__CLASS__) : nil
UIScene *scene = notification.object;
NSMutableDictionary *metadata = [NSMutableDictionary dictionary];
metadata[@"configuration"] = scene.session.configuration.name;
metadata[@"delegateClass"] = BSG_STRING_FROM_CLASS(scene.session.configuration.delegateClass);
metadata[@"delegateClass"] = bsg_string_from_class(scene.session.configuration.delegateClass);
metadata[@"role"] = scene.session.role;
metadata[@"sceneClass"] = BSG_STRING_FROM_CLASS(scene.session.configuration.sceneClass);
metadata[@"sceneClass"] = bsg_string_from_class(scene.session.configuration.sceneClass);
metadata[@"title"] = scene.title.length ? scene.title : nil;
[self addBreadcrumbWithType:BSGBreadcrumbTypeState forNotificationName:notification.name metadata:metadata];
return;
}
}
#endif
#if !TARGET_OS_OSX && \
(defined(__IPHONE_2_0) || (defined(__TVOS_9_0) && __TV_OS_VERSION_MAX_ALLOWED >= __TVOS_9_0))
if ([notification.name hasPrefix:@"UIWindow"] && [notification.object isKindOfClass:UIWINDOW]) {
UIWindow *window = notification.object;
NSMutableDictionary *metadata = [NSMutableDictionary dictionary];
metadata[@"windowClass"] = bsg_string_from_class(window.class);
metadata[@"description"] = window.description;
[self addBreadcrumbWithType:BSGBreadcrumbTypeState forNotificationName:notification.name metadata:metadata];
return;
}
#endif
#if TARGET_OS_OSX
if ([notification.name hasPrefix:@"NSWindow"] && [notification.object isKindOfClass:NSWINDOW]) {
NSWindow *window = notification.object;
NSMutableDictionary *metadata = [NSMutableDictionary dictionary];
metadata[@"windowClass"] = window.className;
metadata[@"title"] = window.title;
metadata[@"description"] = window.description;
[self addBreadcrumbWithType:BSGBreadcrumbTypeState forNotificationName:notification.name metadata:metadata];
return;
}
#endif

[self addBreadcrumbWithType:BSGBreadcrumbTypeState forNotificationName:notification.name];
}

Expand Down
1 change: 1 addition & 0 deletions Bugsnag/Helpers/BSGAppKit.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#define NSAPPLICATION NSClassFromString(@"NSApplication")
#define NSMENUITEM NSClassFromString(@"NSMenuItem")
#define NSWORKSPACE NSClassFromString(@"NSWorkspace")
#define NSWINDOW NSClassFromString(@"NSWindow")

#define NSApplicationDidBecomeActiveNotification @"NSApplicationDidBecomeActiveNotification"
#define NSApplicationDidFinishLaunchingNotification @"NSApplicationDidFinishLaunchingNotification"
Expand Down
1 change: 1 addition & 0 deletions Bugsnag/Helpers/BSGUIKit.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#define UIAPPLICATION NSClassFromString(@"UIApplication")
#define UIDEVICE NSClassFromString(@"UIDevice")
#define UISCENE NSClassFromString(@"UIScene")
#define UIWINDOW NSClassFromString(@"UIWindow")

#define UIApplicationDidBecomeActiveNotification @"UIApplicationDidBecomeActiveNotification"
#define UIApplicationDidEnterBackgroundNotification @"UIApplicationDidEnterBackgroundNotification"
Expand Down
4 changes: 4 additions & 0 deletions Bugsnag/Helpers/BSGUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,7 @@ NSString *_Nullable BSGStringFromThermalState(NSProcessInfoThermalState thermalS
NS_ASSUME_NONNULL_END

__END_DECLS

static inline NSString * _Nullable bsg_string_from_class(Class _Nullable cls) {
return cls ? NSStringFromClass((Class _Nonnull)cls) : nil;
}

0 comments on commit a0ebe99

Please sign in to comment.