-
Notifications
You must be signed in to change notification settings - Fork 0
/
DockItemsSource.m
67 lines (57 loc) · 1.89 KB
/
DockItemsSource.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
//
// DockItemsSource.m
//
// Copyright (c) 2009 Martin Kuehl <purl.org/net/mkhl>
// Licensed under the MIT License.
//
#import <Vermilion/Vermilion.h>
static NSString *const kDockBundleIdentifier = @"com.apple.Dock";
static NSString *const kDockItemsKey = @"persistent-others";
static NSString *const kDockItemPathKey = @"tile-data.file-data._CFURLString";
@interface DockItemsSource : HGSMemorySearchSource
- (void)recacheContents;
- (void)recacheContentsAfterDelay:(NSTimeInterval)delay;
- (void)indexItemAtPath:(NSString *)path;
@end
@implementation DockItemsSource
- (id)initWithConfiguration:(NSDictionary *)configuration
{
self = [super initWithConfiguration:configuration];
if (self == nil)
return nil;
if ([self loadResultsCache])
[self recacheContentsAfterDelay:10.0];
else
[self recacheContents];
return self;
}
- (void)recacheContents
{
[self clearResultIndex];
NSDictionary *settings = [[NSUserDefaults standardUserDefaults]
persistentDomainForName:kDockBundleIdentifier];
for (NSDictionary *item in [settings valueForKey:kDockItemsKey])
[self indexItemAtPath:[item valueForKeyPath:kDockItemPathKey]];
[self recacheContentsAfterDelay:60.0];
}
- (void)recacheContentsAfterDelay:(NSTimeInterval)delay
{
[self performSelector:@selector(recacheContents)
withObject:nil
afterDelay:delay];
}
- (void)indexResultAtPath:(NSString *)path
{
[self indexResult:[HGSResult resultWithFilePath:path
source:self
attributes:nil]];
}
- (void)indexItemAtPath:(NSString *)path
{
[self indexResultAtPath:path];
NSFileManager *manager = [NSFileManager defaultManager];
for (NSString *subpath in [manager directoryContentsAtPath:path])
if (![subpath hasPrefix:@"."])
[self indexResultAtPath:[path stringByAppendingPathComponent:subpath]];
}
@end