Skip to content

Commit

Permalink
Add first-time tutorial + import common sites
Browse files Browse the repository at this point in the history
  • Loading branch information
cstigler committed Oct 11, 2014
1 parent 8824568 commit db24470
Show file tree
Hide file tree
Showing 31 changed files with 1,578 additions and 112 deletions.
2 changes: 2 additions & 0 deletions AppController.h
Expand Up @@ -125,6 +125,8 @@
// open preferences panel
- (IBAction)openPreferences:(id)sender;

- (IBAction)showGetStartedWindow:(id)sender;

// Opens a save panel and saves the blocklist.
- (IBAction)save:(id)sender;

Expand Down
23 changes: 20 additions & 3 deletions AppController.m
Expand Up @@ -27,7 +27,9 @@

NSString* const kSelfControlErrorDomain = @"SelfControlErrorDomain";

@implementation AppController
@implementation AppController {
NSWindowController* getStartedWindowController;
}

@synthesize addingBlock;

Expand All @@ -52,7 +54,8 @@ - (AppController*) init {
@"AllowLocalNetworks": @YES,
@"MaxBlockLength": @1440,
@"BlockLengthInterval": @15,
@"WhitelistAlertSuppress": @NO};
@"WhitelistAlertSuppress": @NO,
@"GetStartedShown": @NO};

[defaults_ registerDefaults:appDefaults];

Expand Down Expand Up @@ -228,6 +231,12 @@ - (void)refreshUserInterface {
[editBlacklistButton_ setEnabled: NO];
[submitButton_ setTitle: NSLocalizedString(@"Loading", @"Loading button")];
}

// if block's off, and we haven't shown it yet, show the first-time modal
if (![defaults_ boolForKey: @"GetStartedShown"]) {
[self showGetStartedWindow: self];
[defaults_ setBool: YES forKey: @"GetStartedShown"];
}
}
[refreshUILock_ unlock];
}
Expand Down Expand Up @@ -257,6 +266,15 @@ - (IBAction)openPreferences:(id)sender {
[preferencesWindowController_ showWindow: nil];
}

- (IBAction)showGetStartedWindow:(id)sender {
if (!getStartedWindowController) {
getStartedWindowController = [[NSWindowController alloc] initWithWindowNibName: @"FirstTime"];
}
[getStartedWindowController.window center];
[getStartedWindowController.window makeKeyAndOrderFront: nil];
[getStartedWindowController showWindow: nil];
}

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
[NSApp setDelegate: self];

Expand Down Expand Up @@ -453,7 +471,6 @@ - (void)dealloc {
object: nil];
}

// @synthesize initialWindow = initialWindow_;
- (id)initialWindow {
return initialWindow_;
}
Expand Down
5 changes: 4 additions & 1 deletion BlockManager.m
Expand Up @@ -259,7 +259,7 @@ - (NSArray*)commonSubdomainsForHostName:(NSString*)hostName {
// If the domain ends in facebook.com... Special case for Facebook because
// users will often forget to block some of its many mirror subdomains that resolve
// to different IPs, i.e. hs.facebook.com. Thanks to Danielle for raising this issue.
if([hostName rangeOfString: @"facebook.com"].location == ([hostName length] - 12)) {
if([hostName hasSuffix: @"facebook.com"]) {
// pulled list of facebook IP ranges from https://developers.facebook.com/docs/ApplicationSecurity/#facebook_scraper
// TODO: pull these automatically by running:
// whois -h whois.radb.net -- '-i origin AS32934' | grep ^route
Expand All @@ -275,6 +275,9 @@ - (NSArray*)commonSubdomainsForHostName:(NSString*)hostName {

[newHosts addObjectsFromArray: facebookIPs];
}
if ([hostName hasSuffix: @"twitter.com"]) {
[newHosts addObject: @"api.twitter.com"];
}

// Block the domain with no subdomains, if www.domain is blocked
if([hostName rangeOfString: @"www."].location == 0) {
Expand Down
3 changes: 3 additions & 0 deletions DomainListWindowController.h
Expand Up @@ -72,6 +72,9 @@
forTableColumn:(NSTableColumn *)tableColumn
row:(int)row;

- (IBAction)importCommonDistractingWebsites:(id)sender;
- (IBAction)importNewsAndPublications:(id)sender;

// Called when the button-menu item is clicked to import all incoming mail
// servers from Thunderbird. Adds to the domain list array all incoming mail
// servers from the Thunderbird default profile that haven't already been added,
Expand Down
71 changes: 15 additions & 56 deletions DomainListWindowController.m
Expand Up @@ -293,8 +293,7 @@ - (void)tableView:(NSTableView *)tableView
}
}

- (IBAction)importIncomingMailServersFromThunderbird:(id)sender {
NSArray* arr = [HostImporter incomingMailHostnamesFromThunderbird];
- (void)addHostArray:(NSArray*)arr {
for(int i = 0; i < [arr count]; i++) {
// Check for dupes
if(![domainList_ containsObject: arr[i]])
Expand All @@ -306,69 +305,29 @@ - (IBAction)importIncomingMailServersFromThunderbird:(id)sender {
object: self];
}

- (IBAction)importCommonDistractingWebsites:(id)sender {
[self addHostArray: [HostImporter commonDistractingWebsites]];
}
- (IBAction)importNewsAndPublications:(id)sender {
[self addHostArray: [HostImporter newsAndPublications]];
}
- (IBAction)importIncomingMailServersFromThunderbird:(id)sender {
[self addHostArray: [HostImporter incomingMailHostnamesFromThunderbird]];
}
- (IBAction)importOutgoingMailServersFromThunderbird:(id)sender {
NSArray* arr = [HostImporter outgoingMailHostnamesFromThunderbird];
for(int i = 0; i < [arr count]; i++) {
// Check for dupes
if(![domainList_ containsObject: arr[i]])
[domainList_ addObject: arr[i]];
}
[defaults_ setObject: domainList_ forKey: @"HostBlacklist"];
[domainListTableView_ reloadData];
[[NSNotificationCenter defaultCenter] postNotificationName: @"SCConfigurationChangedNotification"
object: self];
[self addHostArray: [HostImporter outgoingMailHostnamesFromThunderbird]];
}

- (IBAction)importIncomingMailServersFromMail:(id)sender {
NSArray* arr = [HostImporter incomingMailHostnamesFromMail];
for(int i = 0; i < [arr count]; i++) {
// Check for dupes
if(![domainList_ containsObject: arr[i]])
[domainList_ addObject: arr[i]];
}
[defaults_ setObject: domainList_ forKey: @"HostBlacklist"];
[domainListTableView_ reloadData];
[[NSNotificationCenter defaultCenter] postNotificationName: @"SCConfigurationChangedNotification"
object: self];
[self addHostArray: [HostImporter incomingMailHostnamesFromMail]];
}

- (IBAction)importOutgoingMailServersFromMail:(id)sender {
NSArray* arr = [HostImporter outgoingMailHostnamesFromMail];
for(int i = 0; i < [arr count]; i++) {
// Check for dupes
if(![domainList_ containsObject: arr[i]])
[domainList_ addObject: arr[i]];
}
[defaults_ setObject: domainList_ forKey: @"HostBlacklist"];
[domainListTableView_ reloadData];
[[NSNotificationCenter defaultCenter] postNotificationName: @"SCConfigurationChangedNotification"
object: self];
[self addHostArray: [HostImporter outgoingMailHostnamesFromMail]];
}

- (IBAction)importIncomingMailServersFromMailMate:(id)sender {
NSArray* arr = [HostImporter incomingMailHostnamesFromMailMate];
for(int i = 0; i < [arr count]; i++) {
// Check for dupes
if(![domainList_ containsObject: arr[i]])
[domainList_ addObject: arr[i]];
}
[defaults_ setObject: domainList_ forKey: @"HostBlacklist"];
[domainListTableView_ reloadData];
[[NSNotificationCenter defaultCenter] postNotificationName: @"SCConfigurationChangedNotification"
object: self];
[self addHostArray: [HostImporter incomingMailHostnamesFromMailMate]];
}

- (IBAction)importOutgoingMailServersFromMailMate:(id)sender {
NSArray* arr = [HostImporter outgoingMailHostnamesFromMailMate];
for(int i = 0; i < [arr count]; i++) {
// Check for dupes
if(![domainList_ containsObject: arr[i]])
[domainList_ addObject: arr[i]];
}
[defaults_ setObject: domainList_ forKey: @"HostBlacklist"];
[domainListTableView_ reloadData];
[[NSNotificationCenter defaultCenter] postNotificationName: @"SCConfigurationChangedNotification"
object: self];
[self addHostArray: [HostImporter outgoingMailHostnamesFromMailMate]];
}

@end

0 comments on commit db24470

Please sign in to comment.