2016-09-12 01:21:14 +01:00
|
|
|
//
|
|
|
|
// AppDelegate.m
|
|
|
|
// Test Application
|
|
|
|
//
|
|
|
|
// Created by Patrick Wardle on 9/10/16.
|
|
|
|
// Copyright (c) 2016 Objective-See. All rights reserved.
|
|
|
|
//
|
|
|
|
|
2016-09-13 08:27:45 +01:00
|
|
|
#import "Consts.h"
|
|
|
|
#import "Logging.h"
|
|
|
|
#import "Utilities.h"
|
2016-09-12 01:21:14 +01:00
|
|
|
#import "AppDelegate.h"
|
2016-09-13 08:27:45 +01:00
|
|
|
|
2016-09-12 01:21:14 +01:00
|
|
|
|
|
|
|
@interface AppDelegate ()
|
|
|
|
|
|
|
|
@property (weak) IBOutlet NSWindow *window;
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation AppDelegate
|
|
|
|
|
2016-09-13 08:27:45 +01:00
|
|
|
@synthesize infoWindowController;
|
|
|
|
@synthesize aboutWindowController;
|
|
|
|
|
|
|
|
//center window
|
|
|
|
// ->also make front, init title bar, etc
|
|
|
|
-(void)awakeFromNib
|
2016-09-12 01:21:14 +01:00
|
|
|
{
|
2016-09-13 08:27:45 +01:00
|
|
|
//center
|
|
|
|
[self.window center];
|
|
|
|
|
|
|
|
//make it key window
|
|
|
|
[self.window makeKeyAndOrderFront:self];
|
|
|
|
|
|
|
|
//make window front
|
|
|
|
[NSApp activateIgnoringOtherApps:YES];
|
2016-09-12 01:21:14 +01:00
|
|
|
|
2016-09-13 08:27:45 +01:00
|
|
|
//set title
|
|
|
|
self.window.title = [NSString stringWithFormat:@"OverSight Preferences (v. %@)", getAppVersion()];
|
2016-09-12 01:21:14 +01:00
|
|
|
|
2016-09-13 08:27:45 +01:00
|
|
|
return;
|
2016-09-12 01:21:14 +01:00
|
|
|
}
|
|
|
|
|
2016-09-13 08:27:45 +01:00
|
|
|
//app interface
|
|
|
|
// ->init user interface
|
|
|
|
-(void)applicationDidFinishLaunching:(NSNotification *)aNotification
|
2016-09-12 01:21:14 +01:00
|
|
|
{
|
2016-09-13 08:27:45 +01:00
|
|
|
//set 'log activity' button state
|
|
|
|
self.logActivity.state = [[NSUserDefaults standardUserDefaults] boolForKey:LOG_ACTIVITY];
|
|
|
|
|
|
|
|
//set 'automatically check for updates' button state
|
|
|
|
self.check4Updates.state = [[NSUserDefaults standardUserDefaults] boolForKey:CHECK_4_UPDATES];
|
|
|
|
|
|
|
|
return;
|
2016-09-12 01:21:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//automatically close when user closes window
|
2016-09-13 08:27:45 +01:00
|
|
|
-(BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication *)theApplication
|
2016-09-12 01:21:14 +01:00
|
|
|
{
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
2016-09-13 08:27:45 +01:00
|
|
|
//toggle/set preferences
|
|
|
|
-(IBAction)togglePreference:(NSButton *)sender
|
|
|
|
{
|
|
|
|
//set 'log activity' button
|
|
|
|
if(sender == self.logActivity)
|
|
|
|
{
|
|
|
|
//set
|
|
|
|
[[NSUserDefaults standardUserDefaults] setBool:[sender state] forKey:LOG_ACTIVITY];
|
|
|
|
}
|
|
|
|
|
|
|
|
//set 'automatically check for updates'
|
|
|
|
else if (sender == self.check4Updates)
|
|
|
|
{
|
|
|
|
//set
|
|
|
|
[[NSUserDefaults standardUserDefaults] setBool:[sender state] forKey:CHECK_4_UPDATES];
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
//'about' button handler
|
|
|
|
-(IBAction)about:(id)sender
|
2016-09-12 01:21:14 +01:00
|
|
|
{
|
2016-09-13 08:27:45 +01:00
|
|
|
//alloc/init settings window
|
|
|
|
if(nil == self.aboutWindowController)
|
|
|
|
{
|
|
|
|
//alloc/init
|
|
|
|
aboutWindowController = [[AboutWindowController alloc] initWithWindowNibName:@"AboutWindow"];
|
2016-09-12 01:21:14 +01:00
|
|
|
}
|
|
|
|
|
2016-09-13 08:27:45 +01:00
|
|
|
//center window
|
|
|
|
[[self.aboutWindowController window] center];
|
|
|
|
|
|
|
|
//show it
|
|
|
|
[self.aboutWindowController showWindow:self];
|
|
|
|
|
|
|
|
//invoke function in background that will make window modal
|
|
|
|
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
|
|
|
|
|
|
|
|
//make modal
|
|
|
|
makeModal(self.aboutWindowController);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
2016-09-12 01:21:14 +01:00
|
|
|
}
|
|
|
|
|
2016-09-13 08:27:45 +01:00
|
|
|
//'check for update' (now) button handler
|
|
|
|
-(IBAction)check4Update:(id)sender
|
|
|
|
{
|
|
|
|
//disable button
|
|
|
|
self.check4UpdatesNow.enabled = NO;
|
|
|
|
|
|
|
|
//hide version msg
|
|
|
|
self.versionLabel.hidden = YES;
|
|
|
|
|
|
|
|
//show spinner
|
|
|
|
[self.spinner startAnimation:self];
|
|
|
|
|
|
|
|
//check for update
|
|
|
|
[self isThereAndUpdate];
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
//check for an update
|
|
|
|
-(void)isThereAndUpdate
|
|
|
|
{
|
|
|
|
//version string
|
|
|
|
NSMutableString* versionString = nil;
|
|
|
|
|
|
|
|
//alloc string
|
|
|
|
versionString = [NSMutableString string];
|
|
|
|
|
|
|
|
//check if available version is newer
|
|
|
|
// ->show update window
|
|
|
|
if(YES == isNewVersion(versionString))
|
|
|
|
{
|
|
|
|
//dbg msg
|
|
|
|
logMsg(LOG_DEBUG, [NSString stringWithFormat:@"a new version (%@) is available", versionString]);
|
|
|
|
|
|
|
|
//alloc/init about window
|
|
|
|
infoWindowController = [[InfoWindowController alloc] initWithWindowNibName:@"InfoWindow"];
|
|
|
|
|
|
|
|
//configure
|
|
|
|
[self.infoWindowController configure:[NSString stringWithFormat:@"a new version (%@) is available!", versionString] buttonTitle:@"update"];
|
|
|
|
|
|
|
|
//center window
|
|
|
|
[[self.infoWindowController window] center];
|
|
|
|
|
|
|
|
//show it
|
|
|
|
[self.infoWindowController showWindow:self];
|
|
|
|
|
|
|
|
//invoke function in background that will make window modal
|
|
|
|
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
|
|
|
|
|
|
|
|
//make modal
|
|
|
|
makeModal(self.infoWindowController);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
//stop/hide spinner
|
|
|
|
[self.spinner stopAnimation:self];
|
|
|
|
|
|
|
|
//re-enable button
|
|
|
|
self.check4UpdatesNow.enabled = YES;
|
|
|
|
}
|
|
|
|
|
|
|
|
//no new version
|
|
|
|
// ->just (debug) log msg
|
|
|
|
else
|
|
|
|
{
|
|
|
|
//dbg msg
|
|
|
|
logMsg(LOG_DEBUG, @"no updates available");
|
|
|
|
|
|
|
|
//stop/hide spinner
|
|
|
|
[self.spinner stopAnimation:self];
|
|
|
|
|
|
|
|
//re-enable button
|
|
|
|
self.check4UpdatesNow.enabled = YES;
|
|
|
|
|
|
|
|
//show now new version message
|
|
|
|
self.versionLabel.hidden = NO;
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-09-12 01:21:14 +01:00
|
|
|
@end
|