/
Prefs.m
59 lines (51 loc) · 1.95 KB
/
Prefs.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
#import <Preferences/Preferences.h>
#import <CaptainHook/CaptainHook.h>
#define kPluginPath @"/Library/LivePaper/Plugins"
@interface LivePaperSettingsController : PSListController
@end
@implementation LivePaperSettingsController
- (NSArray *)specifiers
{
if (!_specifiers) {
// Load specifiers
NSMutableArray *specifiers = [[super specifiers] mutableCopy];
// Load Plugins
NSInteger groupIndex = [self indexOfSpecifierID:@"PluginsGroup"];
NSInteger index = groupIndex;
for (NSString *path in [[NSFileManager defaultManager] contentsOfDirectoryAtPath:kPluginPath error:NULL]) {
if (![path hasPrefix:@"."] && [path hasSuffix:@".bundle"]) {
NSString *bundlePath = [kPluginPath stringByAppendingPathComponent:path];
if ([[NSBundle bundleWithPath:bundlePath] objectForInfoDictionaryKey:@"NSPrincipalClass"]) {
index++;
PSSpecifier* specifier = [PSSpecifier preferenceSpecifierNamed:[path stringByDeletingPathExtension] target:self set:NULL get:NULL detail:Nil cell:PSLinkCell edit:Nil];
CHIvar(specifier, action, SEL) = @selector(lazyLoadBundle:);
[specifier setProperty:bundlePath forKey:@"lazy-bundle"];
[specifiers insertObject:specifier atIndex:index];
}
}
}
// If have no configurable plugins, remove plugin settings
if (groupIndex == index) {
[specifiers removeObjectAtIndex:index];
}
[_specifiers release];
_specifiers = specifiers;
}
return _specifiers;
}
@end
@implementation NSObject (LivePaper)
- (NSArray *)livePaperBundleNames
{
NSMutableArray *array = [[NSMutableArray alloc] init];
[array addObject:@"(none)"];
for (NSString *path in [[NSFileManager defaultManager] contentsOfDirectoryAtPath:@"/Library/LivePaper/Plugins" error:NULL]) {
if (![path hasPrefix:@"."] && [path hasSuffix:@".bundle"]) {
[array addObject:[path stringByDeletingPathExtension]];
}
}
NSArray *result = [array sortedArrayUsingSelector:@selector(localizedCaseInsensitiveCompare:)];
[array release];
return result;
}
@end