-
Notifications
You must be signed in to change notification settings - Fork 6
/
Tweak.xm
120 lines (86 loc) · 3.13 KB
/
Tweak.xm
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
113
114
115
116
117
118
119
#import "Headers.h"
@implementation PSSpecifier (CustomWidgetIcons)
- (UIImage *)customIconImage
{
return (UIImage *)objc_getAssociatedObject(self, "CustomWidgetIcon");
}
- (void)setCustomIconImage:(UIImage *)image
{
objc_setAssociatedObject(self, "CustomWidgetIcon", image, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}
@end
%group iOS5Hooks
%hook BulletinBoardController
- (PSSpecifier *)_applicationSpecifierForBBSection:(BBSectionInfo *)section
{
PSSpecifier *specifier = %orig;
if (section.pathToWeeAppPluginBundle)
{
NSDictionary *infoPlist = [NSDictionary dictionaryWithContentsOfFile:[NSString stringWithFormat:@"%@/Info.plist", section.pathToWeeAppPluginBundle]];
UIImage *icon = [UIImage imageWithContentsOfFile:[NSString stringWithFormat:@"%@/%@", section.pathToWeeAppPluginBundle, [infoPlist objectForKey:@"CFBundleIconFile"]]];
[specifier setCustomIconImage:icon];
}
return specifier;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.section > 1)
{
PSSpecifier *specifier = [self specifierAtIndex:[self indexForIndexPath:indexPath]];
if ([specifier customIconImage])
{
UITableViewCell *cell = %orig;
cell.imageView.image = [specifier customIconImage];
return cell;
}
}
return %orig;
}
%end /** BulletinBoardController **/
%end /** iOS5Hooks **/
%group iOS6Hooks
%hook NotificationCell
- (UIImage *)getLazyIcon
{
NSString *imgPath = [[NSBundle bundleWithPath:[self bundlePath]] objectForInfoDictionaryKey:@"CFBundleIconFile"];
if (imgPath)
{
return [UIImage imageWithContentsOfFile:[NSString stringWithFormat:@"%@/%@", [self bundlePath], imgPath]];
}
return %orig;
}
%end /** NotificationCell **/
%end /** iOS6Hooks **/
%group iOS7Hooks
%hook SBBulletinListSection
- (void)_updateWithSectionInfo:(BBSectionInfo *)info
{
%orig;
if ([self isWidgetSection])
{
if ([[info sectionID] isEqualToString:@"com.apple.attributionweeapp.bundle"])
return;
NSBundle *widgetBundle = [NSBundle bundleWithPath:[info pathToWeeAppPluginBundle]];
NSString *imgPath = [widgetBundle objectForInfoDictionaryKey:@"CFBundleIconFile"];
if (imgPath != nil)
[self setIconImage:[UIImage imageWithContentsOfFile:[NSString stringWithFormat:@"%@/%@", [widgetBundle bundlePath], imgPath]]];
NSString *rawDisplayName = [widgetBundle objectForInfoDictionaryKey:@"CFBundleDisplayName"];
NSString *localDisplayName = NSLocalizedStringFromTableInBundle(rawDisplayName, @"InfoPlist", widgetBundle, @"");
if (localDisplayName != nil)
[self setDisplayName:localDisplayName];
}
}
%end /** SBBulletinListSection **/
%end /** iOS7Hooks **/
%ctor
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSInteger sysVer = [[[UIDevice currentDevice] systemVersion] intValue];
if (sysVer == 5)
%init(iOS5Hooks);
else if (sysVer == 6)
%init(iOS6Hooks);
else
%init(iOS7Hooks);
[pool drain];
}