From 10d657527d5385b540988f50c79936f5e0b563b4 Mon Sep 17 00:00:00 2001 From: Ryan Petrich Date: Thu, 23 Sep 2010 02:43:54 -0600 Subject: [PATCH] Use system keyboard sounds setting Kind of a hack, but the setting is buried in UIKit as a static Doesn't track system notifications, but I don't think that's a big deal --- Cydia.mm | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/Cydia.mm b/Cydia.mm index 38ba04eb..b546ec9f 100644 --- a/Cydia.mm +++ b/Cydia.mm @@ -8518,6 +8518,26 @@ MSHook(void, UIWebDocumentView$_setUIKitDelegate$, UIWebDocumentView *self, SEL return _UIWebDocumentView$_setUIKitDelegate$(self, _cmd, delegate); } +static NSNumber *shouldPlayKeyboardSounds; + +Class $UIHardware; + +MSHook(void, UIHardware$_playSystemSound$, Class self, SEL _cmd, int soundIndex) { + switch (soundIndex) { + case 1104: // Keyboard Button Clicked + case 1105: // Keyboard Delete Repeated + if (!shouldPlayKeyboardSounds) { + NSDictionary *dict = [[NSDictionary alloc] initWithContentsOfFile:@"/var/mobile/Library/Preferences/com.apple.preferences.sounds.plist"]; + shouldPlayKeyboardSounds = [[dict objectForKey:@"keyboard"] ?: (id)kCFBooleanTrue retain]; + [dict release]; + } + if (![shouldPlayKeyboardSounds boolValue]) + break; + default: + _UIHardware$_playSystemSound$(self, _cmd, soundIndex); + } +} + int main(int argc, char *argv[]) { _pooled _trace(); @@ -8539,6 +8559,13 @@ int main(int argc, char *argv[]) { _pooled _UIWebDocumentView$_setUIKitDelegate$ = reinterpret_cast(method_getImplementation(UIWebDocumentView$_setUIKitDelegate$)); method_setImplementation(UIWebDocumentView$_setUIKitDelegate$, reinterpret_cast(&$UIWebDocumentView$_setUIKitDelegate$)); } + + $UIHardware = objc_getClass("UIHardware"); + Method UIHardware$_playSystemSound$(class_getClassMethod($UIHardware, @selector(_playSystemSound:))); + if (UIHardware$_playSystemSound$ != NULL) { + _UIHardware$_playSystemSound$ = reinterpret_cast(method_getImplementation(UIHardware$_playSystemSound$)); + method_setImplementation(UIHardware$_playSystemSound$, reinterpret_cast(&$UIHardware$_playSystemSound$)); + } /* }}} */ /* Set Locale {{{ */ Locale_ = CFLocaleCopyCurrent(); -- 2.45.2