-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathTweak.xm
More file actions
91 lines (63 loc) · 2.38 KB
/
Copy pathTweak.xm
File metadata and controls
91 lines (63 loc) · 2.38 KB
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
@interface SBIconView : UIView
@end
@interface SBIconImageView : UIView
@end
@interface SBFolderBackgroundView : UIView
@end
#include <notify.h>
#import <QuartzCore/QuartzCore.h>
//Preferences
#define registerNotification(c, n) CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(), NULL, (c), CFSTR(n), NULL, CFNotificationSuspensionBehaviorCoalesce);
#define PREFS_DOMAIN @"com.gmoran.circa"
#define PREFS_CHANGED_NOTIF "com.gmoran.circa.prefs-changed"
#define PREFS_FILE_PATH @"/var/mobile/Library/Preferences/com.gmoran.circa.plist"
static NSDictionary *prefs = nil;
extern "C" CFNotificationCenterRef CFNotificationCenterGetDistributedCenter(void);
static void prefsChanged(CFNotificationCenterRef center, void *observer, CFStringRef name, const void *object, CFDictionaryRef userInfo) {
// reload prefs
[prefs release];
//Delete old prefs file
if ((prefs = [[NSDictionary alloc] initWithContentsOfFile:PREFS_FILE_PATH]) == nil) {
NSLog(@"CREATING PREFERENCE FILE");
prefs = @{@"circaEnabled": @NO,
@"circaBorderColor": @0
};
[prefs writeToFile:PREFS_FILE_PATH atomically:YES];
prefs = [[NSDictionary alloc] initWithContentsOfFile:PREFS_FILE_PATH];
}
}
static BOOL circaEnabled(void) {
//return (prefs) ? [prefs[@"circaEnabled"] boolValue] : NO;
return YES;
}
static UIColor* borderColor(void) {
int number = [[prefs objectForKey:@"circaBorderColor"] intValue];
if (number == 0) {
return [UIColor whiteColor];
}
else if (number == 1) {
return [UIColor blackColor];
}
else {
return [UIColor whiteColor];
}
}
%hook SBIconView
-(void)setFrame:(CGRect)arg1 {
%orig;
if (circaEnabled()) {
SBIconImageView* imageView = MSHookIvar<SBIconImageView*>(self, "_iconImageView");
imageView.layer.cornerRadius = self.frame.size.width / 2;
imageView.layer.masksToBounds = YES;
imageView.layer.borderWidth = 1.0f;
imageView.layer.borderColor = borderColor().CGColor;
}
}
%end
%ctor {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
prefsChanged(NULL, NULL, NULL, NULL, NULL); // initialize prefs
// register to receive changed notifications
registerNotification(prefsChanged, PREFS_CHANGED_NOTIF);
[pool release];
}