mirror of
https://github.com/sparkle-project/Sparkle
synced 2026-11-25 04:47:55 +00:00
Force feedURL/setFeedURL to be called on the main thread.
This is better than relying solely on documentation.
This commit is contained in:
1 parent
8c805970fb
commit
444809da92
4 files changed
+97
-3
No files matched your search
+6
-1
@@ -35,7 +35,12 @@
|
||||
|
||||
@property NSTimeInterval updateCheckInterval;
|
||||
|
||||
@property (copy) NSURL *feedURL; // *** MUST BE CALLED ON MAIN THREAD ***
|
||||
/*!
|
||||
* The URL of the appcast used to download update information.
|
||||
*
|
||||
* This property must be called on the main thread.
|
||||
*/
|
||||
@property (copy) NSURL *feedURL;
|
||||
|
||||
@property (nonatomic, copy) NSString *userAgentString;
|
||||
|
||||
|
||||
+8
-2
@@ -441,17 +441,23 @@ static NSString * const SUUpdaterDefaultsObservationContext = @"SUUpdaterDefault
|
||||
|
||||
- (void)setFeedURL:(NSURL *)feedURL
|
||||
{
|
||||
if (![NSThread isMainThread])
|
||||
[NSException raise:@"SUThreadException" format:@"This method must be called on the main thread"];
|
||||
|
||||
[host setObject:[feedURL absoluteString] forUserDefaultsKey:SUFeedURLKey];
|
||||
}
|
||||
|
||||
- (NSURL *)feedURL // *** MUST BE CALLED ON MAIN THREAD ***
|
||||
- (NSURL *)feedURL
|
||||
{
|
||||
if (![NSThread isMainThread])
|
||||
[NSException raise:@"SUThreadException" format:@"This method must be called on the main thread"];
|
||||
|
||||
// A value in the user defaults overrides one in the Info.plist (so preferences panels can be created wherein users choose between beta / release feeds).
|
||||
NSString *appcastString = [host objectForKey:SUFeedURLKey];
|
||||
if( [delegate respondsToSelector: @selector(feedURLStringForUpdater:)] )
|
||||
appcastString = [delegate feedURLStringForUpdater: self];
|
||||
if (!appcastString) // Can't find an appcast string!
|
||||
[NSException raise:@"SUNoFeedURL" format:@"You must specify the URL of the appcast as the SUFeedURL key in either the Info.plist or the user defaults!"];
|
||||
[NSException raise:@"SUNoFeedURL" format:@"You must specify the URL of the appcast as the %@ key in either the Info.plist or the user defaults!", SUFeedURLKey];
|
||||
NSCharacterSet* quoteSet = [NSCharacterSet characterSetWithCharactersInString: @"\"\'"]; // Some feed publishers add quotes; strip 'em.
|
||||
NSString* castUrlStr = [appcastString stringByTrimmingCharactersInSet:quoteSet];
|
||||
if( !castUrlStr || [castUrlStr length] == 0 )
|
||||
|
||||
@@ -31,6 +31,7 @@
|
||||
14950071195FCE3D00BC5B5B /* AppKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 0867D6A5FE840307C02AAC07 /* AppKit.framework */; };
|
||||
14950072195FCE4B00BC5B5B /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 0867D69BFE84028FC02AAC07 /* Foundation.framework */; };
|
||||
14950073195FCE4E00BC5B5B /* AppKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 0867D6A5FE840307C02AAC07 /* AppKit.framework */; };
|
||||
14950075195FDF5900BC5B5B /* SUUpdaterTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 14950074195FDF5900BC5B5B /* SUUpdaterTest.m */; };
|
||||
3772FEA913DE0B6B00F79537 /* SUVersionDisplayProtocol.h in Headers */ = {isa = PBXBuildFile; fileRef = 3772FEA813DE0B6B00F79537 /* SUVersionDisplayProtocol.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
||||
550347011370023A00AE7681 /* Sparkle.icns in Resources */ = {isa = PBXBuildFile; fileRef = 550347001370023A00AE7681 /* Sparkle.icns */; };
|
||||
55C14BD4136EEFCE00649790 /* Autoupdate.m in Sources */ = {isa = PBXBuildFile; fileRef = 55C14BD3136EEFCE00649790 /* Autoupdate.m */; };
|
||||
@@ -245,6 +246,7 @@
|
||||
0263187714FEBB42005EBF43 /* uk */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = uk; path = uk.lproj/SUUpdatePermissionPrompt.xib; sourceTree = "<group>"; };
|
||||
0867D69BFE84028FC02AAC07 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; };
|
||||
0867D6A5FE840307C02AAC07 /* AppKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AppKit.framework; path = System/Library/Frameworks/AppKit.framework; sourceTree = SDKROOT; };
|
||||
14950074195FDF5900BC5B5B /* SUUpdaterTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = SUUpdaterTest.m; path = Tests/SUUpdaterTest.m; sourceTree = "<group>"; };
|
||||
3772FEA813DE0B6B00F79537 /* SUVersionDisplayProtocol.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SUVersionDisplayProtocol.h; sourceTree = "<group>"; };
|
||||
4607BEA21948443800EF8DA4 /* nb */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = nb; path = nb.lproj/Sparkle.strings; sourceTree = "<group>"; };
|
||||
4607BEA31948443800EF8DA4 /* nb */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = nb; path = nb.lproj/SUAutomaticUpdateAlert.xib; sourceTree = "<group>"; };
|
||||
@@ -653,6 +655,7 @@
|
||||
children = (
|
||||
612279DA0DB5470200AB99EA /* Sparkle Unit Tests-Info.plist */,
|
||||
61227A150DB548B800AB99EA /* SUVersionComparisonTest.m */,
|
||||
14950074195FDF5900BC5B5B /* SUUpdaterTest.m */,
|
||||
);
|
||||
name = Tests;
|
||||
sourceTree = "<group>";
|
||||
@@ -1183,6 +1186,7 @@
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
61227A160DB548B800AB99EA /* SUVersionComparisonTest.m in Sources */,
|
||||
14950075195FDF5900BC5B5B /* SUUpdaterTest.m in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
|
||||
@@ -0,0 +1,79 @@
|
||||
//
|
||||
// SUUpdaterTest.m
|
||||
// Sparkle
|
||||
//
|
||||
// Created by Jake Petroules on 2014-06-29.
|
||||
// Copyright (c) 2014 Sparkle Project. All rights reserved.
|
||||
//
|
||||
|
||||
#import <XCTest/XCTest.h>
|
||||
#import "SUConstants.h"
|
||||
#import "SUUpdater.h"
|
||||
|
||||
@interface SUUpdaterTest : XCTestCase <SUUpdaterDelegate>
|
||||
|
||||
@end
|
||||
|
||||
@implementation SUUpdaterTest
|
||||
{
|
||||
NSOperationQueue *queue;
|
||||
SUUpdater *updater;
|
||||
}
|
||||
|
||||
- (void)setUp
|
||||
{
|
||||
[super setUp];
|
||||
queue = [[NSOperationQueue alloc] init];
|
||||
updater = [[SUUpdater alloc] init];
|
||||
updater.delegate = self;
|
||||
}
|
||||
|
||||
- (void)tearDown
|
||||
{
|
||||
[updater release];
|
||||
updater = nil;
|
||||
[queue release];
|
||||
queue = nil;
|
||||
[super tearDown];
|
||||
}
|
||||
|
||||
- (NSString *)feedURLStringForUpdater:(SUUpdater *) __unused updater
|
||||
{
|
||||
return @"";
|
||||
}
|
||||
|
||||
- (void)testFeedURL
|
||||
{
|
||||
[updater feedURL]; // this WON'T throw
|
||||
|
||||
[queue addOperationWithBlock:^{
|
||||
XCTAssertTrue(![NSThread isMainThread]);
|
||||
@try {
|
||||
[updater feedURL];
|
||||
XCTFail(@"feedURL did not throw an exception when called on a secondary thread");
|
||||
}
|
||||
@catch (NSException *exception) {
|
||||
NSLog(@"%@", exception);
|
||||
}
|
||||
}];
|
||||
[queue waitUntilAllOperationsAreFinished];
|
||||
}
|
||||
|
||||
- (void)setTestFeedURL
|
||||
{
|
||||
[updater setFeedURL:[NSURL URLWithString:@""]]; // this WON'T throw
|
||||
|
||||
[queue addOperationWithBlock:^{
|
||||
XCTAssertTrue(![NSThread isMainThread]);
|
||||
@try {
|
||||
[updater setFeedURL:[NSURL URLWithString:@""]];
|
||||
XCTFail(@"setFeedURL: did not throw an exception when called on a secondary thread");
|
||||
}
|
||||
@catch (NSException *exception) {
|
||||
NSLog(@"%@", exception);
|
||||
}
|
||||
}];
|
||||
[queue waitUntilAllOperationsAreFinished];
|
||||
}
|
||||
|
||||
@end
|
||||
Reference in new issue
Block a user