-
Notifications
You must be signed in to change notification settings - Fork 7
/
Tweak.xm
148 lines (128 loc) · 4.68 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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
#import <AudioToolbox/AudioToolbox.h>
#import <sys/utsname.h>
#import <UIKit/UIImpactFeedbackGenerator.h>
#import <UIKit/UINotificationFeedbackGenerator.h>
@interface TUCall
@property (getter=isIncoming,nonatomic,readonly) BOOL incoming;
@property (nonatomic,readonly) int callStatus;
@end
@interface MPTelephonyManager
@property (atomic,assign) TUCall * activeCall;
-(void)handleCallStatusChanged:(id)arg1;
-(void)PlayVibration;
@end
static BOOL wasCallConnected = NO;
static BOOL VibrOnDiscConn = YES ;
static int callType = 1;
static NSString* VibrStrength = @"Medium";
static void PerfromVibration()
{
BOOL IsDeviceNewer = true;
struct utsname systemInfo;
uname(&systemInfo);
NSString *pl = [NSString stringWithCString:systemInfo.machine encoding:NSUTF8StringEncoding];
if ([pl isEqualToString:@"iPhone6,1"] ||
[pl isEqualToString:@"iPhone6,2"] ||
[pl isEqualToString:@"iPhone7,1"] ||
[pl isEqualToString:@"iPhone7,2"] ||
[pl isEqualToString:@"iPhone8,1"] ||
[pl isEqualToString:@"iPhone8,2"] ||
[pl isEqualToString:@"iPhone8,4"])
{
IsDeviceNewer = false;
}
if (IsDeviceNewer)
{
if ([VibrStrength isEqualToString:@"Heavy"])
{
UIImpactFeedbackGenerator *myGen = [[UIImpactFeedbackGenerator alloc] init];
[myGen initWithStyle:(UIImpactFeedbackStyleHeavy)];
[myGen impactOccurred];
}
else if ([VibrStrength isEqualToString:@"Light"])
{
UIImpactFeedbackGenerator *myGen = [[UIImpactFeedbackGenerator alloc] init];
[myGen initWithStyle:(UIImpactFeedbackStyleLight)];
[myGen impactOccurred];
}
else if ([VibrStrength isEqualToString:@"Success"])
{
UINotificationFeedbackGenerator *myGen = [[UINotificationFeedbackGenerator alloc] init];
[myGen notificationOccurred:UINotificationFeedbackTypeSuccess];
}
else if ([VibrStrength isEqualToString:@"Warning"])
{
UINotificationFeedbackGenerator *myGen = [[UINotificationFeedbackGenerator alloc] init];
[myGen notificationOccurred:UINotificationFeedbackTypeWarning];
}
else if ([VibrStrength isEqualToString:@"Error"])
{
UINotificationFeedbackGenerator *myGen = [[UINotificationFeedbackGenerator alloc] init];
[myGen notificationOccurred:UINotificationFeedbackTypeError];
}
else if ([VibrStrength isEqualToString:@"Standard"])
{
AudioServicesPlaySystemSound(1352);
}
else
{
UIImpactFeedbackGenerator *myGen = [[UIImpactFeedbackGenerator alloc] init];
[myGen initWithStyle:(UIImpactFeedbackStyleMedium)];
[myGen impactOccurred];
}
//NSLog(@"[LetMeKnow] - Vibration Strength - %@",VibrStrength);
}
else
{
AudioServicesPlaySystemSound(1352);
}
}
%hook TUCall
-(void)_handleStatusChange
{
int callStat = self.callStatus;
// NSString *msg = [NSString stringWithFormat:@"CallStatus %d",callStat];
// UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"CallStatus" message:msg delegate:[[UIApplication sharedApplication] keyWindow].rootViewController cancelButtonTitle:@"Ok" otherButtonTitles:nil];
// [alertView show];
// [alertView release];
bool isIncoming = self.isIncoming;
if (callStat == 1)
{
if ((callType == 1 && !isIncoming) || (callType == 2))
{
PerfromVibration();
}
wasCallConnected = YES;
}
if (callStat == 0 || callStat == 6)
{
if (VibrOnDiscConn && wasCallConnected)
{
PerfromVibration();
}
wasCallConnected = NO;
}
%orig;
}
%end
static void reloadSettings() {
static CFStringRef prefsKey = CFSTR("com.imkpatil.letmeknow");
CFPreferencesAppSynchronize(prefsKey);
if (CFBridgingRelease(CFPreferencesCopyAppValue((CFStringRef)@"WantsVibrOnDisc", prefsKey))) {
VibrOnDiscConn = [(id)CFBridgingRelease(CFPreferencesCopyAppValue((CFStringRef)@"WantsVibrOnDisc", prefsKey)) boolValue];
}
if (CFBridgingRelease(CFPreferencesCopyAppValue((CFStringRef)@"LMKStrength", prefsKey))) {
VibrStrength = [(id)CFBridgingRelease(CFPreferencesCopyAppValue((CFStringRef)@"LMKStrength", prefsKey)) stringValue];
}
if (CFBridgingRelease(CFPreferencesCopyAppValue((CFStringRef)@"CallTypeForVibration", prefsKey))) {
callType = [(id)CFBridgingRelease(CFPreferencesCopyAppValue((CFStringRef)@"CallTypeForVibration", prefsKey)) intValue];
}
}
static void PerformVibrationAction() {
reloadSettings();
PerfromVibration();
}
%ctor {
CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(), NULL, (CFNotificationCallback)PerformVibrationAction, CFSTR("com.imkpatil.letmeknow.settingschanged"), NULL, CFNotificationSuspensionBehaviorCoalesce);
reloadSettings();
}