Skip to content

Commit

Permalink
fix for #34
Browse files Browse the repository at this point in the history
and UI improvements
  • Loading branch information
objective-see committed Dec 11, 2024
1 parent 6e8078b commit 3c5f5ce
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 3 deletions.
1 change: 1 addition & 0 deletions AppDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#import "ResultsWindowController.h"

#import <Cocoa/Cocoa.h>
#import <OSLog/OSLog.h>

/* GLOBALS */

Expand Down
26 changes: 26 additions & 0 deletions AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,29 @@ @implementation AppDelegate
@synthesize categoryTableController;
@synthesize resultsWindowController;

//exception handler
// show alert and log error
void uncaughtExceptionHandler(NSException* exception) {

//alert
NSAlert* alert = nil;

//alloc/init alert
alert = [NSAlert alertWithMessageText:NSLocalizedString(@"ERROR:\nKnockKnock Encountered a Fatal Error", @"KnockKnock Encountered a Fatal Error") defaultButton:@"OK" alternateButton:nil otherButton:nil informativeTextWithFormat:NSLocalizedString(@"Exception: %@",@"Exception: %@"), exception];

//show it
[alert runModal];

//log
os_log_error(OS_LOG_DEFAULT, "KnockKnock crash: %{public}@", exception);
os_log_error(OS_LOG_DEFAULT, "KnockKnock crash (stack trace): %{public}@", [exception callStackSymbols]);

//bye
exit(EXIT_FAILURE);

return;
}

//center window
// also make front
-(void)awakeFromNib
Expand All @@ -57,6 +80,9 @@ -(void)applicationDidFinishLaunching:(NSNotification *)notification
//defaults
NSUserDefaults* defaults = nil;

//set exception handler
NSSetUncaughtExceptionHandler(&uncaughtExceptionHandler);

//init filter object
itemFilter = [[Filter alloc] init];

Expand Down
13 changes: 13 additions & 0 deletions Localizable.xcstrings
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,9 @@
}
}
},
"ERROR:\nKnockKnock Encountered a Fatal Error" : {
"comment" : "KnockKnock Encountered a Fatal Error"
},
"ERROR:\nVirusTotal query for '%@' failed" : {
"comment" : "ERROR:\nVirusTotal query for '%@' failed",
"localizations" : {
Expand Down Expand Up @@ -221,6 +224,9 @@
}
}
},
"Exception: %@" : {
"comment" : "Exception: %@"
},
"extensions hosted in the browser" : {
"comment" : "extensions hosted in the browser",
"localizations" : {
Expand Down Expand Up @@ -526,6 +532,7 @@
},
"Submissions complete, though errors were encountered (HTTP response(s): %@)." : {
"comment" : "Submissions complete, though errors were encountered (HTTP response(s): %@).",
"extractionState" : "stale",
"localizations" : {
"es" : {
"stringUnit" : {
Expand All @@ -535,6 +542,9 @@
}
}
},
"Submissions complete, though errors were encountered.\r\n(HTTP response(s): %@)." : {
"comment" : "Submissions complete, though errors were encountered.\r\n(HTTP response(s): %@)."
},
"Submissions complete. (In subsequent scans item's VT detection ratios will now be displayed)." : {
"comment" : "Submissions complete. (In subsequent scans item's VT detection ratios will now be displayed).",
"localizations" : {
Expand Down Expand Up @@ -645,6 +655,9 @@
}
}
},
"VirusTotal Results: Disabled" : {
"comment" : "VirusTotal Results: Disabled"
},
"VirusTotal:\r\n %lu flagged item(s)\r\n %lu unknown item(s)" : {
"comment" : "VirusTotal:\r\n %lu flagged item(s)\r\n %lu unknown item(s)",
"localizations" : {
Expand Down
32 changes: 29 additions & 3 deletions ResultsWindowController.m
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,25 @@ -(void)windowDidLoad
//set details
self.detailsLabel.stringValue = self.details;

//set unknown items
self.vtDetailsLabel.stringValue = self.vtDetails;
//set VT results
if(nil != self.vtDetails)
{
//set
self.vtDetailsLabel.stringValue = self.vtDetails;
}
//no VT results
// disabled? something else?
else
{
if(YES == ((AppDelegate*)[[NSApplication sharedApplication] delegate]).prefsWindowController.disableVTQueries)
{
self.vtDetailsLabel.stringValue = NSLocalizedString(@"VirusTotal Results: Disabled", @"VirusTotal Results: Disabled");
}
else
{
self.vtDetailsLabel.stringValue = @"VirusTotal: ?";
}
}

//toggle 'Submit' button
self.submitToVT.hidden = !(self.unknownItems.count);
Expand Down Expand Up @@ -87,6 +104,9 @@ -(IBAction)submitToVT:(id)sender
//update UI now that submission is done
-(void)submissionComplete:(NSUInteger)successes httpResponses:(NSMutableArray*)httpResponses
{
//unique responses
NSSet* uniqueResponses = nil;

//enable close
self.closeButton.enabled = YES;

Expand All @@ -101,10 +121,16 @@ -(void)submissionComplete:(NSUInteger)successes httpResponses:(NSMutableArray*)h
}
else
{
//get just unique responses
uniqueResponses = [NSSet setWithArray:httpResponses];

//update message
self.submissionStatus.stringValue = [NSString stringWithFormat:NSLocalizedString(@"Submissions complete, though errors were encountered (HTTP response(s): %@).", @"Submissions complete, though errors were encountered (HTTP response(s): %@)."), [httpResponses componentsJoinedByString:@","]];
self.submissionStatus.stringValue = [NSString stringWithFormat:NSLocalizedString(@"Submissions complete, though errors were encountered.\r\n(HTTP response(s): %@)", @"Submissions complete, though errors were encountered.\r\n(HTTP response(s): %@)"), [[uniqueResponses allObjects] componentsJoinedByString:@","]];
}

//then make action button first responder
[self.window makeFirstResponder:self.closeButton];

return;
}

Expand Down

0 comments on commit 3c5f5ce

Please sign in to comment.