5 // Created by J Osborne on 2/13/13.
9 #import "KDAppDelegate.h"
10 #import "KDCirclePeer.h"
11 #import "NSArray+mapWithBlock.h"
14 #define kSecServerKeychainChangedNotification "com.apple.security.keychainchanged"
16 @implementation KDAppDelegate
18 - (void)applicationDidFinishLaunching:(NSNotification *)aNotification
20 self.stuffNotToLeak = [NSMutableArray new];
21 [self.stuffNotToLeak addObject:[[NSNotificationCenter defaultCenter] addObserverForName:kKDSecItemsUpdated object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification *note) {
22 self.itemTableTitle.title = [NSString stringWithFormat:@"All Items (%ld)", (long)[self.itemDataSource numberOfRowsInTableView:self.itemTable]];
25 [self.syncSpinner setUsesThreadedAnimation:YES];
26 [self.syncSpinner startAnimation:nil];
28 self.itemDataSource = [[KDSecItems alloc] init];
29 self.itemTable.dataSource = self.itemDataSource;
31 int notificationToken;
32 uint32_t rc = notify_register_dispatch(kSecServerKeychainChangedNotification, ¬ificationToken, dispatch_get_main_queue(), ^(int token __unused) {
33 NSLog(@"Received %s", kSecServerKeychainChangedNotification);
34 [(KDSecItems*)self.itemDataSource loadItems];
35 [self.itemTable reloadData];
37 NSAssert(rc == 0, @"Can't register for %s", kSecServerKeychainChangedNotification);
39 self.circle = [KDSecCircle new];
40 [self.circle addChangeCallback:^{
41 self.circleStatusCell.stringValue = self.circle.status;
45 self.peerCountCell.objectValue = @(self.circle.peers.count);
46 NSString *peerNames = [[self.circle.peers mapWithBlock:^id(id obj) {
47 return ((KDCirclePeer*)obj).name;
48 }] componentsJoinedByString:@"\n"];
49 [self.peerTextList.textStorage replaceCharactersInRange:NSMakeRange(0, [self.peerTextList.textStorage length]) withString:peerNames];
51 self.applicantCountCell.objectValue = @(self.circle.applicants.count);
52 NSString *applicantNames = [[self.circle.applicants mapWithBlock:^id(id obj) {
53 return ((KDCirclePeer*)obj).name;
54 }] componentsJoinedByString:@"\n"];
55 [self.applicantTextList.textStorage replaceCharactersInRange:NSMakeRange(0, [self.applicantTextList.textStorage length]) withString:applicantNames];
57 [self.syncSpinner stopAnimation:nil];
63 if (self.circle.isInCircle) {
64 [self.enableKeychainSyncing setState:NSOnState];
65 } else if (self.circle.isOutOfCircle) {
66 [self.enableKeychainSyncing setState:NSOffState];
68 [self.enableKeychainSyncing setState:NSMixedState];
72 -(IBAction)enableKeychainSyncingClicked:(id)sender
74 [self.syncSpinner startAnimation:sender];
75 if (self.circle.isOutOfCircle) {
76 [self.circle enableSync];
78 [self.circle disableSync];