#import <UIKit/UIColor.h>
#import <UIKit/UIImage.h>
#import <UIKit/UIImageView.h>
+#import <UIKit/UINavigationBarBackground.h>
#import <UIKit/UIView-Geometry.h>
#import <UIKit/UIView-Hierarchy.h>
#import <CoreGraphics/CGGeometry.h>
+@interface NSDictionary (WinterBoard)
+- (UIColor *) colorForKey:(NSString *)key;
+@end
+
+@implementation NSDictionary (WinterBoard)
+
+- (UIColor *) colorForKey:(NSString *)key {
+ NSString *value = [self objectForKey:key];
+ if (value == nil)
+ return nil;
+ /* XXX: incorrect */
+ return nil;
+}
+
+@end
+
/* WinterBoard Backend {{{ */
#define WBPrefix "wb_"
void WBRename(const char *classname, const char *oldname, IMP newimp) {
Class _class = objc_getClass(classname);
- if (_class == nil)
+ if (_class == nil) {
+ NSLog(@"WB: cannot find class [%s]", classname);
+ return;
+ }
+ Method method = class_getInstanceMethod(_class, sel_getUid(oldname));
+ if (method == nil) {
+ NSLog(@"WB: cannot find method [%s %s]", classname, oldname);
return;
+ }
size_t namelen = strlen(oldname);
char newname[sizeof(WBPrefix) + namelen];
memcpy(newname, WBPrefix, sizeof(WBPrefix) - 1);
memcpy(newname + sizeof(WBPrefix) - 1, oldname, namelen + 1);
- Method method = class_getInstanceMethod(_class, sel_getUid(oldname));
- if (method == nil)
- return;
const char *type = method_getTypeEncoding(method);
if (!class_addMethod(_class, sel_registerName(newname), method_getImplementation(method), type))
NSLog(@"WB: failed to rename [%s %s]", classname, oldname);
done:
free(methods);
}
-
-static NSString *Dylib_ = @"/Applications/WinterBoard.app/WinterBoard.dylib";
/* }}} */
@protocol WinterBoard
- (NSString *) wb_pathForResource:(NSString *)resource ofType:(NSString *)type;
- (id) wb_initWithSize:(CGSize)size;
- (id) wb_initWithFrame:(CGRect)frame;
+- (id) wb_initWithCoder:(NSCoder *)coder;
- (void) wb_setFrame:(CGRect)frame;
- (void) wb_setBackgroundColor:(id)color;
- (void) wb_setAlpha:(float)value;
-- (void) wb_addSubview:(UIView *)addSubview;
+- (void) wb_setBarStyle:(int)style;
+- (id) wb_initWithFrame:(CGRect)frame withBarStyle:(int)style withTintColor:(UIColor *)color;
@end
-NSString *Themes_ = @"/Library/Themes";
+NSFileManager *Manager_;
+NSDictionary *Info_;
NSString *theme_;
NSString *Wallpaper_;
NSString *SBApplication$pathForIcon(SBApplication<WinterBoard> *self, SEL sel) {
if (theme_ != nil) {
- NSFileManager *manager([NSFileManager defaultManager]);
+ NSString *identifier = [self bundleIdentifier];
#define testForIcon(Name) \
if (NSString *name = Name) { \
- NSString *path = [NSString stringWithFormat:@"%@/%@/Icons/%@.png", Themes_, theme_, name]; \
- if ([manager fileExistsAtPath:path]) \
+ NSString *path = [NSString stringWithFormat:@"%@/Icons/%@.png", theme_, name]; \
+ if ([Manager_ fileExistsAtPath:path]) \
return path; \
}
testForIcon([self displayName]);
- testForIcon([self bundleIdentifier]);
+ testForIcon(identifier);
+
+ if (identifier != nil) {
+ NSString *path = [NSString stringWithFormat:@"%@/Bundles/%@/icon.png", theme_, identifier];
+ if ([Manager_ fileExistsAtPath:path])
+ return path;
+ }
}
return [self wb_pathForIcon];
}
NSString *NSBundle$pathForResource$ofType$(NSBundle<WinterBoard> *self, SEL sel, NSString *resource, NSString *type) {
- if (theme_ != nil && [resource isEqualToString:@"SBDockBG"] && [type isEqualToString:@"png"]) {
- NSFileManager *manager([NSFileManager defaultManager]);
- NSString *path = [NSString stringWithFormat:@"%@/%@/Dock.png", Themes_, theme_];
- if ([manager fileExistsAtPath:path])
- return path;
+ NSLog(@"WB: NSBundle(%@) pathForResource:%@ ofType:%@", [self bundleIdentifier], resource, type);
+
+ if (theme_ != nil) {
+ NSString *identifier = [self bundleIdentifier];
+
+ if (identifier != nil) {
+ NSString *path = [NSString stringWithFormat:@"%@/Bundles/%@/%@.%@", theme_, identifier, resource, type];
+ if ([Manager_ fileExistsAtPath:path])
+ return path;
+ NSLog(@"p...%@ (%u)", path, [Manager_ fileExistsAtPath:path]);
+ }
+
+ if ([resource isEqualToString:@"SBDockBG"] && [type isEqualToString:@"png"]) {
+ NSString *path = [NSString stringWithFormat:@"%@/Dock.png", theme_];
+ if ([Manager_ fileExistsAtPath:path])
+ return path;
+ }
}
return [self wb_pathForResource:resource ofType:type];
return [self wb_setBackgroundColor:color];
}
+bool UINavigationBar$setBarStyle$_(SBAppWindow<WinterBoard> *self) {
+ if (Info_ != nil) {
+ NSNumber *number = [Info_ objectForKey:@"NavigationBarStyle"];
+ if (number != nil) {
+ [self wb_setBarStyle:[number intValue]];
+ return true;
+ }
+ }
+
+ return false;
+}
+
+/*id UINavigationBarBackground$initWithFrame$withBarStyle$withTintColor$(UINavigationBarBackground<WinterBoard> *self, SEL sel, CGRect frame, int style, UIColor *tint) {
+ _trace();
+
+ if (Info_ != nil) {
+ NSNumber *number = [Info_ objectForKey:@"NavigationBarStyle"];
+ if (number != nil)
+ style = [number intValue];
+
+ UIColor *color = [Info_ colorForKey:@"NavigationBarTint"];
+ if (color != nil)
+ tint = color;
+ }
+
+ return [self wb_initWithFrame:frame withBarStyle:style withTintColor:tint];
+}*/
+
+/*id UINavigationBar$initWithCoder$(SBAppWindow<WinterBoard> *self, SEL sel, CGRect frame, NSCoder *coder) {
+ self = [self wb_initWithCoder:coder];
+ if (self == nil)
+ return nil;
+ UINavigationBar$setBarStyle$_(self);
+ return self;
+}
+
+id UINavigationBar$initWithFrame$(SBAppWindow<WinterBoard> *self, SEL sel, CGRect frame) {
+ self = [self wb_initWithFrame:frame];
+ if (self == nil)
+ return nil;
+ UINavigationBar$setBarStyle$_(self);
+ return self;
+}*/
+
+void UINavigationBar$setBarStyle$(SBAppWindow<WinterBoard> *self, SEL sel, int style) {
+ if (UINavigationBar$setBarStyle$_(self))
+ return;
+ return [self wb_setBarStyle:style];
+}
+
/*id SBButtonBar$initWithFrame$(SBButtonBar<WinterBoard> *self, SEL sel, CGRect frame) {
self = [self wb_initWithFrame:frame];
if (self == nil)
}
extern "C" void WBInitialize() {
- /* WinterBoard FrontEnd {{{ */
- if (NSClassFromString(@"SpringBoard") == nil)
- return;
NSLog(@"WB: installing WinterBoard...");
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
- char *dil = getenv("DYLD_INSERT_LIBRARIES");
- if (dil == NULL)
- NSLog(@"WB: DYLD_INSERT_LIBRARIES is unset?");
- else {
- NSArray *dylibs = [[NSString stringWithUTF8String:dil] componentsSeparatedByString:@":"];
- int index = [dylibs indexOfObject:Dylib_];
- if (index == INT_MAX)
- NSLog(@"WB: dylib not in DYLD_INSERT_LIBRARIES?");
- else if ([dylibs count] == 1)
- unsetenv("DYLD_INSERT_LIBRARIES");
- else {
- NSMutableArray *value = [[NSMutableArray alloc] init];
- [value setArray:dylibs];
- [value removeObjectAtIndex:index];
- setenv("DYLD_INSERT_LIBRARIES", [[value componentsJoinedByString:@":"] UTF8String], !0);
- }
- }
- /* }}} */
-
WBRename("SBApplication", "pathForIcon", (IMP) &SBApplication$pathForIcon);
WBRename("NSBundle", "pathForResource:ofType:", (IMP) &NSBundle$pathForResource$ofType$);
WBRename("SBAppWindow", "setBackgroundColor:", (IMP) &SBAppWindow$setBackgroundColor$);
WBRename("SBContentLayer", "initWithSize:", (IMP) &SBContentLayer$initWithSize$);
+ //WBRename("UINavigationBar", "initWithFrame:", (IMP) &UINavigationBar$initWithFrame$);
+ //WBRename("UINavigationBar", "initWithCoder:", (IMP) &UINavigationBar$initWithCoder$);
+ WBRename("UINavigationBar", "setBarStyle:", (IMP) &UINavigationBar$setBarStyle$);
+ //WBRename("UINavigationBarBackground", "initWithFrame:withBarStyle:withTintColor:", (IMP) &UINavigationBarBackground$initWithFrame$withBarStyle$withTintColor$);
+
+ Manager_ = [[NSFileManager defaultManager] retain];
if (NSDictionary *settings = [[NSDictionary alloc] initWithContentsOfFile:[NSString stringWithFormat:@"%@/Library/Preferences/com.saurik.WinterBoard.plist", NSHomeDirectory()]]) {
[settings autorelease];
- theme_ = [[settings objectForKey:@"Theme"] retain];
+ NSString *name = [settings objectForKey:@"Theme"];
+ NSString *path;
- NSFileManager *manager([NSFileManager defaultManager]);
- NSString *path = [NSString stringWithFormat:@"%@/%@/Wallpaper.png", Themes_, theme_];
- if ([manager fileExistsAtPath:path])
+ if (theme_ == nil) {
+ path = [NSString stringWithFormat:@"%@/Library/SummerBoard/Themes/%@", NSHomeDirectory(), name];
+ if ([Manager_ fileExistsAtPath:path])
+ theme_ = [path retain];
+ }
+
+ if (theme_ == nil) {
+ path = [NSString stringWithFormat:@"/Library/Themes/%@", name];
+ if ([Manager_ fileExistsAtPath:path])
+ theme_ = [path retain];
+ }
+ }
+
+ if (theme_ != nil) {
+ NSString *path = [NSString stringWithFormat:@"%@/Wallpaper.png", theme_];
+ if ([Manager_ fileExistsAtPath:path])
Wallpaper_ = [path retain];
+
+ Info_ = [[NSDictionary alloc] initWithContentsOfFile:[NSString stringWithFormat:@"%@/Info.plist", theme_]];
+ if (Info_ == nil) {
+ //LabelColor_ = [UIColor whiteColor];
+ } else {
+ //LabelColor_ = [Info_ colorForKey:@"LabelColor"];
+ }
}
[pool release];