Files
LockDown/Lockdown/ErrorWindowController.m

146 lines
3.1 KiB
Objective-C

//
// ErrorWindowController.m
// Lockdown
//
// Created by Patrick Wardle on 2/14/16 and is licensed under a Creative Commons Attribution-NonCommercial 4.0 International License.
//
#import "Consts.h"
#import "ErrorWindowController.h"
@implementation ErrorWindowController
@synthesize errorURL;
@synthesize shouldExit;
@synthesize closeButton;
//automatically called when nib is loaded
// ->center window
-(void)awakeFromNib
{
//center
[self.window center];
return;
}
//configure the object/window
-(void)configure:(NSDictionary*)errorInfo
{
//set error msg
self.errMsg.stringValue = errorInfo[KEY_ERROR_MSG];
//set error sub msg
self.errSubMsg.stringValue = errorInfo[KEY_ERROR_SUB_MSG];
//save exit
self.shouldExit = [errorInfo[KEY_ERROR_SHOULD_EXIT] boolValue];
//grab optional error url
if(nil != errorInfo[KEY_ERROR_URL])
{
//extract/convert
self.errorURL = [NSURL URLWithString:errorInfo[KEY_ERROR_URL]];
}
//when exiting
// ->change 'close' to 'exit'
if(YES == self.shouldExit)
{
//change title
self.closeButton.title = @"Exit";
}
//for fatal errors
// ->change 'Info' to 'help fix'
if(YES == [[self.errorURL absoluteString] isEqualToString:FATAL_ERROR_URL])
{
//change title
self.infoButton.title = @"Help Fix";
}
//set delegate
[self.window setDelegate:self];
return;
}
//display (show) window
-(void)display
{
//show (now configured), alert
[self showWindow:self];
//make it key window
[self.window makeKeyAndOrderFront:self];
//make window front
[NSApp activateIgnoringOtherApps:YES];
//make close button active
[self.window makeFirstResponder:closeButton];
//make white
[self.window setBackgroundColor: NSColor.whiteColor];
return;
}
//invoked when user clicks '?' (help button)
// ->open url with more info about the error(s)
-(IBAction)help:(id)sender
{
//if a url was specified
// ->use that one
if(nil != self.errorURL)
{
//open URL
// ->invokes user's default browser
[[NSWorkspace sharedWorkspace] openURL:self.errorURL];
}
//use default URL
else
{
//open URL
// ->invokes user's default browser
[[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@#errors", PRODUCT_URL]]];
}
//when error should cause an exit
// ->close window here (to trigger exit)
if(YES == self.shouldExit)
{
//close
[self.window close];
}
return;
}
//invoked when user clicks 'close'
// ->just close window
-(IBAction)close:(id)sender
{
//close
[self.window close];
return;
}
//automatically invoked when window is closing
// ->exit the app if specified...
-(void)windowWillClose:(NSNotification *)notification
{
//check if should exit process
// ->e.g. an error during install, etc
if(YES == self.shouldExit)
{
//exit
[NSApp terminate:self];
}
return;
}
@end