-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathTweak.xm
More file actions
114 lines (81 loc) · 3.71 KB
/
Tweak.xm
File metadata and controls
114 lines (81 loc) · 3.71 KB
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
#import <SpringBoard/SpringBoard.h>
#import <AudioToolbox/AudioServices.h>
#import <AVFoundation/AVAudioPlayer.h>
#define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending)
#define BEEPIOS8 @"/System/Library/Audio/UISounds/connect_power.caf"
#define BEEP @"/System/Library/Audio/UISounds/beep-beep.caf"
NSURL *beepios8url = [NSURL fileURLWithPath:[NSString stringWithFormat:BEEPIOS8]];
NSURL *beepurl = [NSURL fileURLWithPath:[NSString stringWithFormat:BEEP]];
%hook SBUIController
-(void)_indicateConnectedToPower {
NSMutableDictionary *prefs = [[NSMutableDictionary alloc] initWithContentsOfFile:@"/var/mobile/Library/Preferences/com.ziph0n.beepbeep.plist"];
NSString *currentSound = [prefs objectForKey:@"currentSound"];
if ([currentSound length] > 3) { currentSound = [currentSound substringToIndex:[currentSound length] - 4]; }
NSString *mySoundPath = [[NSBundle bundleWithPath:@"/Library/Application Support/BeepBeep/Sounds/"] pathForResource:currentSound ofType:@"caf"];
NSURL *mySoundURL = [[NSURL alloc] initFileURLWithPath:mySoundPath];
BOOL enabled = [[prefs objectForKey:@"enabled"] boolValue];
BOOL sound = [[prefs objectForKey:@"sound"] boolValue];
BOOL custom = [[prefs objectForKey:@"custom"] boolValue];
BOOL vibration = [[prefs objectForKey:@"vibration"] boolValue];
AVAudioPlayer *audioPlayer;
if (enabled) {
if (sound) {
if (!custom) {
if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"8.0")) {
audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:beepios8url error:nil];
audioPlayer.numberOfLoops = 0;
audioPlayer.volume = 1.0;
[audioPlayer play];
} else {
audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:beepurl error:nil];
audioPlayer.numberOfLoops = 0;
audioPlayer.volume = 1.0;
[audioPlayer play];
}
}
else if (custom) {
audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:mySoundURL error:nil];
audioPlayer.numberOfLoops = 0;
audioPlayer.volume = 1.0;
[audioPlayer play];
}
}
if (vibration) {
AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
[NSThread sleepForTimeInterval:0.5];
AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
}
}
else if (!enabled) {
if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"8.0")) {
audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:beepios8url error:nil];
audioPlayer.numberOfLoops = 0;
audioPlayer.volume = 1.0;
[audioPlayer play];
} else {
audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:beepurl error:nil];
audioPlayer.numberOfLoops = 0;
audioPlayer.volume = 1.0;
[audioPlayer play];
}
AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
[NSThread sleepForTimeInterval:0.5];
AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
}
}
-(void) ACPowerChanged {
NSMutableDictionary *prefs = [[NSMutableDictionary alloc] initWithContentsOfFile:@"/var/mobile/Library/Preferences/com.ziph0n.beepbeep.plist"];
BOOL enabled = [[prefs objectForKey:@"enabled"] boolValue];
BOOL screen = [[prefs objectForKey:@"screen"] boolValue];
if (enabled) {
if (screen) {
}
else if (!screen) {
%orig;
}
}
else if (!enabled) {
%orig;
}
}
%end