Permalink
Browse files

added support for sending crash reports automatically

  • Loading branch information...
vemedio authored and TheRealKerni committed Dec 16, 2011
1 parent 3cb486e commit a86314525fdc77e3bb4d475be15bc700cb240137
Showing with 76 additions and 36 deletions.
  1. +12 −1 client/Mac/BWQuincyManager.h
  2. +64 −35 client/Mac/BWQuincyManager.m
@@ -104,6 +104,11 @@ typedef enum CrashReportStatus {
@optional
+// Return the description the crashreport should contain, empty by default. The string will automatically be wrapped into <[DATA[ ]]>, so make sure you don't do that in your string.
+-(NSString *) crashReportDescription;
+
+@optional
+
// Return the userid the crashreport should contain, empty by default
-(NSString *) crashReportUserID;
@@ -127,6 +132,7 @@ typedef enum CrashReportStatus {
NSString *_submissionURL;
NSString *_companyName;
NSString *_appIdentifier;
+ BOOL _autoSubmitCrashReport;
NSString *_crashFile;
@@ -146,6 +152,10 @@ typedef enum CrashReportStatus {
// delegate is required
@property (nonatomic, assign) id <BWQuincyManagerDelegate> delegate;
+// if YES, the crash report will be submitted without asking the user
+// if NO, the user will be asked if the crash report can be submitted (default)
+@property (nonatomic, assign, getter=isAutoSubmitCrashReport) BOOL autoSubmitCrashReport;
+
///////////////////////////////////////////////////////////////////////////////////////////////////
// settings
@@ -154,7 +164,8 @@ typedef enum CrashReportStatus {
- (void) cancelReport;
-- (void) sendReport:(NSString *)xml;
+- (void) sendReportCrash:(NSString*)crashContent
+ description:(NSString*)description;
- (NSString *) applicationName;
- (NSString *) applicationVersionString;
@@ -53,6 +53,7 @@ @implementation BWQuincyManager
@synthesize submissionURL = _submissionURL;
@synthesize companyName = _companyName;
@synthesize appIdentifier = _appIdentifier;
+@synthesize autoSubmitCrashReport = _autoSubmitCrashReport;
+ (BWQuincyManager *)sharedQuincyManager {
static BWQuincyManager *quincyManager = nil;
@@ -185,11 +186,31 @@ - (void) returnToMainApplication {
}
- (void) startManager {
- if ([self hasPendingCrashReport]) {
-
- _quincyUI = [[BWQuincyUI alloc] init:self crashFile:_crashFile companyName:_companyName applicationName:[self applicationName]];
- [_quincyUI askCrashReportDetails];
- } else {
+ if ([self hasPendingCrashReport])
+ {
+ if (!self.autoSubmitCrashReport) {
+ _quincyUI = [[BWQuincyUI alloc] init:self crashFile:_crashFile companyName:_companyName applicationName:[self applicationName]];
+ [_quincyUI askCrashReportDetails];
+ }
+ else
+ {
+ NSError* error = nil;
+ NSString *crashLogs = [NSString stringWithContentsOfFile:_crashFile encoding:NSUTF8StringEncoding error:&error];
+ if (!error)
+ {
+ NSString *lastCrash = [[crashLogs componentsSeparatedByString: @"**********\n\n"] lastObject];
+
+ NSString* description = @"";
+
+ if (_delegate && [_delegate respondsToSelector:@selector(crashReportDescription)]) {
+ description = [_delegate crashReportDescription];
+ }
+
+ [self sendReportCrash:lastCrash description:description];
+ }
+ }
+ }
+ else {
[self returnToMainApplication];
}
}
@@ -229,11 +250,34 @@ - (void) cancelReport {
}
-- (void) sendReport:(NSString *)xml {
- [self returnToMainApplication];
+- (void) sendReportCrash:(NSString*)crashContent
+ description:(NSString*)notes
+{
+ NSString *userid = @"";
+ NSString *contact = @"";
+
+ SInt32 versionMajor, versionMinor, versionBugFix;
+ if (Gestalt(gestaltSystemVersionMajor, &versionMajor) != noErr) versionMajor = 0;
+ if (Gestalt(gestaltSystemVersionMinor, &versionMinor) != noErr) versionMinor= 0;
+ if (Gestalt(gestaltSystemVersionBugFix, &versionBugFix) != noErr) versionBugFix = 0;
+
+ NSString* xml = [[NSString stringWithFormat:@"<crash><applicationname>%s</applicationname><bundleidentifier>%s</bundleidentifier><systemversion>%@</systemversion><senderversion>%@</senderversion><version>%@</version><platform>%@</platform><userid>%@</userid><contact>%@</contact><description><![CDATA[%@]]></description><log><![CDATA[%@]]></log></crash>",
+ [[self applicationName] UTF8String],
+ [[[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleIdentifier"] UTF8String],
+ [NSString stringWithFormat:@"%i.%i.%i", versionMajor, versionMinor, versionBugFix],
+ [self applicationVersion],
+ [self applicationVersion],
+ [self modelVersion],
+ userid,
+ contact,
+ notes,
+ crashContent
+ ] retain];
+
+
+ [self returnToMainApplication];
- [self _postXML:[NSString stringWithFormat:@"<crashes>%@</crashes>", xml]
- toURL:[NSURL URLWithString:self.submissionURL]];
+ [self _postXML:[NSString stringWithFormat:@"<crashes>%@</crashes>", xml] toURL:[NSURL URLWithString:self.submissionURL]];
}
- (void)_postXML:(NSString*)xml toURL:(NSURL*)url {
@@ -460,40 +504,25 @@ - (IBAction) cancelReport:(id)sender {
[_delegate cancelReport];
}
+- (void) _sendReportAfterDelay
+{
+ if ( _delegate != nil && [_delegate respondsToSelector:@selector(sendReport:)])
+ {
+ NSString *notes = [NSString stringWithFormat:@"Comments:\n%@\n\nConsole:\n%@", [descriptionTextField stringValue], _consoleContent];
+
+ [_delegate sendReportCrash:_crashLogContent description:notes];
+ }
+}
- (IBAction) submitReport:(id)sender {
[submitButton setEnabled:NO];
[[self window] makeFirstResponder: nil];
- NSString *userid = @"";
- NSString *contact = @"";
-
- NSString *notes = [NSString stringWithFormat:@"Comments:\n%@\n\nConsole:\n%@", [descriptionTextField stringValue], _consoleContent];
-
- SInt32 versionMajor, versionMinor, versionBugFix;
- if (Gestalt(gestaltSystemVersionMajor, &versionMajor) != noErr) versionMajor = 0;
- if (Gestalt(gestaltSystemVersionMinor, &versionMinor) != noErr) versionMinor= 0;
- if (Gestalt(gestaltSystemVersionBugFix, &versionBugFix) != noErr) versionBugFix = 0;
-
- _xml = [[NSString stringWithFormat:@"<crash><applicationname>%s</applicationname><bundleidentifier>%s</bundleidentifier><systemversion>%@</systemversion><senderversion>%@</senderversion><version>%@</version><platform>%@</platform><userid>%@</userid><contact>%@</contact><description><![CDATA[%@]]></description><log><![CDATA[%@]]></log></crash>",
- [[_delegate applicationName] UTF8String],
- [[[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleIdentifier"] UTF8String],
- [NSString stringWithFormat:@"%i.%i.%i", versionMajor, versionMinor, versionBugFix],
- [_delegate applicationVersion],
- [_delegate applicationVersion],
- [_delegate modelVersion],
- userid,
- contact,
- notes,
- _crashLogContent
- ] retain];
-
+ [self performSelector:@selector(_sendReportAfterDelay) withObject:nil afterDelay:0.01];
+
[self endCrashReporter];
[NSApp stopModal];
-
- if ( _delegate != nil && [_delegate respondsToSelector:@selector(sendReport:)])
- [_delegate performSelector:@selector(sendReport:) withObject:_xml afterDelay:0.01];
}

0 comments on commit a863145

Please sign in to comment.