Skip to content

Commit

Permalink
Fix KSCrash report integration
Browse files Browse the repository at this point in the history
This removes the dependency on our forked KSCrash repo, too.
  • Loading branch information
tmolitor-stud-tu committed Dec 12, 2023
1 parent 9dddf5d commit 9f06cae
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 73 deletions.
2 changes: 1 addition & 1 deletion Monal/Classes/MLCrashReporter.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
@class UIViewController;

@interface MLCrashReporter : NSObject
+(void) reportPendingCrashesWithViewController:(UIViewController*) viewController;
+(void) reportPendingCrashes;
@end

#endif /* MLCrashReporter_h */
75 changes: 49 additions & 26 deletions Monal/Classes/MLCrashReporter.m
Original file line number Diff line number Diff line change
Expand Up @@ -13,38 +13,41 @@
#import <KSCrash/KSCrashReportFilterAppleFmt.h>
#import <KSCrash/KSCrashReportFilterGZip.h>
#import <KSCrash/KSCrashReportFields.h>
#import <KSCrash/KSCrashReportFilterAlert.h>
#import <KSCrash/NSError+SimpleConstructor.h>
#import <MessageUI/MessageUI.h>
#import "MLConstants.h"
#import "HelperTools.h"
#import "MonalAppDelegate.h"
#import "MLCrashReporter.h"

#define PART_SEPARATOR_FORMAT "\n\n-------- d049d576-9bf0-47dd-839f-dee6b07c1df9 -------- %@ -------- d049d576-9bf0-47dd-839f-dee6b07c1df9 --------\n\n"

@interface KSCrashReportFilterAlert: NSObject <KSCrashReportFilter>
+(instancetype) filter;
@end

@interface KSCrashReportFilterEmpty: NSObject <KSCrashReportFilter>
+(KSCrashReportFilterEmpty*) filter;
+(instancetype) filter;
@end

@interface KSCrashReportFilterAddAuxInfo : NSObject <KSCrashReportFilter>
+(KSCrashReportFilterAddAuxInfo*) filter;
+(instancetype) filter;
@end

@interface KSCrashReportFilterAddMLLogfile : NSObject <KSCrashReportFilter>
+(KSCrashReportFilterAddMLLogfile*) filter;
+(instancetype) filter;
@end


@interface MLCrashReporter() <KSCrashReportFilter, MFMailComposeViewControllerDelegate>
@property (atomic, strong) UIViewController* viewController;
@property (atomic, strong) NSArray* _Nullable kscrashReports;
@property (atomic, strong) KSCrashReportFilterCompletion _Nullable kscrashCompletion;
@end


@implementation MLCrashReporter

+(void) reportPendingCrashesWithViewController:(UIViewController*) viewController
+(void) reportPendingCrashes
{
//send out pending KSCrash reports
KSCrash* handler = [KSCrash sharedInstance];
Expand All @@ -60,12 +63,7 @@ +(void) reportPendingCrashesWithViewController:(UIViewController*) viewControlle
id<KSCrashReportFilter> logfileFilter = [KSCrashReportFilterAddMLLogfile filter];
NSString* logfileName = @"Logfile (*.rawlog.gz)";
handler.sink = [KSCrashReportFilterPipeline filterWithFilters:
[KSCrashReportFilterAlert
filterWithTitle:NSLocalizedString(@"Crash Detected", @"Crash reporting")
message:NSLocalizedString(@"The app crashed last time it was launched. Send a crash report? This crash report will contain privacy related data. We will only use it to debug your crash and delete it afterwards!", @"Crash reporting")
yesAnswer:NSLocalizedString(@"Sure, send it!", @"Crash reporting")
noAnswer:NSLocalizedString(@"No, thanks", @"Crash reporting")
],
[KSCrashReportFilterAlert filter],
[KSCrashReportFilterCombine filterWithFiltersAndKeys:
dummyFilter, dummyFilterName, //this dummy is needed to make the filter framework print the title of our aux data
auxInfoFilter, auxInfoName,
Expand All @@ -84,7 +82,7 @@ +(void) reportPendingCrashesWithViewController:(UIViewController*) viewControlle
],
[KSCrashReportFilterStringToData filter],
[KSCrashReportFilterGZipCompress filterWithCompressionLevel:-1],
[[self alloc] initWithViewController:viewController], //this is the last filter sending out all stuff via mail
[[self alloc] init], //this is the last filter sending out all stuff via mail
nil
];
DDLogVerbose(@"Trying to send crash reports...");
Expand All @@ -96,13 +94,6 @@ +(void) reportPendingCrashesWithViewController:(UIViewController*) viewControlle
}];
}

-(id) initWithViewController:(UIViewController*) viewController
{
self = [super init];
self.viewController = viewController;
return self;
}

-(void) filterReports:(NSArray*) reports onCompletion:(KSCrashReportFilterCompletion) onCompletion
{
if(![MFMailComposeViewController canSendMail])
Expand Down Expand Up @@ -133,7 +124,7 @@ -(void) filterReports:(NSArray*) reports onCompletion:(KSCrashReportFilterComple
style:UIAlertActionStyleDefault
handler:nil];
[alertController addAction:okAction];
[self.viewController presentViewController:alertController animated:YES completion:NULL];
[[(MonalAppDelegate*)[[UIApplication sharedApplication] delegate] getTopViewController] presentViewController:alertController animated:YES completion:NULL];

kscrash_callCompletion(onCompletion, reports, NO,
[NSError errorWithDomain:[[self class] description]
Expand Down Expand Up @@ -164,14 +155,14 @@ -(void) filterReports:(NSArray*) reports onCompletion:(KSCrashReportFilterComple

dispatch_async(dispatch_get_main_queue(), ^{
DDLogVerbose(@"Presenting MFMailComposeViewController...");
[self.viewController presentViewController:mailController animated:YES completion:nil];
[[(MonalAppDelegate*)[[UIApplication sharedApplication] delegate] getTopViewController] presentViewController:mailController animated:YES completion:nil];
});
}

-(void) mailComposeController:(__unused MFMailComposeViewController*) mailController didFinishWithResult:(MFMailComposeResult) result error:(NSError*) error
{
dispatch_async(dispatch_get_main_queue(), ^{
[self.viewController dismissViewControllerAnimated:YES completion:nil];
[[(MonalAppDelegate*)[[UIApplication sharedApplication] delegate] getTopViewController] dismissViewControllerAnimated:YES completion:nil];

if(self.kscrashCompletion == nil)
{
Expand Down Expand Up @@ -217,9 +208,41 @@ -(void) mailComposeController:(__unused MFMailComposeViewController*) mailContro

@end

@implementation KSCrashReportFilterAlert

+(instancetype) filter
{
return [[self alloc] init];
}

-(void) filterReports:(NSArray*) reports onCompletion:(KSCrashReportFilterCompletion) onCompletion
{
NSString* title = NSLocalizedString(@"Crash Detected", @"Crash reporting");
NSString* message = NSLocalizedString(@"The app crashed last time it was launched. Send a crash report? This crash report will contain privacy related data. We will only use it to debug your crash and delete it afterwards!", @"Crash reporting");
NSString* yesAnswer = NSLocalizedString(@"Sure, send it!", @"Crash reporting");
NSString* noAnswer = NSLocalizedString(@"No, thanks", @"Crash reporting");

DDLogVerbose(@"KSCrashReportFilterAlert started...");
dispatch_async(dispatch_get_main_queue(), ^{
UIAlertController* alertController = [UIAlertController alertControllerWithTitle:title message:message preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction* yesAction = [UIAlertAction actionWithTitle:yesAnswer style:UIAlertActionStyleDefault handler:^(__unused UIAlertAction* _Nonnull action) {
kscrash_callCompletion(onCompletion, reports, YES, nil);
}];
UIAlertAction* noAction = [UIAlertAction actionWithTitle:noAnswer style:UIAlertActionStyleCancel handler:^(__unused UIAlertAction* _Nonnull action) {
kscrash_callCompletion(onCompletion, reports, NO, nil);
}];
[alertController addAction:yesAction];
[alertController addAction:noAction];
[[(MonalAppDelegate*)[[UIApplication sharedApplication] delegate] getTopViewController] presentViewController:alertController animated:YES completion:NULL];
});
DDLogVerbose(@"KSCrashReportFilterAlert finished...");
}

@end

@implementation KSCrashReportFilterEmpty

+(KSCrashReportFilterEmpty*) filter
+(instancetype) filter
{
return [[self alloc] init];
}
Expand All @@ -238,7 +261,7 @@ -(void) filterReports:(NSArray*) reports onCompletion:(KSCrashReportFilterComple

@implementation KSCrashReportFilterAddAuxInfo

+(KSCrashReportFilterAddAuxInfo*) filter
+(instancetype) filter
{
return [[self alloc] init];
}
Expand Down Expand Up @@ -281,7 +304,7 @@ -(void) filterReports:(NSArray*) reports onCompletion:(KSCrashReportFilterComple

@implementation KSCrashReportFilterAddMLLogfile

+(KSCrashReportFilterAddMLLogfile*) filter
+(instancetype) filter
{
return [[self alloc] init];
}
Expand Down
2 changes: 1 addition & 1 deletion Monal/Classes/MonalAppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -676,7 +676,7 @@ -(void) applicationDidBecomeActive:(UIApplication*) application
}

//report pending crashes
[MLCrashReporter reportPendingCrashesWithViewController:[self getTopViewController]];
[MLCrashReporter reportPendingCrashes];
}

-(void) setActiveChats:(UIViewController*) activeChats
Expand Down
2 changes: 1 addition & 1 deletion Monal/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def monalxmpp
pod 'ASN1Decoder'
#pod 'GoogleWebRTC'
pod 'WebRTC-lib'
pod 'KSCrash', git: 'https://github.com/monal-im/KSCrash', branch: 'master'
pod 'KSCrash', subspecs:['Recording', 'Reporting/Filters/Sets', 'Reporting/Filters/Tools', 'Reporting/Tools', 'Core']
signalDeps
end

Expand Down
58 changes: 14 additions & 44 deletions Monal/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,11 @@ PODS:
- ASN1Decoder (1.9.0)
- DZNEmptyDataSet (1.8.1)
- FLAnimatedImage (1.0.17)
- KSCrash (1.16.2):
- KSCrash/Installations (= 1.16.2)
- KSCrash/Installations (1.16.2):
- KSCrash/Recording
- KSCrash/Reporting
- KSCrash/Core (1.16.2):
- KSCrash/Reporting/Filters/Basic
- KSCrash/Recording (1.16.2):
- KSCrash/Recording/Tools (= 1.16.2)
- KSCrash/Recording/Tools (1.16.2)
- KSCrash/Reporting (1.16.2):
- KSCrash/Recording
- KSCrash/Reporting/Filters (= 1.16.2)
- KSCrash/Reporting/MessageUI (= 1.16.2)
- KSCrash/Reporting/Sinks (= 1.16.2)
- KSCrash/Reporting/Tools (= 1.16.2)
- KSCrash/Reporting/Filters (1.16.2):
- KSCrash/Recording
- KSCrash/Reporting/Filters/Alert (= 1.16.2)
- KSCrash/Reporting/Filters/AppleFmt (= 1.16.2)
- KSCrash/Reporting/Filters/Base (= 1.16.2)
- KSCrash/Reporting/Filters/Basic (= 1.16.2)
- KSCrash/Reporting/Filters/GZip (= 1.16.2)
- KSCrash/Reporting/Filters/JSON (= 1.16.2)
- KSCrash/Reporting/Filters/Sets (= 1.16.2)
- KSCrash/Reporting/Filters/Stringify (= 1.16.2)
- KSCrash/Reporting/Filters/Tools (= 1.16.2)
- KSCrash/Reporting/Filters/Alert (1.16.2):
- KSCrash/Recording
- KSCrash/Reporting/Filters/Base
- KSCrash/Reporting/Filters/AppleFmt (1.16.2):
- KSCrash/Recording
- KSCrash/Reporting/Filters/Base
Expand Down Expand Up @@ -57,12 +34,6 @@ PODS:
- KSCrash/Reporting/Filters/Base
- KSCrash/Reporting/Filters/Tools (1.16.2):
- KSCrash/Recording
- KSCrash/Reporting/MessageUI (1.16.2):
- KSCrash/Recording
- KSCrash/Reporting/Sinks (1.16.2):
- KSCrash/Recording
- KSCrash/Reporting/Filters
- KSCrash/Reporting/Tools
- KSCrash/Reporting/Tools (1.16.2):
- KSCrash/Recording
- MarqueeLabel (4.3.2)
Expand All @@ -71,9 +42,9 @@ PODS:
- MarqueeLabel (~> 4.3.0)
- SnapKit (~> 5.6.0)
- SAMKeychain (1.5.3)
- SDWebImage (5.18.6):
- SDWebImage/Core (= 5.18.6)
- SDWebImage/Core (5.18.6)
- SDWebImage (5.18.7):
- SDWebImage/Core (= 5.18.7)
- SDWebImage/Core (5.18.7)
- SignalProtocolC (2.3.3)
- SignalProtocolObjC (1.1.1):
- SignalProtocolC (~> 2.3.3)
Expand All @@ -88,7 +59,11 @@ DEPENDENCIES:
- ASN1Decoder
- DZNEmptyDataSet
- FLAnimatedImage (~> 1.0)
- KSCrash (from `https://github.com/monal-im/KSCrash`, branch `master`)
- KSCrash/Core
- KSCrash/Recording
- KSCrash/Reporting/Filters/Sets
- KSCrash/Reporting/Filters/Tools
- KSCrash/Reporting/Tools
- MBProgressHUD (~> 1.2.0)
- NotificationBannerSwift (~> 3.2.0)
- SAMKeychain
Expand All @@ -104,6 +79,7 @@ SPEC REPOS:
- ASN1Decoder
- DZNEmptyDataSet
- FLAnimatedImage
- KSCrash
- MarqueeLabel
- MBProgressHUD
- NotificationBannerSwift
Expand All @@ -115,9 +91,6 @@ SPEC REPOS:
- WebRTC-lib

EXTERNAL SOURCES:
KSCrash:
:branch: master
:git: https://github.com/monal-im/KSCrash
SignalProtocolC:
:branch: master
:git: https://github.com/monal-im/libsignal-protocol-c
Expand All @@ -126,9 +99,6 @@ EXTERNAL SOURCES:
:git: https://github.com/monal-im/SignalProtocol-ObjC.git

CHECKOUT OPTIONS:
KSCrash:
:commit: c7ba6e1cb2a548cb108d3536027e36a6e12670cb
:git: https://github.com/monal-im/KSCrash
SignalProtocolC:
:commit: 560504888d9c0ba4be860275d206dcef07e0761e
:git: https://github.com/monal-im/libsignal-protocol-c
Expand All @@ -140,19 +110,19 @@ SPEC CHECKSUMS:
ASN1Decoder: 4f4bbcaf1d1b8be56daa3280e82863a607f5bda9
DZNEmptyDataSet: 9525833b9e68ac21c30253e1d3d7076cc828eaa7
FLAnimatedImage: bbf914596368867157cc71b38a8ec834b3eeb32b
KSCrash: 95066f51c72849faaa7d8d57f300416ee4e5df52
KSCrash: 469b9f982b97309acb719baaecbf9182f62ddf85
MarqueeLabel: 15e524a6762552bb279cb17438b8a94990269fb9
MBProgressHUD: 3ee5efcc380f6a79a7cc9b363dd669c5e1ae7406
NotificationBannerSwift: dce54ded532b26e30cd8e7f4d80e124a0f2ba7d1
SAMKeychain: 483e1c9f32984d50ca961e26818a534283b4cd5c
SDWebImage: 3d8caa2430f3d674dbb3e515df4a100a2105af5f
SDWebImage: f9258c58221ed854cfa0e2b80ee4033710b1c6d3
SignalProtocolC: 8092866e45b663a6bc3e45a8d13bad2571dbf236
SignalProtocolObjC: 1beb46b1d35733e7ab96a919f88bac20ec771c73
SnapKit: e01d52ebb8ddbc333eefe2132acf85c8227d9c25
sqlite3: 6e2d4a4879854d0ec86b476bf3c3e30870bac273
TOCropViewController: edfd4f25713d56905ad1e0b9f5be3fbe0f59c863
WebRTC-lib: bd0d4b76aab1492415216715bd02f4329a33cd10

PODFILE CHECKSUM: 99af97fbdbc651c2f1c5558cb9ba7107ef30aa28
PODFILE CHECKSUM: f415f317e34fd11a687374f84ee8dfb14ebb29a6

COCOAPODS: 1.14.3

0 comments on commit 9f06cae

Please sign in to comment.