Permalink
Browse files

Add first-time tutorial + import common sites

  • Loading branch information...
1 parent 8824568 commit db244705ba2a5b215b0db14c17582e891983df24 @cstigler cstigler committed Oct 11, 2014
View
@@ -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;
View
@@ -27,7 +27,9 @@
NSString* const kSelfControlErrorDomain = @"SelfControlErrorDomain";
-@implementation AppController
+@implementation AppController {
+ NSWindowController* getStartedWindowController;
+}
@synthesize addingBlock;
@@ -52,7 +54,8 @@ - (AppController*) init {
@"AllowLocalNetworks": @YES,
@"MaxBlockLength": @1440,
@"BlockLengthInterval": @15,
- @"WhitelistAlertSuppress": @NO};
+ @"WhitelistAlertSuppress": @NO,
+ @"GetStartedShown": @NO};
[defaults_ registerDefaults:appDefaults];
@@ -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];
}
@@ -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];
@@ -453,7 +471,6 @@ - (void)dealloc {
object: nil];
}
-// @synthesize initialWindow = initialWindow_;
- (id)initialWindow {
return initialWindow_;
}
View
@@ -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
@@ -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) {
@@ -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,
@@ -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]])
@@ -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
Oops, something went wrong.

0 comments on commit db24470

Please sign in to comment.