]> git.saurik.com Git - cydia.git/blobdiff - MobileCydia.mm
Steal more entitlements from MobileSafari: I want Nitro.
[cydia.git] / MobileCydia.mm
index badaa61a8b2a4fb9779c9a5458edbbb774e40133..e6e6949575ac82208e078956ad08b31d83f386a2 100644 (file)
@@ -126,10 +126,12 @@ extern "C" {
 #include <CydiaSubstrate/CydiaSubstrate.h>
 #include "Menes/Menes.h"
 
+#include "CyteKit/IndirectDelegate.h"
 #include "CyteKit/PerlCompatibleRegEx.hpp"
 #include "CyteKit/TableViewCell.h"
 #include "CyteKit/WebScriptObject-Cyte.h"
 #include "CyteKit/WebViewController.h"
+#include "CyteKit/WebViewTableViewCell.h"
 #include "CyteKit/stringWithUTF8Bytes.h"
 
 #include "Cydia/MIMEAddress.h"
@@ -247,11 +249,15 @@ union SplitHash {
 };
 // }}}
 
+static bool ShowPromoted_;
+
 static NSString *Colon_;
 NSString *Elision_;
 static NSString *Error_;
 static NSString *Warning_;
 
+static bool AprilFools_;
+
 static const NSUInteger UIViewAutoresizingFlexibleBoth(UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight);
 
 static _finline NSString *CydiaURL(NSString *path) {
@@ -3930,11 +3936,16 @@ static _H<NSMutableSet> Diversions_;
 
 @end
 
+@class CydiaObject;
+
 @interface CydiaWebViewController : CyteWebViewController {
     _H<CydiaObject> cydia_;
 }
 
 + (void) addDiversion:(Diversion *)diversion;
++ (NSURLRequest *) requestWithHeaders:(NSURLRequest *)request;
++ (void) didClearWindowObject:(WebScriptObject *)window forFrame:(WebFrame *)frame withCydia:(CydiaObject *)cydia;
+- (void) setDelegate:(id)delegate;
 
 @end
 
@@ -4110,6 +4121,8 @@ static _H<NSMutableSet> Diversions_;
         return @"setMetadataValue";
     else if (selector == @selector(setSessionValue::))
         return @"setSessionValue";
+    else if (selector == @selector(setShowPromoted:))
+        return @"setShowPromoted";
     else if (selector == @selector(substitutePackageNames:))
         return @"substitutePackageNames";
     else if (selector == @selector(scrollToBottom:))
@@ -4225,6 +4238,15 @@ static _H<NSMutableSet> Diversions_;
     return [Values_ allKeys];
 } }
 
+- (void) _setShowPromoted:(NSNumber *)value {
+    [Metadata_ setObject:value forKey:@"ShowPromoted"];
+    Changed_ = true;
+}
+
+- (void) setShowPromoted:(NSNumber *)value {
+    [self performSelectorOnMainThread:@selector(_setShowPromoted:) withObject:value waitUntilDone:NO];
+}
+
 - (id) getMetadataValue:(NSString *)key {
 @synchronized (Values_) {
     return [Values_ objectForKey:key];
@@ -4537,7 +4559,10 @@ static _H<NSMutableSet> Diversions_;
 
 - (void) webView:(WebView *)view didClearWindowObject:(WebScriptObject *)window forFrame:(WebFrame *)frame {
     [super webView:view didClearWindowObject:window forFrame:frame];
+    [CydiaWebViewController didClearWindowObject:window forFrame:frame withCydia:cydia_];
+}
 
++ (void) didClearWindowObject:(WebScriptObject *)window forFrame:(WebFrame *)frame withCydia:(CydiaObject *)cydia {
     WebDataSource *source([frame dataSource]);
     NSURLResponse *response([source response]);
     NSURL *url([response URL]);
@@ -4554,7 +4579,7 @@ static _H<NSMutableSet> Diversions_;
     }
 
     if (bridged)
-        [window setValue:cydia_ forKey:@"cydia"];
+        [window setValue:cydia forKey:@"cydia"];
 }
 
 - (void) _setupMail:(MFMailComposeViewController *)controller {
@@ -4569,10 +4594,14 @@ static _H<NSMutableSet> Diversions_;
 }
 
 - (NSURLRequest *) webView:(WebView *)view resource:(id)resource willSendRequest:(NSURLRequest *)request redirectResponse:(NSURLResponse *)response fromDataSource:(WebDataSource *)source {
-    NSURL *url([request URL]);
-    NSString *host([url host]);
+    return [CydiaWebViewController requestWithHeaders:[super webView:view resource:resource willSendRequest:request redirectResponse:response fromDataSource:source]];
+}
 
-    NSMutableURLRequest *copy([[super webView:view resource:resource willSendRequest:request redirectResponse:response fromDataSource:source] mutableCopy]);
++ (NSURLRequest *) requestWithHeaders:(NSURLRequest *)request {
+    NSMutableURLRequest *copy([request mutableCopy]);
+
+    NSURL *url([copy URL]);
+    NSString *host([url host]);
 
     if ([copy valueForHTTPHeaderField:@"X-Cydia-Cf-Version"] == nil)
         [copy setValue:[NSString stringWithFormat:@"%.2f", kCFCoreFoundationVersionNumber] forHTTPHeaderField:@"X-Cydia-Cf-Version"];
@@ -5776,14 +5805,12 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
 }
 
 - (void) loadView {
-    [self setView:[[[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]] autorelease]];
-
-    list_ = [[[UITableView alloc] initWithFrame:[[self view] bounds]] autorelease];
+    list_ = [[[UITableView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]] autorelease];
     [list_ setAutoresizingMask:UIViewAutoresizingFlexibleBoth];
     [list_ setRowHeight:24.0f];
     [(UITableView *) list_ setDataSource:self];
     [list_ setDelegate:self];
-    [[self view] addSubview:list_];
+    [self setView:list_];
 }
 
 - (void) viewDidLoad {
@@ -6227,11 +6254,13 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
 }
 
 - (void) loadView {
-    [self setView:[[[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]] autorelease]];
+    UIView *view([[[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]] autorelease]);
+    [view setAutoresizingMask:(UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight)];
+    [self setView:view];
 
     list_ = [[[UITableView alloc] initWithFrame:[[self view] bounds] style:UITableViewStylePlain] autorelease];
     [list_ setAutoresizingMask:UIViewAutoresizingFlexibleBoth];
-    [[self view] addSubview:list_];
+    [view addSubview:list_];
 
     // XXX: is 20 the most optimal number here?
     [list_ setSectionIndexMinimumDisplayRowCount:20];
@@ -7184,7 +7213,10 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
 
 /* Section Controller {{{ */
 @interface SectionController : FilteredPackageListController {
+    _H<IndirectDelegate, 1> indirect_;
+    _H<CydiaObject> cydia_;
     _H<NSString> section_;
+    std::vector< _H<CyteWebViewTableViewCell, 1> > promoted_;
 }
 
 - (id) initWithDatabase:(Database *)database section:(NSString *)section;
@@ -7198,7 +7230,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
     if (name == nil)
         name = @"all";
 
-    return [NSURL URLWithString:[NSString stringWithFormat:@"cydia://sections/%@", name]];
+    return [NSURL URLWithString:[NSString stringWithFormat:@"cydia://sections/%@", [name stringByAddingPercentEscapesIncludingReserved]]];
 }
 
 - (id) initWithDatabase:(Database *)database section:(NSString *)name {
@@ -7211,10 +7243,102 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
         title = UCLocalize("NO_SECTION");
 
     if ((self = [super initWithDatabase:database title:title filter:@selector(isVisibleInSection:) with:name]) != nil) {
+        indirect_ = [[[IndirectDelegate alloc] initWithDelegate:self] autorelease];
+        cydia_ = [[[CydiaObject alloc] initWithDelegate:indirect_] autorelease];
         section_ = name;
     } return self;
 }
 
+- (NSInteger) numberOfSectionsInTableView:(UITableView *)list {
+    return [super numberOfSectionsInTableView:list] + 1;
+}
+
+- (NSString *) tableView:(UITableView *)list titleForHeaderInSection:(NSInteger)section {
+    return section == 0 ? nil : [super tableView:list titleForHeaderInSection:(section - 1)];
+}
+
+- (NSInteger) tableView:(UITableView *)list numberOfRowsInSection:(NSInteger)section {
+    return section == 0 ? promoted_.size() : [super tableView:list numberOfRowsInSection:(section - 1)];
+}
+
++ (NSIndexPath *) adjustedIndexPath:(NSIndexPath *)path {
+    return [NSIndexPath indexPathForRow:[path row] inSection:([path section] - 1)];
+}
+
+- (UITableViewCell *) tableView:(UITableView *)table cellForRowAtIndexPath:(NSIndexPath *)path {
+    if ([path section] != 0)
+        return [super tableView:table cellForRowAtIndexPath:[SectionController adjustedIndexPath:path]];
+
+    return promoted_[[path row]];
+}
+
+- (void) tableView:(UITableView *)table didSelectRowAtIndexPath:(NSIndexPath *)path {
+    if ([path section] != 0)
+        return [super tableView:table didSelectRowAtIndexPath:[SectionController adjustedIndexPath:path]];
+}
+
+- (NSInteger) tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index {
+    NSInteger section([super tableView:tableView sectionForSectionIndexTitle:title atIndex:index]);
+    return section == 0 ? 0 : section + 1;
+}
+
+- (void) webView:(WebView *)view decidePolicyForNewWindowAction:(NSDictionary *)action request:(NSURLRequest *)request newFrameName:(NSString *)frame decisionListener:(id<WebPolicyDecisionListener>)listener {
+    NSURL *url([request URL]);
+    if (url == nil)
+        return;
+
+    if ([frame isEqualToString:@"_open"])
+        [delegate_ openURL:url];
+    else {
+        CyteViewController *controller([delegate_ pageForURL:url forExternal:NO] ?: [[[CydiaWebViewController alloc] initWithRequest:request] autorelease]);
+        [controller setDelegate:delegate_];
+        [[self navigationController] pushViewController:controller animated:YES];
+    }
+
+    [listener ignore];
+}
+
+- (NSURLRequest *) webView:(WebView *)view resource:(id)resource willSendRequest:(NSURLRequest *)request redirectResponse:(NSURLResponse *)response fromDataSource:(WebDataSource *)source {
+    return [CydiaWebViewController requestWithHeaders:request];
+}
+
+- (void) webView:(WebView *)view didClearWindowObject:(WebScriptObject *)window forFrame:(WebFrame *)frame {
+    [CydiaWebViewController didClearWindowObject:window forFrame:frame withCydia:cydia_];
+}
+
+- (void) loadView {
+    [super loadView];
+
+    // XXX: this code is horrible. I mean, wtf Jay?
+    if (ShowPromoted_ && [[Metadata_ objectForKey:@"ShowPromoted"] boolValue]) {
+        promoted_.resize(1);
+
+        for (unsigned i(0); i != promoted_.size(); ++i) {
+            CyteWebViewTableViewCell *promoted([CyteWebViewTableViewCell cellWithRequest:[NSURLRequest
+                requestWithURL:[Diversion divertURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@/#!/sectionhead/%u/%@",
+                    UI_, i, section_ == nil ? @"" : [section_ stringByAddingPercentEscapesIncludingReserved]]
+                ]]
+
+                cachePolicy:NSURLRequestUseProtocolCachePolicy
+                timeoutInterval:120
+            ]]);
+
+            [promoted setDelegate:self];
+            promoted_[i] = promoted;
+        }
+    }
+}
+
+- (void) setDelegate:(id)delegate {
+    [super setDelegate:delegate];
+    [cydia_ setDelegate:delegate];
+}
+
+- (void) releaseSubviews {
+    promoted_.clear();
+    [super releaseSubviews];
+}
+
 @end
 /* }}} */
 /* Sections Controller {{{ */
@@ -7325,14 +7449,12 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
 }
 
 - (void) loadView {
-    [self setView:[[[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]] autorelease]];
-
-    list_ = [[[UITableView alloc] initWithFrame:[[self view] bounds]] autorelease];
+    list_ = [[[UITableView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]] autorelease];
     [list_ setAutoresizingMask:UIViewAutoresizingFlexibleBoth];
     [list_ setRowHeight:45.0f];
     [(UITableView *) list_ setDataSource:self];
     [list_ setDelegate:self];
-    [[self view] addSubview:list_];
+    [self setView:list_];
 }
 
 - (void) viewDidLoad {
@@ -7430,7 +7552,10 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
     _H<NSArray> packages_;
     _H<NSMutableArray> sections_;
     _H<UITableView, 2> list_;
+    _H<CyteWebView, 1> dickbar_;
     unsigned upgrades_;
+    _H<IndirectDelegate, 1> indirect_;
+    _H<CydiaObject> cydia_;
 }
 
 - (id) initWithDatabase:(Database *)database;
@@ -7507,20 +7632,91 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
 }
 
 - (void) loadView {
-    [self setView:[[[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]] autorelease]];
+    UIView *view([[[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]] autorelease]);
+    [view setAutoresizingMask:(UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight)];
+    [self setView:view];
 
-    list_ = [[[UITableView alloc] initWithFrame:[[self view] bounds] style:UITableViewStylePlain] autorelease];
+    list_ = [[[UITableView alloc] initWithFrame:[view bounds] style:UITableViewStylePlain] autorelease];
     [list_ setAutoresizingMask:UIViewAutoresizingFlexibleBoth];
     [list_ setRowHeight:73];
     [(UITableView *) list_ setDataSource:self];
     [list_ setDelegate:self];
-    [[self view] addSubview:list_];
+    [view addSubview:list_];
+
+    if (AprilFools_ && kCFCoreFoundationVersionNumber >= kCFCoreFoundationVersionNumber_iPhoneOS_3_0) {
+        CGRect dickframe([view bounds]);
+        dickframe.size.height = 44;
+
+        dickbar_ = [[[CyteWebView alloc] initWithFrame:dickframe] autorelease];
+        [dickbar_ setDelegate:self];
+        [view addSubview:dickbar_];
+
+        [dickbar_ setBackgroundColor:[UIColor clearColor]];
+        [dickbar_ setScalesPageToFit:YES];
+
+        UIWebDocumentView *document([dickbar_ _documentView]);
+        [document setBackgroundColor:[UIColor clearColor]];
+        [document setDrawsBackground:NO];
+
+        WebView *webview([document webView]);
+        [webview setShouldUpdateWhileOffscreen:NO];
+
+        UIScrollView *scroller([dickbar_ scrollView]);
+        [scroller setScrollingEnabled:NO];
+        [scroller setFixedBackgroundPattern:YES];
+        [scroller setBackgroundColor:[UIColor clearColor]];
+
+        WebPreferences *preferences([webview preferences]);
+        [preferences setCacheModel:WebCacheModelDocumentBrowser];
+        [preferences setJavaScriptCanOpenWindowsAutomatically:YES];
+        [preferences setOfflineWebApplicationCacheEnabled:YES];
+
+        [dickbar_ loadRequest:[NSURLRequest
+            requestWithURL:[Diversion divertURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@/#!/dickbar/", UI_]]]
+            cachePolicy:NSURLRequestUseProtocolCachePolicy
+            timeoutInterval:120
+        ]];
+
+        UIEdgeInsets inset = {44, 0, 0, 0};
+        [list_ setContentInset:inset];
+
+        [dickbar_ setAutoresizingMask:UIViewAutoresizingFlexibleWidth];
+    }
+}
+
+- (void) webView:(WebView *)view decidePolicyForNewWindowAction:(NSDictionary *)action request:(NSURLRequest *)request newFrameName:(NSString *)frame decisionListener:(id<WebPolicyDecisionListener>)listener {
+    NSURL *url([request URL]);
+    if (url == nil)
+        return;
+
+    if ([frame isEqualToString:@"_open"])
+        [delegate_ openURL:url];
+    else {
+        CyteViewController *controller([delegate_ pageForURL:url forExternal:NO] ?: [[[CydiaWebViewController alloc] initWithRequest:request] autorelease]);
+        [controller setDelegate:delegate_];
+        [[self navigationController] pushViewController:controller animated:YES];
+    }
+
+    [listener ignore];
+}
+
+- (NSURLRequest *) webView:(WebView *)view resource:(id)resource willSendRequest:(NSURLRequest *)request redirectResponse:(NSURLResponse *)response fromDataSource:(WebDataSource *)source {
+    return [CydiaWebViewController requestWithHeaders:request];
+}
+
+- (void) webView:(WebView *)view didClearWindowObject:(WebScriptObject *)window forFrame:(WebFrame *)frame {
+    [CydiaWebViewController didClearWindowObject:window forFrame:frame withCydia:cydia_];
+}
+
+- (void) setDelegate:(id)delegate {
+    [super setDelegate:delegate];
+    [cydia_ setDelegate:delegate];
 }
 
 - (void) viewDidLoad {
     [super viewDidLoad];
 
-    [[self navigationItem] setTitle:UCLocalize("CHANGES")];
+    [[self navigationItem] setTitle:(AprilFools_ ? @"Timeline" : UCLocalize("CHANGES"))];
 }
 
 - (void) releaseSubviews {
@@ -7528,12 +7724,15 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
 
     packages_ = nil;
     sections_ = nil;
+    dickbar_ = nil;
 
     [super releaseSubviews];
 }
 
 - (id) initWithDatabase:(Database *)database {
     if ((self = [super init]) != nil) {
+        indirect_ = [[[IndirectDelegate alloc] initWithDelegate:self] autorelease];
+        cydia_ = [[[CydiaObject alloc] initWithDelegate:indirect_] autorelease];
         database_ = database;
     } return self;
 }
@@ -7686,7 +7885,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
     if ([search_ text] == nil || [[search_ text] isEqualToString:@""])
         return [NSURL URLWithString:@"cydia://search"];
     else
-        return [NSURL URLWithString:[NSString stringWithFormat:@"cydia://search/%@", [search_ text]]];
+        return [NSURL URLWithString:[NSString stringWithFormat:@"cydia://search/%@", [[search_ text] stringByAddingPercentEscapesIncludingReserved]]];
 }
 
 - (void) useSearch {
@@ -7907,13 +8106,15 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
 }
 
 - (void) loadView {
-    [self setView:[[[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]] autorelease]];
+    UIView *view([[[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]] autorelease]);
+    [view setAutoresizingMask:(UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight)];
+    [self setView:view];
 
     table_ = [[[UITableView alloc] initWithFrame:[[self view] bounds] style:UITableViewStyleGrouped] autorelease];
     [table_ setAutoresizingMask:UIViewAutoresizingFlexibleBoth];
     [(UITableView *) table_ setDataSource:self];
     [table_ setDelegate:self];
-    [[self view] addSubview:table_];
+    [view addSubview:table_];
 
     subscribedSwitch_ = [[[UISwitch alloc] initWithFrame:CGRectMake(0, 0, 50, 20)] autorelease];
     [subscribedSwitch_ setAutoresizingMask:UIViewAutoresizingFlexibleLeftMargin];
@@ -8503,14 +8704,12 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
 }
 
 - (void) loadView {
-    [self setView:[[[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]] autorelease]];
-
-    list_ = [[[UITableView alloc] initWithFrame:[[self view] bounds] style:UITableViewStylePlain] autorelease];
+    list_ = [[[UITableView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame] style:UITableViewStylePlain] autorelease];
     [list_ setAutoresizingMask:UIViewAutoresizingFlexibleBoth];
     [list_ setRowHeight:53];
     [(UITableView *) list_ setDataSource:self];
     [list_ setDelegate:self];
-    [[self view] addSubview:list_];
+    [self setView:list_];
 }
 
 - (void) viewDidLoad {
@@ -8651,13 +8850,11 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
 @implementation SettingsController
 
 - (void) loadView {
-    [self setView:[[[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]] autorelease]];
-
-    table_ = [[[UITableView alloc] initWithFrame:[[self view] bounds] style:UITableViewStyleGrouped] autorelease];
+    table_ = [[[UITableView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame] style:UITableViewStyleGrouped] autorelease];
     [table_ setAutoresizingMask:UIViewAutoresizingFlexibleBoth];
     [table_ setDelegate:self];
     [(UITableView *) table_ setDataSource:self];
-    [[self view] addSubview:table_];
+    [self setView:table_];
 
     NSArray *items = [NSArray arrayWithObjects:
         UCLocalize("USER"),
@@ -8834,8 +9031,11 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
 @implementation StashController
 
 - (void) loadView {
-    [self setView:[[[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]] autorelease]];
-    [[self view] setBackgroundColor:[UIColor viewFlipsideBackgroundColor]];
+    UIView *view([[[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]] autorelease]);
+    [view setAutoresizingMask:(UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight)];
+    [self setView:view];
+
+    [view setBackgroundColor:[UIColor viewFlipsideBackgroundColor]];
 
     spinner_ = [[[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge] autorelease];
     CGRect spinrect = [spinner_ frame];
@@ -8843,7 +9043,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
     spinrect.origin.y = [[self view] frame].size.height - 80.0f;
     [spinner_ setFrame:spinrect];
     [spinner_ setAutoresizingMask:UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleTopMargin];
-    [[self view] addSubview:spinner_];
+    [view addSubview:spinner_];
     [spinner_ startAnimating];
 
     CGRect captrect;
@@ -8859,7 +9059,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
     [caption_ setBackgroundColor:[UIColor clearColor]];
     [caption_ setShadowColor:[UIColor blackColor]];
     [caption_ setTextAlignment:UITextAlignmentCenter];
-    [[self view] addSubview:caption_];
+    [view addSubview:caption_];
 
     CGRect statusrect;
     statusrect.size.width = [[self view] frame].size.width;
@@ -8874,7 +9074,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
     [status_ setBackgroundColor:[UIColor clearColor]];
     [status_ setShadowColor:[UIColor blackColor]];
     [status_ setTextAlignment:UITextAlignmentCenter];
-    [[self view] addSubview:status_];
+    [view addSubview:status_];
 }
 
 - (void) releaseSubviews {
@@ -9525,8 +9725,12 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
     NSString *path([[url absoluteString] substringFromIndex:[scheme length] + 3]);
     NSArray *components([path componentsSeparatedByString:@"/"]);
 
-    if ([scheme isEqualToString:@"apptapp"] && [components count] > 0 && [[components objectAtIndex:0] isEqualToString:@"package"])
-        return [self pageForPackage:[components objectAtIndex:1]];
+    if ([scheme isEqualToString:@"apptapp"] && [components count] > 0 && [[components objectAtIndex:0] isEqualToString:@"package"]) {
+        CyteViewController *controller([self pageForPackage:[components objectAtIndex:1]]);
+        if (controller != nil)
+            [controller setDelegate:self];
+        return controller;
+    }
 
     if ([components count] < 1 || ![scheme isEqualToString:@"cydia"])
         return nil;
@@ -9579,13 +9783,13 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
         }
 
         if (!external && [base isEqualToString:@"search"]) {
-            controller = [[[SearchController alloc] initWithDatabase:database_ query:argument] autorelease];
+            controller = [[[SearchController alloc] initWithDatabase:database_ query:[argument stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding]] autorelease];
         }
 
         if (!external && [base isEqualToString:@"sections"]) {
             if ([argument isEqualToString:@"all"])
                 argument = nil;
-            controller = [[[SectionController alloc] initWithDatabase:database_ section:argument] autorelease];
+            controller = [[[SectionController alloc] initWithDatabase:database_ section:[argument stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding]] autorelease];
         }
 
         if (!external && [base isEqualToString:@"sources"]) {
@@ -9727,7 +9931,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
     NSMutableArray *items([NSMutableArray arrayWithObjects:
         [[[UITabBarItem alloc] initWithTitle:@"Cydia" image:[UIImage applicationImageNamed:@"home.png"] tag:0] autorelease],
         [[[UITabBarItem alloc] initWithTitle:UCLocalize("SECTIONS") image:[UIImage applicationImageNamed:@"install.png"] tag:0] autorelease],
-        [[[UITabBarItem alloc] initWithTitle:UCLocalize("CHANGES") image:[UIImage applicationImageNamed:@"changes.png"] tag:0] autorelease],
+        [[[UITabBarItem alloc] initWithTitle:(AprilFools_ ? @"Timeline" : UCLocalize("CHANGES")) image:[UIImage applicationImageNamed:@"changes.png"] tag:0] autorelease],
         [[[UITabBarItem alloc] initWithTitle:UCLocalize("SEARCH") image:[UIImage applicationImageNamed:@"search.png"] tag:0] autorelease],
     nil]);
 
@@ -9764,6 +9968,11 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
     }
 }
 
+- (void) applicationDidReceiveMemoryWarning:(UIApplication *)application {
+    NSLog(@"--");
+    [[NSURLCache sharedURLCache] removeAllCachedResponses];
+}
+
 - (void) applicationDidFinishLaunching:(id)unused {
     //[NSThread detachNewThreadSelector:@selector(_sendMemoryWarningNotifications) toTarget:self withObject:nil];
 
@@ -9884,8 +10093,8 @@ _trace();
     NSDate *closed = [Metadata_ objectForKey:@"LastClosed"];
     if (valid && closed != nil) {
         NSTimeInterval interval([closed timeIntervalSinceNow]);
-        // XXX: Is 60 minutes the optimal time here?
-        if (interval <= -(60*60))
+        // XXX: Is 30 minutes the optimal time here?
+        if (interval <= -(30*60))
             valid = NO;
     }
 
@@ -10424,11 +10633,21 @@ int main(int argc, char *argv[]) {
     //UIKeyboardDisableAutomaticAppearance();
     /* }}} */
 
+    BOOL (*GSSystemHasCapability)(CFStringRef) = reinterpret_cast<BOOL (*)(CFStringRef)>(dlsym(RTLD_DEFAULT, "GSSystemHasCapability"));
+    ShowPromoted_ = GSSystemHasCapability != NULL && GSSystemHasCapability(CFSTR("armv7"));
+
     Colon_ = UCLocalize("COLON_DELIMITED");
     Elision_ = UCLocalize("ELISION");
     Error_ = UCLocalize("ERROR");
     Warning_ = UCLocalize("WARNING");
 
+#if !ForRelease
+    AprilFools_ = true;
+#else
+    CFGregorianDate date(CFAbsoluteTimeGetGregorianDate(CFAbsoluteTimeGetCurrent(), CFTimeZoneCopySystem()));
+    AprilFools_ = date.month == 4 && date.day == 1;
+#endif
+
     _trace();
     int value(UIApplicationMain(argc, argv, @"Cydia", @"Cydia"));