|
| 1 | +// |
| 2 | +// FinderSync.m |
| 3 | +// FinderSync |
| 4 | +// |
| 5 | +// Created by Gabriel on 6/10/15. |
| 6 | +// Copyright (c) 2015 Keybase. All rights reserved. |
| 7 | +// |
| 8 | + |
| 9 | +#import "FinderSync.h" |
| 10 | + |
| 11 | +#import <KBKit/KBWorkspace.h> |
| 12 | + |
| 13 | +@interface FinderSync () |
| 14 | +@property NSString *mountDir; |
| 15 | +@end |
| 16 | + |
| 17 | +#define KBBadgeAvailable (@"available") |
| 18 | +#define KBBadgeUnavailable (@"unavailable") |
| 19 | + |
| 20 | +@implementation FinderSync |
| 21 | + |
| 22 | +- (instancetype)init { |
| 23 | + if ((self = [super init])) { |
| 24 | + NSString *mountDir = [KBWorkspace.userDefaults objectForKey:@"MountDir"]; |
| 25 | + NSLog(@"Finder sync using: %@", mountDir); |
| 26 | + if (mountDir) { |
| 27 | + [FIFinderSyncController defaultController].directoryURLs = [NSSet setWithObject:[NSURL fileURLWithPath:mountDir]]; |
| 28 | + } |
| 29 | + [FIFinderSyncController.defaultController setBadgeImage:[NSImage imageNamed:NSImageNameStatusUnavailable] label:@"Unavailable" forBadgeIdentifier:KBBadgeUnavailable]; |
| 30 | + [FIFinderSyncController.defaultController setBadgeImage:[NSImage imageNamed:NSImageNameStatusAvailable] label:@"Available" forBadgeIdentifier:KBBadgeAvailable]; |
| 31 | + } |
| 32 | + return self; |
| 33 | +} |
| 34 | + |
| 35 | +#pragma mark - |
| 36 | + |
| 37 | +- (void)beginObservingDirectoryAtURL:(NSURL *)URL { |
| 38 | + // The user is now seeing the container's contents. |
| 39 | + // If they see it in more than one view at a time, we're only told once. |
| 40 | + NSLog(@"beginObservingDirectoryAtURL:%@", URL.filePathURL); |
| 41 | +} |
| 42 | + |
| 43 | +- (void)endObservingDirectoryAtURL:(NSURL *)URL { |
| 44 | + // The user is no longer seeing the container's contents. |
| 45 | + NSLog(@"endObservingDirectoryAtURL:%@", URL.filePathURL); |
| 46 | +} |
| 47 | + |
| 48 | +- (void)requestBadgeIdentifierForURL:(NSURL *)URL { |
| 49 | + NSLog(@"requestBadgeIdentifierForURL:%@", URL.filePathURL); |
| 50 | + |
| 51 | + [[FIFinderSyncController defaultController] setBadgeIdentifier:KBBadgeUnavailable forURL:URL]; |
| 52 | +} |
| 53 | + |
| 54 | +#pragma mark Menu/Toolbar |
| 55 | + |
| 56 | +- (NSString *)toolbarItemName { |
| 57 | + return @"Keybase"; |
| 58 | +} |
| 59 | + |
| 60 | +- (NSString *)toolbarItemToolTip { |
| 61 | + return @"Keybase: ?"; |
| 62 | +} |
| 63 | + |
| 64 | +- (NSImage *)toolbarItemImage { |
| 65 | + return [NSImage imageNamed:NSImageNameCaution]; |
| 66 | +} |
| 67 | + |
| 68 | +- (NSMenu *)menuForMenuKind:(FIMenuKind)whichMenu { |
| 69 | + NSMenu *menu = [[NSMenu alloc] initWithTitle:@""]; |
| 70 | + [menu addItemWithTitle:@"Open" action:@selector(open:) keyEquivalent:@""]; |
| 71 | + return menu; |
| 72 | +} |
| 73 | + |
| 74 | +- (IBAction)open:(id)sender { |
| 75 | + NSURL *target = [[FIFinderSyncController defaultController] targetedURL]; |
| 76 | + NSArray *items = [[FIFinderSyncController defaultController] selectedItemURLs]; |
| 77 | + |
| 78 | + NSLog(@"%@, target: %@, items:", [sender title], [target filePathURL]); |
| 79 | + [items enumerateObjectsUsingBlock: ^(id obj, NSUInteger idx, BOOL *stop) { |
| 80 | + NSLog(@" %@", [obj filePathURL]); |
| 81 | + }]; |
| 82 | +} |
| 83 | + |
| 84 | +@end |
| 85 | + |
0 commit comments