/
OnePasswordAction.m
112 lines (90 loc) · 4.02 KB
/
OnePasswordAction.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
//
// OnePasswordAction.m
// OnePassword
//
// Created by Patrick Robertson on 15/01/2010.
// Copyright Patrick Roberston 2010. All rights reserved.
//
// This file is part of Quicksilver 1Password Module.
//
// Quicksilver 1Password Module is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Quicksilver 1Password Module is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Quicksilver 1Password Module. If not, see <http://www.gnu.org/licenses/>.
//
#import "OnePasswordAction.h"
#import "OnePasswordSource.h"
#import "OnePasswordDefines.h"
@implementation OnePasswordAction
// Method to only show browsers in the 3rd pane for the 'Go & Fill With...' action
- (NSArray *)validIndirectObjectsForAction:(NSString *)action directObject:(QSObject *)dObject{
// only for 'Go & Fill With...' action
if (![action isEqualToString:@"goAndFillWith"]) {
return nil;
}
NSArray *validBrowsers = [NSArray arrayWithObjects:@"org.mozilla.firefox",
@"com.apple.Safari",@"com.google.Chrome",@"org.mozilla.camino",@"com.operasoftware.Opera",
@"com.omnigroup.omniweb",@"com.ranchero.NetNewsWire",
@"com.fluidapp.Fluid",@"com.devon-technologies.agent",@"de.icab.iCab",@"org.webkit.nightly.WebKit",nil];
NSMutableArray *validIndirects = [NSMutableArray arrayWithCapacity:1];
NSMutableSet *set = [NSMutableSet set];
NSMutableArray *validBrowserPaths = [NSMutableArray arrayWithCapacity:1];
NSWorkspace *ws = [NSWorkspace sharedWorkspace];
for(NSString *browserID in validBrowsers) {
NSString *browserPath = [ws absolutePathForAppBundleWithIdentifier:browserID];
if (browserPath) {
[validBrowserPaths addObject:browserPath];
}
}
// Get the default app for the url
NSURL *appURL = nil;
LSGetApplicationForURL((CFURLRef)[NSURL URLWithString:@"http://"], kLSRolesAll, NULL, (CFURLRef *)&appURL);
// Set the default app to be 1st in the returned list
id preferred = [QSObject fileObjectWithPath:[appURL path]];
if (!preferred) {
preferred = [NSNull null];
}
[appURL release];
[set addObjectsFromArray:validBrowserPaths];
validIndirects = [[QSLibrarian sharedInstance] scoredArrayForString:nil inSet:[QSObject fileObjectsWithPathArray:[set allObjects]]];
return [NSArray arrayWithObjects:preferred, validIndirects, nil];
}
- (QSObject *)goAndFill:(QSObject *)dObject{
[self goAndFill:dObject with:nil];
return nil;
}
- (QSObject *)goAndFill:(QSObject *)dObject with:(QSObject *)iObject {
NSWorkspace *ws = [NSWorkspace sharedWorkspace];
NSMutableArray *URLArray = [[NSMutableArray alloc] initWithCapacity:[dObject count]];
for (QSObject *goAndFillObject in [dObject splitObjects]) {
NSString *URLString = [NSString stringWithFormat:@"%@?onepasswdfill=%@",[goAndFillObject details],[goAndFillObject objectForType:QS1PasswordForm]];
[URLArray addObject:[NSURL URLWithString:[URLString URLEncoding]]];
}
if (!iObject) {
[ws openURLs:URLArray withAppBundleIdentifier:nil
options:0
additionalEventParamDescriptor:nil
launchIdentifiers:nil];
} else {
for(QSObject *individual in [iObject splitObjects]){
if([individual isApplication]) {
NSString *ident = [[NSBundle bundleWithPath:[individual singleFilePath]] bundleIdentifier];
[ws openURLs:URLArray withAppBundleIdentifier:ident
options:0
additionalEventParamDescriptor:nil
launchIdentifiers:nil];
}
}
}
[URLArray release];
return nil;
}
@end