Revision: 4113
          http://skim-app.svn.sourceforge.net/skim-app/?rev=4113&view=rev
Author:   hofman
Date:     2008-07-01 04:57:21 -0700 (Tue, 01 Jul 2008)

Log Message:
-----------
Use asynch URL connection on main thread to load appcast, as a synch connection 
on a thread leaks.

Modified Paths:
--------------
    trunk/vendorsrc/andymatuschak/Sparkle/SUAppcast.h
    trunk/vendorsrc/andymatuschak/Sparkle/SUAppcast.m

Modified: trunk/vendorsrc/andymatuschak/Sparkle/SUAppcast.h
===================================================================
--- trunk/vendorsrc/andymatuschak/Sparkle/SUAppcast.h   2008-06-30 20:09:01 UTC 
(rev 4112)
+++ trunk/vendorsrc/andymatuschak/Sparkle/SUAppcast.h   2008-07-01 11:57:21 UTC 
(rev 4113)
@@ -8,8 +8,9 @@
 
 #import <Cocoa/Cocoa.h>
 
[EMAIL PROTECTED] RSS, SUAppcastItem;
[EMAIL PROTECTED] SUAppcastItem;
 @interface SUAppcast : NSObject {
+    NSMutableData *data;
        NSArray *items;
        id delegate;
 }
@@ -23,5 +24,6 @@
 @end
 
 @interface NSObject (SUAppcastDelegate)
-- appcastDidFinishLoading:(SUAppcast *)appcast;
+- (void)appcastDidFinishLoading:(SUAppcast *)appcast;
+- (void)appcastDidFailToLoad:(SUAppcast *)appcast;
 @end
\ No newline at end of file

Modified: trunk/vendorsrc/andymatuschak/Sparkle/SUAppcast.m
===================================================================
--- trunk/vendorsrc/andymatuschak/Sparkle/SUAppcast.m   2008-06-30 20:09:01 UTC 
(rev 4112)
+++ trunk/vendorsrc/andymatuschak/Sparkle/SUAppcast.m   2008-07-01 11:57:21 UTC 
(rev 4113)
@@ -14,7 +14,11 @@
 
 - (void)fetchAppcastFromURL:(NSURL *)url
 {
-       [NSThread detachNewThreadSelector:@selector(_fetchAppcastFromURL:) 
toTarget:self withObject:url]; // let's not block the main thread
+    NSURLRequest *request = [NSURLRequest requestWithURL:url 
cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:60.0];
+            
+    data = [[NSMutableData alloc] init];
+    NSURLConnection *connection = [NSURLConnection 
connectionWithRequest:request delegate:self];
+    [connection retain];
 }
 
 - (void)setDelegate:del
@@ -24,13 +28,14 @@
 
 - (void)dealloc
 {
+       [data release];
        [items release];
        [super dealloc];
 }
 
 - (SUAppcastItem *)newestItem
 {
-       return [items count] ? [items objectAtIndex:0] : nil; // the RSS class 
takes care of sorting by published date, descending.
+       return [items count] ? [items objectAtIndex:0] : nil; // we take care 
of sorting by published date, descending.
 }
 
 - (NSArray *)items
@@ -38,37 +43,52 @@
        return items;
 }
 
-- (void)_fetchAppcastFromURL:(NSURL *)url
+- (NSURLRequest *)connection:(NSURLConnection *)connection 
willSendRequest:(NSURLRequest *)request redirectResponse:(NSURLResponse 
*)redirectResponse
 {
-       NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
+       return request;
+}
+
+- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData 
*)incrementalData
+{
+       [data appendData:incrementalData];
+}
+
+- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError 
*)error
+{
+       [connection release];
        
+    if ([delegate respondsToSelector:@selector(appcastDidFailToLoad:)])
+               [delegate appcastDidFailToLoad:self];
+}
+
+- (void)connectionDidFinishLoading:(NSURLConnection *)connection
+{
+       [connection release];
+       
        NSError *error = nil;
-    NSURLRequest *request = [NSURLRequest requestWithURL:url 
cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:60.0];
-    NSURLResponse *response = nil;
-    NSData *data = [NSURLConnection sendSynchronousRequest:request 
returningResponse:&response error:&error];
     NSXMLDocument *document = nil;
+       NSArray *xmlItems = nil;
+       NSMutableArray *appcastItems = [NSMutableArray array];
+    BOOL failed = NO;
+       
+    if ([data length])
+        document = [[NSXMLDocument alloc] initWithData:data options:0 
error:&error];
     
-    if (data)
-        document = [[NSXMLDocument alloc] initWithData:data options:0 
error:&error];
-        
-       BOOL failed = NO;
+    if (document == nil) {
+        failed = YES;
+       } else {
+        xmlItems = [document nodesForXPath:@"/rss/channel/item" error:&error];
+        if (nil == xmlItems)
+            failed = YES;
+       }
        
-       if (nil == document)
-               failed = YES;
+       if (failed == NO) {
                
-       NSArray *xmlItems = [document nodesForXPath:@"/rss/channel/item" 
error:&error];
-       if (nil == xmlItems)
-               failed = YES;
-       
-       NSMutableArray *appcastItems = [NSMutableArray array];
-       
-       if (xmlItems) {
-               
                NSEnumerator *nodeEnum = [xmlItems objectEnumerator];
                NSXMLNode *node;
                NSMutableDictionary *dict = [NSMutableDictionary dictionary];
                
-               while ((node = [nodeEnum nextObject])) {
+               while (failed == NO && (node = [nodeEnum nextObject])) {
                        
                        // walk the children in reverse
                        node = [[node children] lastObject];
@@ -101,12 +121,18 @@
                                node = [node previousSibling];
                        }
                        SUAppcastItem *anItem = [[SUAppcastItem alloc] 
initWithDictionary:dict];
-                       [appcastItems addObject:anItem];
-                       [anItem release];
+            if (anItem == nil) {
+                failed = YES;
+            } else {
+                [appcastItems addObject:anItem];
+                [anItem release];
+            }
                        [dict removeAllObjects];
                }
        }
        
+       [document release];
+       
        if ([appcastItems count]) {
                NSSortDescriptor *sort = [[[NSSortDescriptor alloc] 
initWithKey:@"date" ascending:NO] autorelease];
                [appcastItems sortUsingDescriptors:[NSArray 
arrayWithObject:sort]];
@@ -114,12 +140,9 @@
        }
        
        if (failed && [delegate 
respondsToSelector:@selector(appcastDidFailToLoad:)])
-               [delegate 
performSelectorOnMainThread:@selector(appcastDidFailToLoad:) withObject:self 
waitUntilDone:NO];
+               [delegate appcastDidFailToLoad:self];
        else if (NO == failed && [delegate 
respondsToSelector:@selector(appcastDidFinishLoading:)])
-               [delegate 
performSelectorOnMainThread:@selector(appcastDidFinishLoading:) withObject:self 
waitUntilDone:NO];
-       
-       [document release];
-       [pool release];
+               [delegate appcastDidFinishLoading:self];
 }
 
 @end


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://sourceforge.net/services/buy/index.php
_______________________________________________
Skim-app-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/skim-app-commit

Reply via email to