]> git.saurik.com Git - cydia.git/blobdiff - MobileCydia.mm
Standardize [super reloadData] placement.
[cydia.git] / MobileCydia.mm
index 6b43a70b3dfd7fef5628557c4efb77bfe939d1d3..e278ab8605eea1614914794652904b319504d9a0 100644 (file)
@@ -1086,6 +1086,8 @@ bool IsWildcat_;
 static CGFloat ScreenScale_;
 static NSString *Idiom_;
 
+static NSMutableDictionary *SessionData_;
+static NSObject *HostConfig_;
 static NSMutableSet *BridgedHosts_;
 static NSMutableSet *PipelinedHosts_;
 
@@ -4232,6 +4234,8 @@ static NSMutableSet *Diversions_;
         return @"getInstalledPackages";
     else if (selector == @selector(getPackageById:))
         return @"getPackageById";
+    else if (selector == @selector(getSessionValue:))
+        return @"getSessionValue";
     else if (selector == @selector(installPackages:))
         return @"installPackages";
     else if (selector == @selector(localizedStringForKey:value:table:))
@@ -4242,6 +4246,8 @@ static NSMutableSet *Diversions_;
         return @"refreshSources";
     else if (selector == @selector(removeButton))
         return @"removeButton";
+    else if (selector == @selector(setSessionValue::))
+        return @"setSessionValue";
     else if (selector == @selector(substitutePackageNames:))
         return @"substitutePackageNames";
     else if (selector == @selector(scrollToBottom:))
@@ -4320,16 +4326,31 @@ static NSMutableSet *Diversions_;
     return [NSString stringWithCString:value];
 }
 
+- (id) getSessionValue:(NSString *)key {
+@synchronized (SessionData_) {
+    return [SessionData_ objectForKey:key];
+} }
+
+- (void) setSessionValue:(NSString *)key :(NSString *)value {
+@synchronized (SessionData_) {
+    if (value == (id) [WebUndefined undefined])
+        [SessionData_ removeObjectForKey:key];
+    else
+        [SessionData_ setObject:value forKey:key];
+} }
+
 - (void) addBridgedHost:(NSString *)host {
-    [BridgedHosts_ performSelectorOnMainThread:@selector(addObject:) withObject:host waitUntilDone:NO];
-}
+@synchronized (HostConfig_) {
+    [BridgedHosts_ addObject:host];
+} }
 
 - (void) addPipelinedHost:(NSString *)host scheme:(NSString *)scheme {
+@synchronized (HostConfig_) {
     if (scheme != (id) [WebUndefined undefined])
         host = [NSString stringWithFormat:@"%@:%@", [scheme lowercaseString], host];
 
-    [PipelinedHosts_ performSelectorOnMainThread:@selector(addObject:) withObject:host waitUntilDone:NO];
-}
+    [PipelinedHosts_ addObject:host];
+} }
 
 - (void) popViewController:(NSNumber *)value {
     if (value == (id) [WebUndefined undefined])
@@ -4668,9 +4689,11 @@ static NSMutableSet *Diversions_;
     NSURLResponse *response([source response]);
     NSURL *url([response URL]);
 
-    if ([[[url scheme] lowercaseString] isEqualToString:@"https"])
-        if ([BridgedHosts_ containsObject:[url host]])
-            [window setValue:cydia_ forKey:@"cydia"];
+    @synchronized (HostConfig_) {
+        if ([[[url scheme] lowercaseString] isEqualToString:@"https"])
+            if ([BridgedHosts_ containsObject:[url host]])
+                [window setValue:cydia_ forKey:@"cydia"];
+    }
 }
 
 - (NSURLRequest *) webView:(WebView *)view resource:(id)resource willSendRequest:(NSURLRequest *)request redirectResponse:(NSURLResponse *)response fromDataSource:(WebDataSource *)source {
@@ -5257,9 +5280,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
 }
 
 - (void) viewWillAppear:(BOOL)animated {
-    if (![self hasLoaded])
-        [[[self navigationController] navigationBar] setBarStyle:UIBarStyleBlack];
-
+    [[[self navigationController] navigationBar] setBarStyle:UIBarStyleBlack];
     [super viewWillAppear:animated];
 }
 
@@ -6148,6 +6169,8 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
 }
 
 - (void) reloadData {
+    [super reloadData];
+
     package_ = [database_ packageWithName:name_];
 
     [buttons_ removeAllObjects];
@@ -6183,8 +6206,6 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
         target:self
         action:@selector(customButtonClicked)
     ] autorelease];
-
-    [super reloadData];
 }
 
 - (bool) isLoading {
@@ -7506,7 +7527,6 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
     NSMutableArray *sections_;
     UITableView *list_;
     unsigned upgrades_;
-    BOOL hasSentFirstLoad_;
 }
 
 - (id) initWithDatabase:(Database *)database;
@@ -7527,21 +7547,9 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
     return [NSURL URLWithString:@"cydia://changes"];
 }
 
-- (void) viewWillAppear:(BOOL)animated {
-    // Loads after it appears, so don't load beforehand.
-    loaded_ = YES;
-    [super viewWillAppear:animated];
-}
-
 - (void) viewDidAppear:(BOOL)animated {
     [super viewDidAppear:animated];
-
-    if (!hasSentFirstLoad_) {
-        hasSentFirstLoad_ = YES;
-        [self performSelector:@selector(reloadData) withObject:nil afterDelay:0.0];
-    } else {
-        [list_ deselectRowAtIndexPath:[list_ indexPathForSelectedRow] animated:animated];
-    }
+    [list_ deselectRowAtIndexPath:[list_ indexPathForSelectedRow] animated:animated];
 }
 
 - (NSInteger) numberOfSectionsInTableView:(UITableView *)list {
@@ -7651,7 +7659,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
     _trace();
 }
 
-- (void) reloadData {
+- (void) _reloadData {
 @synchronized (database_) {
     era_ = [database_ era];
     NSArray *packages = [database_ packages];
@@ -7749,6 +7757,11 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
     PrintTimes();
 } }
 
+- (void) reloadData {
+    [super reloadData];
+    [self performSelector:@selector(_reloadData) withObject:nil afterDelay:0];
+}
+
 @end
 /* }}} */
 /* Search Controller {{{ */
@@ -7825,8 +7838,9 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
 
 - (void) reloadData {
     [self setObject:[search_ text]];
-    [super reloadData];
     [self resetCursor];
+
+    [super reloadData];
 }
 
 - (void) didSelectPackage:(Package *)package {
@@ -8220,6 +8234,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
     [key_ release];
     key_ = [[source_ key] retain];
     [self setObject:source_];
+
     [[self navigationItem] setTitle:[source_ label]];
 
     [super reloadData];
@@ -8874,6 +8889,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
 
 - (void) reloadData {
     [super reloadData];
+
     [table_ reloadData];
 }
 
@@ -9775,7 +9791,9 @@ _trace();
     if ([self respondsToSelector:@selector(setApplicationSupportsShakeToEdit:)])
         [self setApplicationSupportsShakeToEdit:NO];
 
-    [BridgedHosts_ addObject:[[NSURL URLWithString:CydiaURL(@"")] host]];
+    @synchronized (HostConfig_) {
+        [BridgedHosts_ addObject:[[NSURL URLWithString:CydiaURL(@"")] host]];
+    }
 
     [NSURLCache setSharedURLCache:[[[SDURLCache alloc]
         initWithMemoryCapacity:524288
@@ -10039,9 +10057,11 @@ MSHook(id, NSURLConnection$init$, NSURLConnection *self, SEL _cmd, NSURLRequest
 
     NSString *compound([NSString stringWithFormat:@"%@:%@", scheme, host]);
 
-    if ([copy respondsToSelector:@selector(setHTTPShouldUsePipelining:)])
-        if ([PipelinedHosts_ containsObject:host] || [PipelinedHosts_ containsObject:compound])
-            [copy setHTTPShouldUsePipelining:YES];
+    @synchronized (HostConfig_) {
+        if ([copy respondsToSelector:@selector(setHTTPShouldUsePipelining:)])
+            if ([PipelinedHosts_ containsObject:host] || [PipelinedHosts_ containsObject:compound])
+                [copy setHTTPShouldUsePipelining:YES];
+    }
 
     if ((self = _NSURLConnection$init$(self, _cmd, copy, delegate, usesCache, maxContentLength, startImmediately, connectionProperties)) != nil) {
     } return self;
@@ -10077,8 +10097,13 @@ int main(int argc, char *argv[]) { _pooled
             NSLog(@"unknown UIUserInterfaceIdiom!");
     }
 
-    BridgedHosts_ = [NSMutableSet setWithCapacity:2];
-    PipelinedHosts_ = [NSMutableSet setWithCapacity:2];
+    SessionData_ = [[NSMutableDictionary alloc] initWithCapacity:4];
+
+    HostConfig_ = [[NSObject alloc] init];
+    @synchronized (HostConfig_) {
+        BridgedHosts_ = [NSMutableSet setWithCapacity:4];
+        PipelinedHosts_ = [NSMutableSet setWithCapacity:4];
+    }
 
     UI_ = CydiaURL([NSString stringWithFormat:@"ui/ios~%@", Idiom_]);