]> git.saurik.com Git - winterboard.git/commitdiff
Use pincrush to optimize themes.
authorJay Freeman (saurik) <saurik@saurik.com>
Thu, 1 Apr 2010 01:16:47 +0000 (01:16 +0000)
committerJay Freeman (saurik) <saurik@saurik.com>
Thu, 1 Apr 2010 01:16:47 +0000 (01:16 +0000)
Library.mm
Optimize.cpp [new file with mode: 0755]
Settings.mm
WinterBoardSettings.bundle/WinterBoard.plist
control
makefile

index ea458e31aaa30262ba73ac917fd05067eaca9b38..aa24ab84a6a4624d536a34cd47be179164ea2540 100644 (file)
@@ -172,6 +172,7 @@ static BOOL (*_GSFontGetUseLegacyFontMetrics)();
 
 bool Debug_ = false;
 bool Engineer_ = false;
+bool SummerBoard_ = true;
 
 static UIImage *(*_UIApplicationImageWithName)(NSString *name);
 static UIImage *(*_UIImageAtPath)(NSString *name, NSBundle *path);
@@ -239,7 +240,7 @@ static NSString *$pathForFile$inBundle$(NSString *file, NSBundle *bundle, bool u
         [names addObject:[NSString stringWithFormat:@"Bundles/com.apple.MobileSMS/%@", file]];
     else if ([identifier isEqualToString:@"com.apple.calculator"])
         [names addObject:[NSString stringWithFormat:@"Files/Applications/Calculator.app/%@", file]];
-    else if (![identifier isEqualToString:@"com.apple.springboard"]);
+    else if (![identifier isEqualToString:@"com.apple.springboard"] || !SummerBoard_);
         remapResourceName(@"FSO_BG.png", @"StatusBar")
         remapResourceName(@"SBDockBG.png", @"Dock")
         remapResourceName(@"SBWeatherCelsius.png", @"Icons/Weather")
@@ -261,10 +262,11 @@ static NSString *$pathForIcon$(SBApplication *self) {
 
     NSMutableArray *names = [NSMutableArray arrayWithCapacity:8];
 
+    /* XXX: I might need to keep this for backwards compatibility
     if (identifier != nil)
         [names addObject:[NSString stringWithFormat:@"Bundles/%@/icon.png", identifier]];
     if (folder != nil)
-        [names addObject:[NSString stringWithFormat:@"Folders/%@/icon.png", folder]];
+        [names addObject:[NSString stringWithFormat:@"Folders/%@/icon.png", folder]]; */
 
     #define testForIcon(Name) \
         if (NSString *name = Name) \
@@ -744,7 +746,7 @@ MSHook(id, SBUIController$init, SBUIController *self, SEL sel) {
             [controller_ play:&error];
 #elif UseMPMoviePlayerController
             NSURL *url([NSURL fileURLWithPath:mp4]);
-            MPMoviePlayerController *controller = [[MPMoviePlayerController alloc] initWithContentURL:url];
+            MPMoviePlayerController *controller = [[$MPMoviePlayerController alloc] initWithContentURL:url];
            controller.movieControlMode = MPMovieControlModeHidden;
            [controller play];
 #else
@@ -1388,7 +1390,7 @@ static void dlset(Type_ &function, const char *name) {
 }
 
 extern "C" void WBInitialize() {
-    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+    NSAutoreleasePool *pool([[NSAutoreleasePool alloc] init]);
 
     NSString *identifier([[NSBundle mainBundle] bundleIdentifier]);
 
@@ -1443,8 +1445,8 @@ extern "C" void WBInitialize() {
 
     _UIImage$defaultDesktopImage = MSHookMessage(object_getClass($UIImage), @selector(defaultDesktopImage), &$UIImage$defaultDesktopImage);
 
-    //WBRename("UINavigationBar", @selector(initWithCoder:", (IMP) &UINavigationBar$initWithCoder$);
-    //WBRename("UINavigationBarBackground", @selector(initWithFrame:withBarStyle:withTintColor:", (IMP) &UINavigationBarBackground$initWithFrame$withBarStyle$withTintColor$);
+    //WBRename("UINavigationBar", @selector(initWithCoder:), (IMP) &UINavigationBar$initWithCoder$);
+    //WBRename("UINavigationBarBackground", @selector(initWithFrame:withBarStyle:withTintColor:), (IMP) &UINavigationBarBackground$initWithFrame$withBarStyle$withTintColor$);
 
     _UINavigationBar$setBarStyle$ = MSHookMessage($UINavigationBar, @selector(setBarStyle:), &$UINavigationBar$setBarStyle$);
     _UIToolbar$setBarStyle$ = MSHookMessage($UIToolbar, @selector(setBarStyle:), &$UIToolbar$setBarStyle$);
@@ -1458,30 +1460,31 @@ extern "C" void WBInitialize() {
 
     themes_ = [[NSMutableArray alloc] initWithCapacity:8];
 
-    if (NSDictionary *settings = [[NSDictionary alloc] initWithContentsOfFile:[NSString stringWithFormat:@"/User/Library/Preferences/com.saurik.WinterBoard.plist"]]) {
-        [settings autorelease];
+    if (NSDictionary *settings = [NSDictionary dictionaryWithContentsOfFile:[NSString stringWithFormat:@"/User/Library/Preferences/com.saurik.WinterBoard.plist"]]) {
+        if (NSNumber *value = [settings objectForKey:@"SummerBoard"])
+            SummerBoard_ = [value boolValue];
+        if (NSNumber *value = [settings objectForKey:@"Debug"])
+            Debug_ = [value boolValue];
 
-        if (NSNumber *debug = [settings objectForKey:@"Debug"])
-            Debug_ = [debug boolValue];
-
-        NSArray *themes = [settings objectForKey:@"Themes"];
+        NSArray *themes([settings objectForKey:@"Themes"]);
         if (themes == nil)
             if (NSString *theme = [settings objectForKey:@"Theme"])
                 themes = [NSArray arrayWithObject:[NSDictionary dictionaryWithObjectsAndKeys:
                     theme, @"Name",
                     [NSNumber numberWithBool:true], @"Active",
                 nil]];
+
         if (themes != nil)
             for (NSDictionary *theme in themes) {
-                NSNumber *active = [theme objectForKey:@"Active"];
+                NSNumber *active([theme objectForKey:@"Active"]);
                 if (![active boolValue])
                     continue;
 
-                NSString *name = [theme objectForKey:@"Name"];
+                NSString *name([theme objectForKey:@"Name"]);
                 if (name == nil)
                     continue;
 
-                NSString *theme = nil;
+                NSString *theme(nil);
 
                 #define testForTheme(format...) \
                     if (theme == nil) { \
@@ -1495,18 +1498,17 @@ extern "C" void WBInitialize() {
                 testForTheme(@"/Library/Themes/%@.theme", name)
                 testForTheme(@"/Library/Themes/%@", name)
                 testForTheme(@"%@/Library/SummerBoard/Themes/%@", NSHomeDirectory(), name)
+
             }
     }
 
     Info_ = [[NSMutableDictionary dictionaryWithCapacity:16] retain];
 
     for (NSString *theme in themes_)
-        if (NSDictionary *info = [[NSDictionary alloc] initWithContentsOfFile:[NSString stringWithFormat:@"%@/Info.plist", theme]]) {
-            [info autorelease];
+        if (NSDictionary *info = [NSDictionary dictionaryWithContentsOfFile:[NSString stringWithFormat:@"%@/Info.plist", theme]])
             for (NSString *key in [info allKeys])
                 if ([Info_ objectForKey:key] == nil)
                     [Info_ setObject:[info objectForKey:key] forKey:key];
-        }
 
     bool sms($getTheme$([NSArray arrayWithObjects:@"SMSBackground.png", @"SMSBackground.jpg", nil]) != nil);
 
@@ -1540,12 +1542,16 @@ extern "C" void WBInitialize() {
             NULL, &ChangeWallpaper, (CFStringRef) @"com.saurik.winterboard.lockbackground", NULL, 0
         );
 
-        NSBundle *MediaPlayer = [NSBundle bundleWithPath:@"/System/Library/Frameworks/MediaPlayer.framework"];
-        if (MediaPlayer != nil)
-            [MediaPlayer load];
+        /*
+        if ($getTheme$([NSArray arrayWithObjects:@"Wallpaper.mp4"]) != nil) {
+            NSBundle *MediaPlayer([NSBundle bundleWithPath:@"/System/Library/Frameworks/MediaPlayer.framework"]);
+            if (MediaPlayer != nil)
+                [MediaPlayer load];
+
+            $MPMoviePlayerController = objc_getClass("MPMoviePlayerController");
+            $MPVideoView = objc_getClass("MPVideoView");
+        }*/
 
-        $MPMoviePlayerController = objc_getClass("MPMoviePlayerController");
-        $MPVideoView = objc_getClass("MPVideoView");
         $WebCoreFrameBridge = objc_getClass("WebCoreFrameBridge");
 
         $SBApplication = objc_getClass("SBApplication");
@@ -1572,8 +1578,11 @@ extern "C" void WBInitialize() {
 
         WBRename(WebCoreFrameBridge, renderedSizeOfNode:constrainedToWidth:, renderedSizeOfNode$constrainedToWidth$);
 
-        WBRename(SBApplication, pathForIcon, pathForIcon);
-        WBRename(SBApplicationIcon, icon, icon);
+        if (SummerBoard_) {
+            WBRename(SBApplication, pathForIcon, pathForIcon);
+            WBRename(SBApplicationIcon, icon, icon);
+        }
+
         WBRename(SBBookmarkIcon, icon, icon);
         WBRename(SBButtonBar, didMoveToSuperview, didMoveToSuperview);
         WBRename(SBCalendarIconContentsView, drawRect:, drawRect$);
diff --git a/Optimize.cpp b/Optimize.cpp
new file mode 100755 (executable)
index 0000000..bf5dfbe
--- /dev/null
@@ -0,0 +1,13 @@
+#include <sys/types.h>
+#include <unistd.h>
+
+#include <stdlib.h>
+
+int main(int argc, char *argv[]) {
+    setuid(0);
+    setgid(0);
+
+    system("/usr/bin/find -L /Library/Themes/ -name '*.png' -not -xtype l -print0 | /usr/bin/xargs -0 pincrush -i");
+
+    return 0;
+}
index 19fea78d8adac9bd453973c4159249437e56bd92..956d7e5acd7ad470e63bd234c0a6a9434d18c7bc 100644 (file)
@@ -60,6 +60,77 @@ static BOOL settingsChanged;
 static NSMutableDictionary *_settings;
 static NSString *_plist;
 
+/* [NSObject yieldToSelector:(withObject:)] {{{*/
+@interface NSObject (wb$yieldToSelector)
+- (id) wb$yieldToSelector:(SEL)selector withObject:(id)object;
+- (id) wb$yieldToSelector:(SEL)selector;
+@end
+
+@implementation NSObject (Cydia)
+
+- (void) wb$doNothing {
+}
+
+- (void) wb$_yieldToContext:(NSMutableArray *)context {
+    NSAutoreleasePool *pool([[NSAutoreleasePool alloc] init]);
+
+    SEL selector(reinterpret_cast<SEL>([[context objectAtIndex:0] pointerValue]));
+    id object([[context objectAtIndex:1] nonretainedObjectValue]);
+    volatile bool &stopped(*reinterpret_cast<bool *>([[context objectAtIndex:2] pointerValue]));
+
+    /* XXX: deal with exceptions */
+    id value([self performSelector:selector withObject:object]);
+
+    NSMethodSignature *signature([self methodSignatureForSelector:selector]);
+    [context removeAllObjects];
+    if ([signature methodReturnLength] != 0 && value != nil)
+        [context addObject:value];
+
+    stopped = true;
+
+    [self
+        performSelectorOnMainThread:@selector(wb$doNothing)
+        withObject:nil
+        waitUntilDone:NO
+    ];
+
+    [pool release];
+}
+
+- (id) wb$yieldToSelector:(SEL)selector withObject:(id)object {
+    /*return [self performSelector:selector withObject:object];*/
+
+    volatile bool stopped(false);
+
+    NSMutableArray *context([NSMutableArray arrayWithObjects:
+        [NSValue valueWithPointer:selector],
+        [NSValue valueWithNonretainedObject:object],
+        [NSValue valueWithPointer:const_cast<bool *>(&stopped)],
+    nil]);
+
+    NSThread *thread([[[NSThread alloc]
+        initWithTarget:self
+        selector:@selector(wb$_yieldToContext:)
+        object:context
+    ] autorelease]);
+
+    [thread start];
+
+    NSRunLoop *loop([NSRunLoop currentRunLoop]);
+    NSDate *future([NSDate distantFuture]);
+
+    while (!stopped && [loop runMode:NSDefaultRunLoopMode beforeDate:future]);
+
+    return [context count] == 0 ? nil : [context objectAtIndex:0];
+}
+
+- (id) wb$yieldToSelector:(SEL)selector {
+    return [self wb$yieldToSelector:selector withObject:nil];
+}
+
+@end
+/* }}} */
+
 /* Theme Settings Controller {{{ */
 @interface WBSThemesController: PSViewController <UITableViewDelegate, UITableViewDataSource> {
     UITableView *_tableView;
@@ -293,6 +364,29 @@ static NSString *_plist;
     [super dealloc];
 }
 
+- (void) _optimizeThemes {
+    system("/usr/libexec/winterboard/Optimize");
+}
+
+- (void) optimizeThemes {
+    UIView *view([self view]);
+    UIWindow *window([view window]);
+
+    UIProgressHUD *hud([[[UIProgressHUD alloc] initWithWindow:window] autorelease]);
+    [hud setText:@"Reticulating Splines\nPlease Wait (Minutes)"];
+
+    [window setUserInteractionEnabled:NO];
+
+    [window addSubview:hud];
+    [hud show:YES];
+    [self wb$yieldToSelector:@selector(_optimizeThemes)];
+    [hud removeFromSuperview];
+
+    [window setUserInteractionEnabled:YES];
+
+    [self settingsChanged];
+}
+
 - (void) suspend {
     if (!settingsChanged)
         return;
index e8124bbb8aec1fcf39abf37bbd5372c6d2193c56..253be244f079a3e86c6b01a62928b08bcc871250 100644 (file)
@@ -2,7 +2,8 @@
     items = ({
         cell = PSSwitchCell;
         key = IconHidden;
-        label = "Hide Application";
+        default = 0;
+        label = "Hide WinterBoard";
     }, {
         cell = PSGroupCell;
        isStaticText = true;
         label = "WinterBoard can also be found under the normal iPhone OS Settings application.";
     }, {
         cell = PSGroupCell;
+    }, {
+        cell = PSSwitchCell;
+        key = SummerBoard;
+        default = 1;
+        label = "SummerBoard Mode";
+    }, {
+        cell = PSSwitchCell;
+        key = Debug;
+        default = 0;
+        label = "Debug Logging";
+    }, {
+        cell = PSGroupCell;
     }, {
         cell = PSLinkCell;
         detail = WBSThemesController;
         icon = Themes.png;
-        label = Themes;
+        label = "Select Themes";
+    }, {
+        cell = PSGroupCell;
+    }, {
+        cell = PSButtonCell;
+        action = optimizeThemes;
+        label = "Optimize Themes (v1.0)";
+    }, {
+        cell = PSGroupCell;
+       isStaticText = true;
+    }, {
+        cell = PSTitleValueCell;
+        label = "iPhone-optimize PNGs (for speed).";
     });
 
     title = WinterBoard;
diff --git a/control b/control
index b10c1fdb35c962753b903645b4360727e423f1fb..c5bff7e8cd61c0a34408860fa32ae240ffaa8ba5 100644 (file)
--- a/control
+++ b/control
@@ -3,10 +3,10 @@ Priority: optional
 Section: System
 Maintainer: Jay Freeman (saurik) <saurik@saurik.com>
 Architecture: iphoneos-arm
-Version: 0.9.3147-1
+Version: 0.9.3151-2
 Description: more powerful, open-source SummerBoard
 Name: WinterBoard
-Depends: mobilesubstrate (>= 0.9.2958-1), killall, preferenceloader, libhide
+Depends: mobilesubstrate (>= 0.9.2958-1), killall, preferenceloader, libhide (>= 2.0.4), findutils, net.howett.pincrush (>= 0.0.1-23)
 Provides: theme-manager
 Conflicts: com.modmyifone.winterboardicon, winterboardsettings, themesettings
 Replaces: com.modmyifone.winterboardicon, winterboardsettings, themesettings
index 3c2600484658b97bf439fa292addfa42e5843f71..75594fd265fe35b4a55291521ecf4592d0a067e0 100644 (file)
--- a/makefile
+++ b/makefile
@@ -4,7 +4,7 @@ else
 target := $(PKG_TARG)-
 endif
 
-all: WinterBoard WinterBoard.dylib UIImages WinterBoardSettings
+all: WinterBoard WinterBoard.dylib UIImages WinterBoardSettings Optimize
 
 clean:
        rm -f WinterBoard WinterBoard.dylib UIImages
@@ -25,7 +25,11 @@ WinterBoard: Application.mm makefile
        $(target)g++ -g0 -O2 -Wall -Werror -o $@ $(filter %.mm,$^) -framework UIKit -framework Foundation -framework CoreFoundation -lobjc -framework CoreGraphics -I/apl/sdk -framework Preferences -F$(PKG_ROOT)/System/Library/PrivateFrameworks
        ldid -S $@
 
-package:
+Optimize: Optimize.cpp makefile
+       $(target)g++ -g0 -O2 -Wall -Werror -o $@ $(filter %.cpp,$^)
+       ldid -S $@
+
+package: all
        rm -rf winterboard
        mkdir -p winterboard/DEBIAN
        mkdir -p winterboard/Applications/WinterBoard.app
@@ -33,6 +37,9 @@ package:
        mkdir -p winterboard/Library/MobileSubstrate/DynamicLibraries
        mkdir -p winterboard/Library/PreferenceLoader/Preferences
        mkdir -p winterboard/System/Library/PreferenceBundles
+       mkdir -p winterboard/usr/libexec/winterboard
+       cp -a Optimize winterboard/usr/libexec/winterboard
+       chmod 6755 winterboard/usr/libexec/winterboard/Optimize
        cp -a WinterBoardSettings.plist winterboard/Library/PreferenceLoader/Preferences
        cp -a WinterBoardSettings.bundle winterboard/System/Library/PreferenceBundles
        cp -a Icon-Small.png winterboard/System/Library/PreferenceBundles/WinterBoardSettings.bundle/icon.png