Skip to content

Commit bcbeada

Browse files
committed
Finder sync (proof of concept)
1 parent fe4d163 commit bcbeada

24 files changed

Lines changed: 372 additions & 147 deletions

‎osx/Extensions/Action/Action.entitlements‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<true/>
77
<key>com.apple.security.application-groups</key>
88
<array>
9-
<string>Keybase</string>
9+
<string>keybase</string>
1010
</array>
1111
<key>com.apple.security.files.user-selected.read-only</key>
1212
<true/>

‎osx/Extensions/Action/ActionViewController.m‎

Lines changed: 10 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,8 @@
77
//
88

99
#import "ActionViewController.h"
10-
#import "KBPGPEncryptActionView.h"
11-
#import "KBService.h"
12-
#import "KBWorkspace.h"
13-
#import "KBLogFormatter.h"
10+
11+
#import <KBKit/KBAppActions.h>
1412

1513
@interface ActionViewController ()
1614
@end
@@ -22,35 +20,21 @@ - (NSString *)nibName {
2220
}
2321

2422
- (void)loadView {
25-
static dispatch_once_t onceToken;
26-
dispatch_once(&onceToken, ^{
27-
DDTTYLogger.sharedInstance.logFormatter = [[KBLogFormatter alloc] init];
28-
[DDLog addLogger:DDTTYLogger.sharedInstance withLevel:DDLogLevelDebug]; // Xcode output
29-
});
30-
31-
KBPGPEncryptActionView *encryptView = [[KBPGPEncryptActionView alloc] init];
32-
[encryptView sizeToFit];
33-
self.view = encryptView;
34-
3523
NSExtensionItem *item = self.extensionContext.inputItems.firstObject;
36-
encryptView.extensionItem = item;
37-
38-
KBEnvConfig *config = [KBEnvConfig env:KBEnvSandbox];
39-
KBService *service = [[KBService alloc] initWithConfig:config];
40-
encryptView.client = service.client;
41-
42-
encryptView.completion = ^(id sender, NSExtensionItem *item) {
43-
if (!item) {
24+
DDLogDebug(@"Attachments: %@", item.attachments);
25+
id view = [KBAppActions encryptWithExtensionItem:item completion:^(id sender, NSExtensionItem *outputItem) {
26+
if (!outputItem) {
4427
[self cancel];
4528
} else {
46-
[self share:item];
29+
[self performAction:outputItem];
4730
}
48-
};
31+
}];
4932

50-
DDLogDebug(@"Attachments: %@", item.attachments);
33+
[view sizeToFit];
34+
self.view = view;
5135
}
5236

53-
- (void)share:(NSExtensionItem *)outputItem {
37+
- (void)performAction:(NSExtensionItem *)outputItem {
5438
[self.extensionContext completeRequestReturningItems:@[outputItem] completionHandler:nil];
5539
}
5640

‎osx/Extensions/Action/Info.plist‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@
3232
<dict>
3333
<key>NSExtensionActivationRule</key>
3434
<dict>
35-
<key>NSExtensionActivationSupportsFileWithMaxCount</key>
36-
<string>1</string>
3735
<key>NSExtensionActivationSupportsText</key>
3836
<true/>
37+
<key>NSExtensionActivationSupportsFileWithMaxCount</key>
38+
<string>1</string>
3939
</dict>
4040
<key>NSExtensionServiceRoleType</key>
4141
<string>NSExtensionServiceRoleTypeEditor</string>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>com.apple.security.app-sandbox</key>
6+
<true/>
7+
<key>com.apple.security.application-groups</key>
8+
<array>
9+
<string>keybase</string>
10+
</array>
11+
<key>com.apple.security.files.user-selected.read-only</key>
12+
<true/>
13+
</dict>
14+
</plist>
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
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+
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<key>CFBundleDevelopmentRegion</key>
66
<string>en</string>
77
<key>CFBundleDisplayName</key>
8-
<string>FinderSync</string>
8+
<string>Keybase</string>
99
<key>CFBundleExecutable</key>
1010
<string>$(EXECUTABLE_NAME)</string>
1111
<key>CFBundleIdentifier</key>

‎osx/Extensions/Share/Share.entitlements‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<true/>
77
<key>com.apple.security.application-groups</key>
88
<array>
9-
<string>Keybase</string>
9+
<string>keybase</string>
1010
</array>
1111
<key>com.apple.security.files.user-selected.read-only</key>
1212
<true/>

‎osx/FinderSync/FinderSync.entitlements‎

Lines changed: 0 additions & 10 deletions
This file was deleted.

‎osx/FinderSync/FinderSync.m‎

Lines changed: 0 additions & 91 deletions
This file was deleted.

0 commit comments

Comments
 (0)