Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PLAT-8918] Mac Catalyst: fix crash in addBreadcrumbForTableViewNotification: #1485

Merged
merged 2 commits into from
Sep 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 18 additions & 28 deletions Bugsnag/Breadcrumbs/BSGNotificationBreadcrumbs.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,13 @@

#import "BSGNotificationBreadcrumbs.h"

#import "BugsnagBreadcrumbs.h"
#import "BugsnagConfiguration+Private.h"
#import "BSGKeys.h"
#import "BSGUtils.h"
#import "BSGDefines.h"
#import "BSGAppKit.h"
#import "BSGDefines.h"
#import "BSGKeys.h"
#import "BSGUIKit.h"

#define BSG_HAVE_TABLE_VIEW (TARGET_OS_OSX || TARGET_OS_IOS || TARGET_OS_TV)
#define BSG_HAVE_TEXT_CONTROL (TARGET_OS_OSX || TARGET_OS_IOS )
#import "BSGUtils.h"
#import "BugsnagBreadcrumbs.h"
#import "BugsnagConfiguration+Private.h"

BSG_OBJC_DIRECT_MEMBERS
@interface BSGNotificationBreadcrumbs ()
Expand Down Expand Up @@ -170,30 +167,30 @@ - (instancetype)initWithConfiguration:(BugsnagConfiguration *)configuration
}

- (NSArray<NSNotificationName> *)automaticBreadcrumbControlEvents {
#if !BSG_HAVE_TEXT_CONTROL
return nil;
#elif BSG_HAVE_APPKIT
return @[
NSControlTextDidBeginEditingNotification,
NSControlTextDidEndEditingNotification
];
#else
#if TARGET_OS_IOS
return @[
UITextFieldTextDidBeginEditingNotification,
UITextFieldTextDidEndEditingNotification,
UITextViewTextDidBeginEditingNotification,
UITextViewTextDidEndEditingNotification
];
#elif TARGET_OS_OSX
return @[
NSControlTextDidBeginEditingNotification,
NSControlTextDidEndEditingNotification
];
#else
return nil;
#endif
}

- (NSArray<NSNotificationName> *)automaticBreadcrumbTableItemEvents {
#if !BSG_HAVE_TABLE_VIEW
return @[];
#elif BSG_HAVE_APPKIT
return @[ NSTableViewSelectionDidChangeNotification ];
#if TARGET_OS_IOS || TARGET_OS_TV
return @[UITableViewSelectionDidChangeNotification];
#elif TARGET_OS_OSX
return @[NSTableViewSelectionDidChangeNotification];
#else
return @[ UITableViewSelectionDidChangeNotification ];
return @[];
#endif
}

Expand Down Expand Up @@ -321,8 +318,6 @@ - (BOOL)tryAddSceneNotification:(NSNotification *)notification {
#endif

- (BOOL)tryAddWindowNotification:(NSNotification *)notification {
#if BSG_HAVE_WINDOW

#if TARGET_OS_IOS || TARGET_OS_TV
if ([notification.name hasPrefix:@"UIWindow"] && [notification.object isKindOfClass:UIWINDOW]) {
UIWindow *window = notification.object;
Expand Down Expand Up @@ -365,7 +360,6 @@ - (BOOL)tryAddWindowNotification:(NSNotification *)notification {
}
#endif

#endif
return NO;
}

Expand All @@ -380,8 +374,6 @@ - (void)addBreadcrumbForNotification:(NSNotification *)notification {
}

- (void)addBreadcrumbForTableViewNotification:(__unused NSNotification *)notification {
#if BSG_HAVE_TABLE_VIEW

#if TARGET_OS_IOS || TARGET_OS_TV
NSIndexPath *indexPath = ((UITableView *)notification.object).indexPathForSelectedRow;
[self addBreadcrumbWithType:BSGBreadcrumbTypeNavigation forNotificationName:notification.name metadata:
Expand All @@ -391,8 +383,6 @@ - (void)addBreadcrumbForTableViewNotification:(__unused NSNotification *)notific
[self addBreadcrumbWithType:BSGBreadcrumbTypeNavigation forNotificationName:notification.name metadata:
tableView ? @{@"selectedRow" : @(tableView.selectedRow), @"selectedColumn" : @(tableView.selectedColumn)} : nil];
#endif

#endif
}

- (void)addBreadcrumbForMenuItemNotification:(__unused NSNotification *)notification {
Expand Down
4 changes: 2 additions & 2 deletions Bugsnag/BugsnagSessionTracker.m
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ - (void)startWithNotificationCenter:(NSNotificationCenter *)notificationCenter i
bsg_log_debug(@"Not starting session because app is not in the foreground");
}

#if BSG_HAVE_APPKIT
#if TARGET_OS_OSX
[notificationCenter addObserver:self
selector:@selector(handleAppForegroundEvent)
name:NSApplicationWillBecomeActiveNotification
Expand All @@ -81,7 +81,7 @@ - (void)startWithNotificationCenter:(NSNotificationCenter *)notificationCenter i
selector:@selector(handleAppBackgroundEvent)
name:NSApplicationDidResignActiveNotification
object:nil];
#elif BSG_HAVE_WATCHKIT
#elif TARGET_OS_WATCH
[notificationCenter addObserver:self
selector:@selector(handleAppForegroundEvent)
name:WKApplicationWillEnterForegroundNotification
Expand Down
2 changes: 1 addition & 1 deletion Bugsnag/Client/BugsnagClient.m
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ - (void)start {

[center addObserver:self
selector:@selector(applicationWillTerminate:)
#if BSG_HAVE_APPKIT
#if TARGET_OS_OSX
name:NSApplicationWillTerminateNotification
#else
name:UIApplicationWillTerminateNotification
Expand Down
2 changes: 0 additions & 2 deletions Bugsnag/Helpers/BSGAppKit.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
// Copyright © 2021 Bugsnag Inc. All rights reserved.
//

#include "BSGDefines.h"

#if __has_include(<AppKit/AppKit.h>)

#import <AppKit/AppKit.h>
Expand Down
3 changes: 0 additions & 3 deletions Bugsnag/Helpers/BSGDefines.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
#include <TargetConditionals.h>

// Capabilities dependent upon system defines and files
#define BSG_HAVE_APPKIT __has_include(<AppKit/AppKit.h>)
#define BSG_HAVE_BATTERY ( TARGET_OS_IOS || TARGET_OS_WATCH)
#define BSG_HAVE_MACH_EXCEPTIONS (TARGET_OS_OSX || TARGET_OS_IOS )
#define BSG_HAVE_MACH_THREADS (TARGET_OS_OSX || TARGET_OS_IOS || TARGET_OS_TV )
Expand All @@ -22,8 +21,6 @@
#define BSG_HAVE_SIGALTSTACK (TARGET_OS_OSX || TARGET_OS_IOS )
#define BSG_HAVE_SYSCALL (TARGET_OS_OSX || TARGET_OS_IOS || TARGET_OS_TV )
#define BSG_HAVE_UIDEVICE __has_include(<UIKit/UIDevice.h>)
#define BSG_HAVE_UIKIT __has_include(<UIKit/UIKit.h>)
#define BSG_HAVE_WATCHKIT __has_include(<WatchKit/WatchKit.h>)
#define BSG_HAVE_WINDOW (TARGET_OS_OSX || TARGET_OS_IOS || TARGET_OS_TV )

// Capabilities dependent upon previously defined capabilities
Expand Down
2 changes: 0 additions & 2 deletions Bugsnag/Helpers/BSGUIKit.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
// Copyright © 2020 Bugsnag Inc. All rights reserved.
//

#import "BSGDefines.h"

#if __has_include(<UIKit/UIKit.h>)

#import <UIKit/UIKit.h>
Expand Down
10 changes: 5 additions & 5 deletions Bugsnag/KSCrash/Source/KSCrash/Recording/BSG_KSCrash.m
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@

#import "BSG_KSCrash.h"

#import "BSG_KSCrashC.h"
#import "BSG_KSCrashIdentifier.h"
#import "BSGDefines.h"
#import "BSGAppKit.h"
#import "BSGDefines.h"
#import "BSGUIKit.h"
#import "BSGWatchKit.h"
#import "BSG_KSCrashC.h"
#import "BSG_KSCrashIdentifier.h"

// ============================================================================
#pragma mark - Constants -
Expand Down Expand Up @@ -71,7 +71,7 @@ - (BSG_KSCrashType)install:(BSG_KSCrashType)crashTypes directory:(NSString *)dir
free(recrashReportPath);

NSNotificationCenter *nCenter = [NSNotificationCenter defaultCenter];
#if BSG_HAVE_APPKIT
#if TARGET_OS_OSX
// MacOS "active" serves the same purpose as "foreground" in iOS
[nCenter addObserver:self
selector:@selector(applicationDidEnterBackground)
Expand All @@ -81,7 +81,7 @@ - (BSG_KSCrashType)install:(BSG_KSCrashType)crashTypes directory:(NSString *)dir
selector:@selector(applicationWillEnterForeground)
name:NSApplicationDidBecomeActiveNotification
object:nil];
#elif BSG_HAVE_WATCHKIT
#elif TARGET_OS_WATCH
[nCenter addObserver:self
selector:@selector(applicationDidBecomeActive)
name:WKApplicationDidBecomeActiveNotification
Expand Down
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
Changelog
=========

## TBD

### Bug fixes

* Fix a crash on Mac Catalyst when user interacts with help menu.
[#1484](https://github.com/bugsnag/bugsnag-cocoa/issues/1484)
[#1485](https://github.com/bugsnag/bugsnag-cocoa/pull/1485)

## 6.23.0 (2022-09-14)

### Enhancements
Expand Down
4 changes: 2 additions & 2 deletions Tests/BugsnagTests/BugsnagSessionTrackerTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,9 @@ - (void)testHandleAppForegroundEvent {
- (void)testStartInBackground {
[self.sessionTracker startWithNotificationCenter:NSNotificationCenter.defaultCenter isInForeground:NO];
XCTAssertNil(self.sessionTracker.runningSession, @"There should be no running session after starting tracker in background");
#if BSG_HAVE_WATCHKIT
#if TARGET_OS_WATCH
[NSNotificationCenter.defaultCenter postNotificationName:WKApplicationDidBecomeActiveNotification object:nil];
#elif BSG_HAVE_APPKIT
#elif TARGET_OS_OSX
[NSNotificationCenter.defaultCenter postNotificationName:NSApplicationDidBecomeActiveNotification object:nil];
#else
[NSNotificationCenter.defaultCenter postNotificationName:UIApplicationDidBecomeActiveNotification object:nil];
Expand Down