-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathRMLController.m
207 lines (161 loc) · 5.38 KB
/
RMLController.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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
#import "RMLController.h"
#import "RMLAlertView.h"
#include "RMLDebug.h"
#include <execinfo.h>
#define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending)
#pragma mark Fake interfaces to deal with private APIs
@interface NSThread (private)
+(id)callStackSymbols;
@end
#pragma mark Private interface
@interface RMLController (private)
-(void)loadBundle;
-(void)loadPreferences;
@end
#pragma mark Implementation
@implementation RMLController
#pragma mark Properties
@synthesize isVersion4 = _isVersion4;
@synthesize isVersion43 = _isVersion43;
@synthesize isVersion5 = _isVersion5;
@synthesize isEnabled = _isEnabled;
@synthesize snoozeTime = _snoozeTime;
@synthesize keepNagging = _keepNagging;
@synthesize nagInterval = _nagInterval;
@synthesize nagLimit = _nagLimit;
@synthesize jailbreakFacade = _jailbreakFacade;
@synthesize resourceBundle = _resourceBundle;
#pragma mark Object lifecycle
-(id)initWithJailbreakFacade:(id <RMLJailbreakFacade>)facade {
if ((self = [super init])) {
self.jailbreakFacade = facade;
[self loadBundle];
[self loadPreferences];
}
return self;
}
-(void)dealloc {
[_jailbreakFacade release];
[_resourceBundle release];
[super dealloc];
}
#pragma mark Localization
-(void)loadBundle {
#if TARGET_IPHONE_SIMULATOR
NSString *path = [[NSBundle mainBundle] pathForResource:@"RemindMeLaterSettings" ofType:@"bundle"];
#else
NSString *path = @"/System/Library/PreferenceBundles/RemindMeLaterSettings.bundle";
#endif
_resourceBundle = [[NSBundle bundleWithPath:path] retain];
#if DEBUG_LOG
NSLog(@"RMLController.loadBundle: bundle is %@", _resourceBundle);
#endif
}
#pragma mark Settings
// TODO - make use of the PostNotification hook to avoid constantly reloading these prefs
-(void)loadPreferences {
_isVersion4 = (objc_getClass("UILocalNotification") != nil);
_isVersion43 = SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"4.3");
_isVersion5 = SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"5.0");
// Default values
_isEnabled = YES;
_snoozeTime = 5;
_keepNagging = YES;
_nagInterval = 5;
_nagLimit = 3;
#if TARGET_IPHONE_SIMULATOR
NSString *plist = [[NSBundle mainBundle] pathForResource:@"ca.varju.RemindMeLater" ofType:@"plist"];
#else
NSString *plist = @"/User/Library/Preferences/ca.varju.RemindMeLater.plist";
#endif
NSDictionary *settings = [[[NSDictionary alloc] initWithContentsOfFile:plist] autorelease];
if (settings) {
NSNumber* b;
b = [settings objectForKey:@"SnoozeTime"];
if (b) {
_snoozeTime = [b intValue];
}
b = [settings objectForKey:@"KeepNagging"];
if (b) {
_keepNagging = [b boolValue];
}
b = [settings objectForKey:@"NagInterval"];
if (b) {
_nagInterval = [b intValue];
}
b = [settings objectForKey:@"NagLimit"];
if (b) {
_nagLimit = [b intValue];
}
}
#if DEBUG_LOG
NSLog(@"RMLController.loadPreferences: out with enabled %d, snoozeTime %d, version4 %d, version43 %d, version5 %d, keepNagging %d, nagInterval %d",
_isEnabled, _snoozeTime, _isVersion4, _isVersion43, _isVersion5, _keepNagging, _nagInterval);
#endif
}
#pragma mark RMLAlertView hooks
-(UIAlertView *)configureAlertView:(UIAlertView *)originalView payload:(id)payload {
UIAlertView *view = [[RMLAlertView alloc] initWithAlertView:originalView controller:self payload:payload];
#if DEBUG_LOG
NSLog(@"RMLController.configureAlertView: view is %@", view);
#endif
return view;
}
-(void)configureAlertItem:(id<SBAlertItem>)alertItem {
if (!_isEnabled) {
return;
}
#if DEBUG_LOG
[self logCalendarAlertItem:alertItem msg:@"RMLController.configureAlertItem"];
#endif
UIAlertView *view = alertItem.alertSheet;
#if DEBUG_LOG
NSLog(@"RMLController.configureAlertItem: alertview delegate is %@", view.delegate);
#endif
UIView *replacementView = [self configureAlertView:view payload:alertItem];
[alertItem setValue:replacementView forKey:@"_alertSheet"];
}
-(void)playSound:(BOOL)onlyOn43 {
#if DEBUG_LOG
NSLog(@"RMLController.playSound: in with onlyOn43=%d", onlyOn43);
#endif
if (onlyOn43 && ![self isVersion43]) {
#if DEBUG_LOG
NSLog(@"RMLController.playSound: not forcing sound to repeat");
#endif
return;
}
[self.jailbreakFacade playSound:!onlyOn43];
}
#pragma mark Debug hooks
-(void)logCalendarAlertItem:(id)item msg:(NSString *)msg {
double date = [[item valueForKey:@"date"] doubleValue];
NSLog(@"%@: - date: %f", msg, date);
NSString* title = [item valueForKey:@"title"];
NSLog(@"%@: - title: %@", msg, title);
NSString* location = [item valueForKey:@"location"];
NSLog(@"%@: - location: %@", msg, location);
if ([self isVersion4]) {
NSString* zone = [item valueForKey:@"timeZone"];
NSLog(@"%@: - zone: %@", msg, zone);
}
int eventId = [[item valueForKey:@"eventId"] intValue];
NSLog(@"%@: - eventId: %d", msg, eventId);
BOOL isAllDay = [[item valueForKey:@"isAllDay"] boolValue];
NSLog(@"%@: - isAllDay: %s", msg, isAllDay ? "true" : "false");
}
-(void) logStack {
if ([[NSThread class] respondsToSelector:@selector(callStackSymbols)]) {
NSLog(@"%@", [NSThread callStackSymbols]);
} else {
void* callstack[128];
int frames = backtrace(callstack, 128);
char** strs = backtrace_symbols(callstack, frames);
int i;
for (i = 0; i < frames; ++i) {
NSLog(@"%s", strs[i]);
}
free(strs);
}
}
@end