-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTweak.xm
87 lines (64 loc) · 1.94 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
#import "AVFlashlight.h"
#import <AudioToolbox/AudioServices.h>
@interface SpringBoard : NSObject
-(BOOL)_handlePhysicalButtonEvent:(id)arg1 ;
-(void)_simulateHomeButtonPress;
-(void)_simulateLockButtonPress;
@end
@interface AVSystemController
+ (id)sharedAVSystemController;
- (BOOL)getActiveCategoryVolume:(float*)volume andName:(id*)name;
- (BOOL)setActiveCategoryVolumeTo:(float)to;
@end
BOOL pressed = NO;
NSTimer *pressedTimer;
static AVFlashlight *_sharedFlashlight;
%hook AVFlashlight
-(id)init {
if (!_sharedFlashlight) {
_sharedFlashlight = %orig;
}
return _sharedFlashlight;
}
%end
%hook SpringBoard
-(_Bool)_handlePhysicalButtonEvent:(UIPressesEvent *)arg1
{
int type = arg1.allPresses.allObjects[0].type;
int force = arg1.allPresses.allObjects[0].force;
// type = 101 -> Home button
// type = 104 -> Power button
// force = 0 -> button released
// force = 1 -> button pressed
if(type == 104 && force == 1) //Power PRESSED
{
pressed = YES;
pressedTimer = [[NSTimer scheduledTimerWithTimeInterval:.6 target:self selector:@selector(toggleFlashlight) userInfo:nil repeats:NO] retain];
}
if(type == 104 && force == 0) //Power RELEASED
{
if (pressedTimer != nil) {
[pressedTimer invalidate];
pressedTimer = nil;
}
pressed = NO;
}
return %orig;
}
%new
- (void)toggleFlashlight
{
if (pressed) {
if (_sharedFlashlight.flashlightLevel > 0) {
[_sharedFlashlight setFlashlightLevel: 0.0 withError:nil];
}
else {
[_sharedFlashlight setFlashlightLevel:1.0 withError:nil];
}
AudioServicesPlaySystemSoundWithCompletion(kSystemSoundID_Vibrate, ^{
AudioServicesDisposeSystemSoundID(kSystemSoundID_Vibrate);
});
pressed = NO;
}
}
%end