forked from phoenix3200/libstatusbar
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1 parent
8810f06
commit a92bf30
Showing
16 changed files
with
1,376 additions
and
415 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,22 @@ | ||
|
||
@interface StatusBarItemClient : NSObject | ||
@interface LSStatusBarClient : NSObject | ||
{ | ||
bool _isLocal; | ||
NSDictionary* _currentMessage; | ||
NSArray* _titleStrings; | ||
} | ||
|
||
+ (id) sharedInstance; | ||
|
||
- (id) init; | ||
|
||
- (NSDictionary*) currentMessage; | ||
- (void) retrieveCurrentMessage; | ||
- (bool) processCurrentMessage; | ||
- (void) updateStatusBar; | ||
|
||
- (void) setProperties: (id) properties forItem: (NSString*) item; | ||
|
||
- (NSString*) titleStringAtIndex: (int) idx; | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,265 @@ | ||
|
||
//#define TESTING | ||
|
||
#import "common.h" | ||
#import "defines.h" | ||
|
||
#import "classes.h" | ||
#import "LSStatusBarClient.h" | ||
#import "LSStatusBarServer.h" | ||
#import "UIStatusBarCustomItem.h" | ||
|
||
void UpdateStatusBar(CFNotificationCenterRef center, LSStatusBarClient* client) | ||
{ | ||
[client updateStatusBar]; | ||
} | ||
|
||
@implementation LSStatusBarClient | ||
|
||
+ (id) sharedInstance | ||
{ | ||
static LSStatusBarClient* client; | ||
|
||
if(!client) | ||
{ | ||
client = [[self alloc] init]; | ||
} | ||
return client; | ||
} | ||
|
||
- (id) init | ||
{ | ||
self = [super init]; | ||
if(self) | ||
{ | ||
_isLocal = $SpringBoard ? YES : NO; | ||
|
||
CFNotificationCenterRef darwin = CFNotificationCenterGetDarwinNotifyCenter(); | ||
CFNotificationCenterAddObserver(darwin, self, (CFNotificationCallback) UpdateStatusBar, (CFStringRef) @"libstatusbar_changed", NULL, NULL); | ||
|
||
[self updateStatusBar]; | ||
|
||
} | ||
return self; | ||
} | ||
|
||
- (NSDictionary*) currentMessage | ||
{ | ||
return _currentMessage; | ||
} | ||
|
||
- (void) retrieveCurrentMessage | ||
{ | ||
[_currentMessage release]; | ||
if(_isLocal) | ||
{ | ||
_currentMessage = [[[LSStatusBarServer sharedInstance] currentMessage] retain]; | ||
} | ||
else | ||
{ CPDistributedMessagingCenter* dmc = [CPDistributedMessagingCenter centerNamed: @"com.apple.springboard.libstatusbar"]; | ||
|
||
_currentMessage = [[dmc sendMessageAndReceiveReplyName: @"currentMessage" userInfo: nil] retain]; | ||
} | ||
NSDesc(_currentMessage); | ||
} | ||
|
||
- (NSString*) titleStringAtIndex: (int) idx | ||
{ | ||
if(idx < (int)[_titleStrings count]) | ||
{ | ||
return [_titleStrings objectAtIndex: idx]; | ||
} | ||
return nil; | ||
} | ||
|
||
- (bool) processCurrentMessage | ||
{ | ||
bool ret = NO; | ||
|
||
//NSMutableDictionary *processedMessage = [_currentMessage mutableCopy]; | ||
|
||
NSMutableArray* processedKeys = [[_currentMessage objectForKey: @"keys"] mutableCopy]; | ||
|
||
|
||
[_titleStrings release]; | ||
_titleStrings = [[_currentMessage objectForKey: @"titleStrings"] retain]; | ||
|
||
|
||
/* | ||
if(_titleStrings) | ||
{ | ||
[processedMessage removeObjectForKey: @"titleStrings"]; | ||
} | ||
*/ | ||
|
||
int keyidx = 22; | ||
|
||
NSDesc(_currentMessage); | ||
extern NSMutableArray* customItems[3]; | ||
|
||
for(int i=0; i<3; i++) | ||
{ | ||
if(customItems[i]) | ||
{ | ||
NSDesc(customItems[i]); | ||
int cnt = [customItems[i] count]-1; | ||
/* | ||
extern NSMutableArray* allCustomItems; | ||
if(allCustomItems) | ||
{ | ||
int cnt = [allCustomItems count]-1; | ||
*/ | ||
for(; cnt>= 0; cnt--) | ||
// for(UIStatusBarCustomItem* item in customItems[i]) | ||
{ | ||
UIStatusBarCustomItem* item = [customItems[i] objectAtIndex: cnt]; | ||
//UIStatusBarCustomItem* item = [allCustomItems objectAtIndex: cnt]; | ||
|
||
NSString* indicatorName = [item indicatorName]; | ||
|
||
NSObject* properties = nil; | ||
if(_currentMessage) | ||
{ | ||
properties = [_currentMessage objectForKey: indicatorName]; | ||
} | ||
|
||
if(!properties) | ||
{ | ||
ret = YES; | ||
|
||
NSLog(@"removing item: %@", indicatorName); | ||
[item removeAllViews]; | ||
//[allCustomItems removeObjectAtIndex: cnt]; | ||
[customItems[i] removeObjectAtIndex: cnt]; | ||
// [customItems[i] removeObject: item]; | ||
} | ||
else | ||
{ | ||
NSLog(@"keeping item: %@", indicatorName); | ||
//[processedMessage removeObjectForKey: indicatorName]; | ||
[processedKeys removeObject: indicatorName]; | ||
|
||
int &type(MSHookIvar<int>(item, "_type")); | ||
if(type > keyidx) | ||
keyidx = type; | ||
|
||
item.properties = [properties isKindOfClass: [NSDictionary class]] ? (NSDictionary*) properties : nil; | ||
} | ||
} | ||
} | ||
else | ||
{ | ||
NSLog(@"creating array"); | ||
customItems[i] = [[NSMutableArray alloc] init]; | ||
} | ||
} | ||
|
||
keyidx++; | ||
|
||
if(processedKeys && [processedKeys count]) | ||
{ | ||
ret = YES; | ||
GETCLASS(UIStatusBarItem); | ||
for(NSString* key in processedKeys)//processedMessage) | ||
{ | ||
NSLog(@"adding item: %@", key); | ||
|
||
UIStatusBarCustomItem* item = [$UIStatusBarItem itemWithType: keyidx++]; | ||
[item setIndicatorName: key]; | ||
|
||
NSObject* properties = [_currentMessage objectForKey: key]; | ||
item.properties = [properties isKindOfClass: [NSDictionary class]] ? (NSDictionary*) properties : nil; | ||
|
||
|
||
if([item leftOrder]) | ||
{ | ||
if(!customItems[0]) | ||
{ | ||
customItems[0] = [[NSMutableArray alloc] init]; | ||
} | ||
[customItems[0] addObject: item]; | ||
} | ||
else if([item rightOrder]) | ||
{ | ||
if(!customItems[1]) | ||
{ | ||
customItems[1] = [[NSMutableArray alloc] init]; | ||
} | ||
[customItems[1] addObject: item]; | ||
} | ||
else | ||
{ | ||
if(!customItems[2]) | ||
{ | ||
customItems[2] = [[NSMutableArray alloc] init]; | ||
} | ||
[customItems[2] addObject: item]; | ||
} | ||
} | ||
} | ||
|
||
|
||
//if(_titleStrings && [_titleStrings count]) | ||
|
||
// too many cases; just refresh the damn thing. | ||
{ | ||
ret = YES; | ||
} | ||
|
||
|
||
|
||
[processedKeys release]; | ||
|
||
NSLog(@"processCurrentMessage? %@", ret ? @"YES" : @"NO"); | ||
return ret; | ||
} | ||
|
||
- (void) updateStatusBar | ||
{ | ||
SelLog(); | ||
|
||
[self retrieveCurrentMessage]; | ||
|
||
// need a decent guard band because we do call before UIApp exists | ||
if([self processCurrentMessage] && UIApp) | ||
{ | ||
UIStatusBarForegroundView* _foregroundView = MSHookIvar<UIStatusBarForegroundView*>([UIApp statusBar], "_foregroundView"); | ||
if(_foregroundView) | ||
{ | ||
//[_foregroundView _reflowItemViewsWithDuration: 0.0f suppressCenterAnimation: YES]; | ||
|
||
[_foregroundView setStatusBarData: (StatusBarData*) [$UIStatusBarServer getStatusBarData] actions: 1 animated: YES]; | ||
} | ||
} | ||
} | ||
|
||
- (void) setProperties: (id) properties forItem: (NSString*) item | ||
{ | ||
SelLog(); | ||
if(item) | ||
{ | ||
NSString* bundleId = [[NSBundle mainBundle] bundleIdentifier]; | ||
|
||
if(_isLocal) | ||
{ | ||
[[LSStatusBarServer sharedInstance] setProperties: properties forItem: item bundle: bundleId]; | ||
} | ||
else | ||
{ | ||
|
||
|
||
NSDictionary* dict = [[NSDictionary alloc] initWithObjectsAndKeys: | ||
item, @"item", | ||
properties, @"properties", | ||
bundleId, @"bundle", | ||
nil]; | ||
|
||
CPDistributedMessagingCenter* dmc = [CPDistributedMessagingCenter centerNamed: @"com.apple.springboard.libstatusbar"]; | ||
|
||
[dmc sendMessageName: @"setProperties:userInfo:" userInfo: dict]; | ||
[dict release]; | ||
} | ||
} | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
enum StatusBarAlignment | ||
{ | ||
StatusBarAlignmentLeft = 1, | ||
StatusBarAlignmentRight = 2, | ||
StatusBarAlignmentCenter = 4 | ||
}; | ||
|
||
|
||
@interface LSStatusBarItem : NSObject | ||
{ | ||
NSString* _identifier; | ||
NSMutableDictionary* _properties; | ||
NSMutableSet* _delegates; | ||
BOOL _manualUpdate; | ||
} | ||
|
||
+ (void) updateItems; | ||
|
||
- (void) dealloc; | ||
- (void) setProperties: (NSDictionary*) dict; | ||
|
||
@end | ||
|
||
|
||
@interface LSStatusBarItem (API) | ||
|
||
- (id) initWithIdentifier: (NSString*) identifier alignment: (StatusBarAlignment) alignment; | ||
|
||
// bitmasks (e.g. left or right) are not supported yet | ||
@property (nonatomic, readonly) StatusBarAlignment alignment; | ||
|
||
@property (nonatomic, getter=isVisible) BOOL visible; | ||
|
||
// useful only with left/right alignment - will throw error for center alignment | ||
@property (nonatomic, assign) NSString* imageName; | ||
|
||
// useful only with center alignment - will throw error otherwise | ||
// will not be visible on the lockscreen | ||
@property (nonatomic, assign) NSString* titleString; | ||
|
||
// set to NO and manually call update if you need to make multiple changes | ||
@property (nonatomic, getter=isManualUpdate) BOOL manualUpdate; | ||
|
||
// manually call if manualUpdate = YES | ||
- (void) update; | ||
|
||
@end | ||
|
||
|
||
|
||
|
||
@interface LSStatusBarItem (Unimplemented) | ||
|
||
|
||
// leave alone unless you want to limit which apps your icon shows up in | ||
@property (nonatomic, assign) NSString* exclusiveToApp; | ||
|
||
// convenience methods? | ||
//@property (nonatomic, getter=isSpringBoardOnly) BOOL springBoardOnly; | ||
//@property (getter=isCurrentAppOnly) BOOL currentAppOnly; | ||
|
||
// delegate must respond to @selector(statusBarAction:); only valid from inside of SpringBoard | ||
- (void) addTouchDelegate: (id) delegate; | ||
- (void) removeTouchDelegate: (id) delegate; | ||
|
||
|
||
@end |
Oops, something went wrong.