From 8810f06468ce09a61f8e639a53b965d05edfc0fb Mon Sep 17 00:00:00 2001 From: Paul Griffin Date: Mon, 5 Jul 2010 22:53:41 -0400 Subject: [PATCH] Race update --- Makefile | 2 +- StatusBarItemClient.h | 2 +- StatusBarItemClient.mm | 17 +++++--- common.h | 1 + libstatusbar.mm | 96 ++++++++++++++++++++++++------------------ 5 files changed, 70 insertions(+), 48 deletions(-) diff --git a/Makefile b/Makefile index 24929e5..c64229a 100644 --- a/Makefile +++ b/Makefile @@ -3,7 +3,7 @@ libstatusbar_OBJCC_FILES = libstatusbar.mm Classes.mm \ StatusBarItemClient.mm StatusBarItemServer.mm \ UIStatusBarCustomItem.mm UIStatusBarCustomItemView.mm libstatusbar_FRAMEWORKS = UIKit -libstatusbar_PRIVATE_FRAMEWORKS = AppSupport +libstatusbar_PRIVATE_FRAMEWORKS = AppSupport SpringboardServices #SYSROOT = /Wildcat7B367.dyld_cache diff --git a/StatusBarItemClient.h b/StatusBarItemClient.h index 1475eae..6c90ed3 100644 --- a/StatusBarItemClient.h +++ b/StatusBarItemClient.h @@ -10,7 +10,7 @@ - (id) init; - (void) retrieveCurrentMessage; -- (void) processCurrentMessage; +- (bool) processCurrentMessage; - (void) updateStatusBar; - (void) setProperties: (id) properties forItem: (NSString*) item; diff --git a/StatusBarItemClient.mm b/StatusBarItemClient.mm index 0bbb8a6..750c93f 100644 --- a/StatusBarItemClient.mm +++ b/StatusBarItemClient.mm @@ -59,8 +59,10 @@ - (void) retrieveCurrentMessage NSDesc(_currentMessage); } -- (void) processCurrentMessage +- (bool) processCurrentMessage { + bool ret = NO; + NSMutableDictionary *processedMessage = [_currentMessage mutableCopy]; int keyidx = 22; @@ -82,6 +84,8 @@ - (void) processCurrentMessage NSString* indicatorName = [item indicatorName]; if(processedMessage==nil || [processedMessage objectForKey: indicatorName] == nil) { + ret = YES; + NSLog(@"removing item: %@", indicatorName); [item removeAllViews]; [customItems[i] removeObjectAtIndex: cnt]; @@ -108,16 +112,18 @@ - (void) processCurrentMessage keyidx++; - if(processedMessage) + if(processedMessage && [processedMessage count]) { + ret = YES; GETCLASS(UIStatusBarItem); for(NSString* key in processedMessage) - //NSString* key = @"Pause"; { NSLog(@"adding item: %@", key); [[$UIStatusBarItem itemWithType: keyidx++] setIndicatorName: key]; } } + NSLog(@"processCurrentMessage? %@", ret ? @"YES" : @"NO"); + return ret; } - (void) updateStatusBar @@ -125,10 +131,9 @@ - (void) updateStatusBar SelLog(); [self retrieveCurrentMessage]; - [self processCurrentMessage]; - // need a decent guard band because we call updateStatusBar before UIApp exists - if(UIApp) + // need a decent guard band because we do call before UIApp exists + if([self processCurrentMessage] && UIApp) { UIStatusBarForegroundView* _foregroundView = MSHookIvar([UIApp statusBar], "_foregroundView"); if(_foregroundView) diff --git a/common.h b/common.h index 92896eb..f27c7e9 100644 --- a/common.h +++ b/common.h @@ -10,6 +10,7 @@ extern "C" UIApplication* UIApp; + (UIImage*) kitImageNamed: (NSString*) name; @end +extern "C" int SBSSpringBoardServerPort(); #import #import diff --git a/libstatusbar.mm b/libstatusbar.mm index ad5d40c..50a5534 100644 --- a/libstatusbar.mm +++ b/libstatusbar.mm @@ -251,15 +251,67 @@ void removeBT() } */ -__attribute__((constructor)) void start() +HOOKDEF(void, UIApplication, _startWindowServerIfNecessary) { + HookLog(); + CALL_ORIG(UIApplication, _startWindowServerIfNecessary); + + // use this only for starting client + // register as client - make sure SpringBoard is running + // UIKit should still not exist.../yet/ + if($SpringBoard || SBSSpringBoardServerPort()) + { + [StatusBarItemClient sharedInstance]; + } NSLine(); - [[NSAutoreleasePool alloc] init]; + // testing stuff... + /* + { + float delay = 4.0f; + CFRunLoopTimerCallBack callback = (CFRunLoopTimerCallBack) addBT; + + CFRunLoopTimerRef waitTimer = CFRunLoopTimerCreate(kCFAllocatorDefault, CFAbsoluteTimeGetCurrent()+delay, 0.0f, 0, 0, callback, NULL); + CFRunLoopAddTimer(CFRunLoopGetMain(), waitTimer, kCFRunLoopCommonModes); + } + { + float delay = 8.0f; + CFRunLoopTimerCallBack callback = (CFRunLoopTimerCallBack) addPause; + + + CFRunLoopTimerRef waitTimer = CFRunLoopTimerCreate(kCFAllocatorDefault, CFAbsoluteTimeGetCurrent()+delay, 0.0f, 0, 0, callback, NULL); + CFRunLoopAddTimer(CFRunLoopGetMain(), waitTimer, kCFRunLoopCommonModes); + } + + { + float delay = 12.0f; + CFRunLoopTimerCallBack callback = (CFRunLoopTimerCallBack) removeBT; + + + CFRunLoopTimerRef waitTimer = CFRunLoopTimerCreate(kCFAllocatorDefault, CFAbsoluteTimeGetCurrent()+delay, 0.0f, 0, 0, callback, NULL); + CFRunLoopAddTimer(CFRunLoopGetMain(), waitTimer, kCFRunLoopCommonModes); + } + { + float delay = 16.0f; + CFRunLoopTimerCallBack callback = (CFRunLoopTimerCallBack) addBT; + + + CFRunLoopTimerRef waitTimer = CFRunLoopTimerCreate(kCFAllocatorDefault, CFAbsoluteTimeGetCurrent()+delay, 0.0f, 0, 0, callback, NULL); + CFRunLoopAddTimer(CFRunLoopGetMain(), waitTimer, kCFRunLoopCommonModes); + } + */ +} + + +__attribute__((constructor)) void start() +{ + NSLine(); // get classes Classes_Fetch(); + [[NSAutoreleasePool alloc] init]; + // we only hook UIKit apps - used as a guard band if($UIStatusBarItem) { @@ -283,52 +335,16 @@ void removeBT() HOOKMESSAGE(UIApplication, addStatusBarImageNamed:removeOnExit:, addStatusBarImageNamed$removeOnExit$); HOOKMESSAGE(UIApplication, addStatusBarImageNamed:, addStatusBarImageNamed$); HOOKMESSAGE(UIApplication, removeStatusBarImageNamed:, removeStatusBarImageNamed$); + HOOKMESSAGE(UIApplication, _startWindowServerIfNecessary, _startWindowServerIfNecessary); } if($SpringBoard) { [StatusBarItemServer sharedInstance]; } - // register as client - [StatusBarItemClient sharedInstance]; - - // testing stuff...timers used because we are doing this before UIKit has been initialized - /* - { - float delay = 4.0f; - CFRunLoopTimerCallBack callback = (CFRunLoopTimerCallBack) addBT; - - CFRunLoopTimerRef waitTimer = CFRunLoopTimerCreate(kCFAllocatorDefault, CFAbsoluteTimeGetCurrent()+delay, 0.0f, 0, 0, callback, NULL); - CFRunLoopAddTimer(CFRunLoopGetMain(), waitTimer, kCFRunLoopCommonModes); - } - { - float delay = 8.0f; - CFRunLoopTimerCallBack callback = (CFRunLoopTimerCallBack) addPause; - - - CFRunLoopTimerRef waitTimer = CFRunLoopTimerCreate(kCFAllocatorDefault, CFAbsoluteTimeGetCurrent()+delay, 0.0f, 0, 0, callback, NULL); - CFRunLoopAddTimer(CFRunLoopGetMain(), waitTimer, kCFRunLoopCommonModes); - } - - { - float delay = 12.0f; - CFRunLoopTimerCallBack callback = (CFRunLoopTimerCallBack) removeBT; - - - CFRunLoopTimerRef waitTimer = CFRunLoopTimerCreate(kCFAllocatorDefault, CFAbsoluteTimeGetCurrent()+delay, 0.0f, 0, 0, callback, NULL); - CFRunLoopAddTimer(CFRunLoopGetMain(), waitTimer, kCFRunLoopCommonModes); - } - { - float delay = 16.0f; - CFRunLoopTimerCallBack callback = (CFRunLoopTimerCallBack) addBT; - - - CFRunLoopTimerRef waitTimer = CFRunLoopTimerCreate(kCFAllocatorDefault, CFAbsoluteTimeGetCurrent()+delay, 0.0f, 0, 0, callback, NULL); - CFRunLoopAddTimer(CFRunLoopGetMain(), waitTimer, kCFRunLoopCommonModes); - } - */ NSLine(); + } }