-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTweak.xm
127 lines (99 loc) · 3.01 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
120
121
122
123
124
125
126
127
#include <mach/mach_time.h>
#include <IOKit/hid/IOHIDEvent.h>
#import <UIKit/UIKit.h>
BOOL _lEnabled;
BOOL _pdEnabled;
BOOL _lockEnabled;
BOOL _lockPDEnabled;
extern "C"{
typedef uint32_t IOHIDEventOptionBits;
typedef struct __IOHIDEvent *IOHIDEventRef;
IOHIDEventRef IOHIDEventCreateKeyboardEvent(CFAllocatorRef allocator, AbsoluteTime timeStamp, uint16_t usagePage, uint16_t usage, Boolean down, IOHIDEventOptionBits flags);
}
@interface SBSpotlightSettings
@property(nonatomic) _Bool enableSpotlightOnMinusPage;
- (void)setDefaultValues;
@end
@interface SPUISearchViewController
@property (nonatomic) unsigned int presentsFromEdge;
- (BOOL)_isPullDownSpotlight;
@end
@interface SpringBoard : UIApplication
- (void)_lockButtonUp:(struct __IOHIDEvent *)arg1 fromSource:(int)arg2;
- (void)_lockButtonDown:(struct __IOHIDEvent *)arg1 fromSource:(int)arg2;
@end
static void loadPrefs() {
NSMutableDictionary *prefs = [[NSMutableDictionary alloc] initWithContentsOfFile:@"/var/mobile/Library/Preferences/com.ezi.locklight.plist"];
if(prefs)
{
_lEnabled = [prefs objectForKey:@"LEnabled"] ? [[prefs objectForKey:@"LEnabled"] boolValue] : NO;
_pdEnabled = [prefs objectForKey:@"PDEnabled"] ? [[prefs objectForKey:@"PDEnabled"] boolValue] : NO;
_lockEnabled = [prefs objectForKey:@"LockEnabled"] ? [[prefs objectForKey:@"LockEnabled"] boolValue] : NO;
_lockPDEnabled = [prefs objectForKey:@"LockPDEnabled"] ? [[prefs objectForKey:@"LockPDEnabled"] boolValue] : NO;
}
[prefs release];
}
static void lockDevice() {
SpringBoard *springboard = (SpringBoard *)[%c(SpringBoard) sharedApplication];
uint64_t abTime = mach_absolute_time();
IOHIDEventRef event = IOHIDEventCreateKeyboardEvent(kCFAllocatorDefault, *(AbsoluteTime *)&abTime, 0xC, 0x40, YES, 0);
[springboard _lockButtonDown:event fromSource:1];
CFRelease(event);
event = IOHIDEventCreateKeyboardEvent(kCFAllocatorDefault, *(AbsoluteTime *)&abTime, 0xC, 0x40, YES, 0);
[springboard _lockButtonUp:event fromSource:1];
CFRelease(event);
}
%group pullDown2Lock
%hook SPUISearchViewController
- (void)didFinishPresenting:(BOOL)arg1 {
if (arg1 && [self _isPullDownSpotlight]/*self.presentsFromEdge == 1*/) {
lockDevice();
}
else {
%orig;
}
}
%end
%end
%group leftSP2Lock
%hook SPUISearchViewController
- (void)didFinishPresenting:(BOOL)arg1 {
if (arg1 && ![self _isPullDownSpotlight]/*self.presentsFromEdge == 8*/) {
lockDevice();
}
else {
%orig;
}
}
%end
%end
%group killPullDownSP
%hook SBSearchScrollView
- (_Bool)gestureRecognizerShouldBegin:(id)arg1 {
return NO;
}
%end
%end
%group killLeftSP
%hook SBSpotlightSettings
- (void)setDefaultValues {
%orig;
self.enableSpotlightOnMinusPage = NO;
}
%end
%end
%ctor {
loadPrefs();
if (_lEnabled && _lockEnabled) {
%init(leftSP2Lock);
}
else if (!_lEnabled) {
%init(killLeftSP);
}
if (!_pdEnabled) {
%init(killPullDownSP);
}
else if (_lockPDEnabled) {
%init(pullDown2Lock);
}
}