-
Notifications
You must be signed in to change notification settings - Fork 1
/
Tweak.xm
102 lines (85 loc) · 2.73 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
/*
* Tweak: LockVibe
* Version: 2.1
* Created by EvilPenguin
*
* Enjoy :0)
*/
#import <AudioToolbox/AudioToolbox.h>
#import <GraphicsServices/GraphicsServices.h>
#define LOCK_VIBE_PLIST @"/var/mobile/Library/Preferences/us.nakedproductions.lockvibe.plist"
#define listenToNotification$withCallBack(notification, callback); CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(), NULL, (CFNotificationCallback)&callback, CFSTR(notification), NULL, CFNotificationSuspensionBehaviorHold);
#define isSettingEnabled(settingName) [plistDict objectForKey:settingName] ? [[plistDict objectForKey:settingName] boolValue] : NO
static NSMutableDictionary *plistDict = nil;
static BOOL isEnabled;
static void loadSettings(void) {
if (plistDict) {
[plistDict release];
plistDict = nil;
}
plistDict = [[NSMutableDictionary alloc] initWithContentsOfFile:LOCK_VIBE_PLIST];
isEnabled = isSettingEnabled(@"LockVibeEnabled");
}
#pragma mark -
#pragma mark == SpringBoard ==
%hook SpringBoard
- (void)autoLock {
if (isSettingEnabled(@"AutoLock")) AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
%orig;
}
- (void)menuButtonDown:(GSEventRef)down {
if (isSettingEnabled(@"MenuDown")) AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
%orig(down);
}
- (void)lockButtonDown:(GSEventRef)down {
if (isSettingEnabled(@"LockDown")) AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
%orig(down);
}
%end
#pragma mark -
#pragma mark == SBSearchView ==
%hook SBSearchView
- (void)keyboardDidShow:(id)keyboard {
if (isSettingEnabled(@"ShowSearch")) AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
%orig(keyboard);
}
%end
#pragma mark -
#pragma mark == SBApplication ==
%hook SBApplication
- (void)launchSucceeded:(BOOL)succeeded {
if (isSettingEnabled(@"AppLaunch")) AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
%orig(succeeded);
}
- (void)exitedCommon {
if (isSettingEnabled(@"AppClose")) AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
%orig;
}
%end
#pragma mark -
#pragma mark == VolumeControl ==
%hook VolumeControl
- (void) increaseVolume {
if (isSettingEnabled(@"VolumeIncrease")) AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
%orig;
}
- (void) decreaseVolume {
if (isSettingEnabled(@"VolumeDecrease")) AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
%orig;
}
%end
#pragma mark -
#pragma mark == SBLowPowerAlertItem ==
%hook SBLowPowerAlertItem
- (id)initWithLevel:(unsigned)level {
if (isSettingEnabled(@"PowerAlert")) AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
return %orig(level);
}
%end
%ctor {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
%init;
listenToNotification$withCallBack("com.understruction.lockvibe.update", loadSettings);
loadSettings();
[pool drain];
}