forked from rpetrich/MathAlarm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTweak.xm
105 lines (91 loc) · 2.64 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
#import <UIKit/UIKit2.h>
#import <SpringBoard/SpringBoard.h>
#import <CaptainHook/CaptainHook.h>
%hook SBRemoteLocalNotificationAlert
static BOOL waitingForAnswer;
static BOOL lockScreen;
static NSInteger answer;
static UIWindow *window1;
+ (void)stopPlayingAlertSoundOrRingtone
{
if (!waitingForAnswer)
%orig;
}
static inline BOOL IsMobileTimerAlarm(SBRemoteLocalNotificationAlert *self)
{
return [[CHIvar(self, _app, SBApplication *) displayIdentifier] isEqualToString:@"com.apple.mobiletimer"];
}
- (void)configure:(BOOL)configure requirePasscodeForActions:(BOOL)actions
{
if (IsMobileTimerAlarm(self)) {
waitingForAnswer = YES;
UIAlertView *alertView = [self alertSheet];
alertView.title = @"Alarm";
NSInteger a = arc4random() % 90 + 11;
NSInteger b = arc4random() % 10 + 3;
alertView.message = [NSString stringWithFormat:@"%d × %d = ?", a, b];
answer = a * b;
UITextField *textField = [alertView addTextFieldWithValue:nil label:@"Answer"];
textField.keyboardAppearance = UIKeyboardAppearanceAlert;
textField.keyboardType = UIKeyboardTypeNumberPad;
alertView.cancelButtonIndex = [alertView addButtonWithTitle:@"Snooze"];
[alertView addButtonWithTitle:@"Deactivate"];
[alertView setNumberOfRows:1];
if(lockScreen) {
window1 = [[UIWindow alloc] init];
window1.frame = CGRectMake(0.0, 0.0, 0.0, 0.0);
window1.windowLevel = UIWindowLevelAlert;
[window1 makeKeyAndVisible];
}
} else {
%orig;
}
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (IsMobileTimerAlarm(self)) {
UITextField *textField = [alertView textFieldAtIndex:0];
waitingForAnswer = ![textField.text isEqualToString:[NSString stringWithFormat:@"%d", answer]];
if (waitingForAnswer)
return;
}
if(lockScreen) {
[window1 resignKeyWindow];
[window1 release];
}
%orig;
}
%new(v@:@i)
- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex
{
if (IsMobileTimerAlarm(self) && waitingForAnswer)
[alertView performSelector:@selector(show) withObject:nil afterDelay:0.0];
}
%new(v@:@)
- (void)didPresentAlertView:(UIAlertView *)alertView
{
UITextField *textField = [alertView textFieldAtIndex:0];
[textField becomeFirstResponder];
}
- (void)willDeactivateForReason:(NSInteger)reason
{
if (!IsMobileTimerAlarm(self) || !waitingForAnswer)
%orig;
}
- (void)dismiss:(NSInteger)reason
{
if (!IsMobileTimerAlarm(self) || !waitingForAnswer)
%orig;
}
%end
%hook SBAwayController
- (void) lock {
lockScreen = YES;
%orig;
}
- (void)_finishedUnlockAttemptWithStatus:(BOOL)status
{
lockScreen = NO;
%orig;
}
%end