Add delegate outlets to SUStandardUpdaterController

This adds delegate outlets to the updater and to the user driver, so a
developer can hook either of them up. Note we now initialize the updater and
user driver after being awoken from the nib.

We also took this chance to make the delegates to the updater and user driver read only.
This means that the delegates have to be available on initialization, which is good because
changing delegates or setting delegates too late (and missing messages) is bad.
This commit is contained in:
Zorg committed 2016-03-06 23:38:17 -05:00
1 parent 1e92d403ec
commit 00368011c8
4 files changed
+62 -15

No files matched your search

+30 -9
View File
@@ -11,14 +11,16 @@
NS_ASSUME_NONNULL_BEGIN
@class SUUpdater;
@protocol SUStandardUserDriver;
@protocol SUUserDriver, SUStandardUserDriver, SUUpdaterDelegate, SUStandardUserDriverDelegate;
/*!
A controller class that instantiates a SUUpdater and allows binding UI to it.
This controller's updater targets the application's main bundle, and uses Sparkle's standard user interface.
Thus it is only suitable under these circumstances. Typically, this class is used by sticking it as a custom NSObject subclass in an Interface Builder nib (probably in MainMenu).
The controller creates an SUUpdater instance and allows hooking up the check for updates action and menu item validation.
This class is meant to be instantiated in a nib. When doing so, the controller's updater target's the application's main bundle,
and uses Sparkle's standard user interface. Typically, this class is used by sticking it as a custom NSObject subclass in an Interface Builder nib (probably in MainMenu).
The controller creates an SUUpdater instance and allows hooking up the check for updates action and menu item validation. It also allows hooking
up the updater's and user driver's delegates.
This controller class may not be valuable to you if:
* You want to control or defer the instantiation of an SUUpdater, or don't want to be tied into a nib's instantiation, or don't want to use a nib
@@ -30,20 +32,39 @@ NS_ASSUME_NONNULL_BEGIN
@interface SUStandardUpdaterController : NSObject
/*!
Initializes a new updater controller instance. Typically this class is instantiated in a nib, thus this
method is not usually called directly by the developer.
Initializes a new updater controller instance using a provided updater and user driver.
Typically this class is instantiated in a nib, thus this method is not usually used.
*/
- (instancetype)init;
- (instancetype)initWithUpdater:(SUUpdater *)updater userDriver:(id<SUUserDriver, SUStandardUserDriver>)userDriver;
/*!
Interface builder outlet for the updater's delegate.
This property should only be set using Interface Builder by creating a connection using the outlet
*/
@property (nonatomic, weak, nullable) IBOutlet id<SUUpdaterDelegate> updaterDelegate;
/*!
Interface builder outlet for the user driver's delegate.
This property should only be set using Interface Builder by creating a connection using the outlet
*/
@property (nonatomic, weak, nullable) IBOutlet id<SUStandardUserDriverDelegate> userDriverDelegate;
/*!
Accessible property for the updater. Some properties on the updater can be binded via KVO
This is nil before being awoken from a nib
*/
@property (nonatomic, readonly) SUUpdater *updater;
@property (nonatomic, readonly, nullable) SUUpdater *updater;
/*!
Accessible property for the updater's user driver.
This is nil before being awoken from a nib
*/
@property (nonatomic, readonly) id <SUStandardUserDriver> userDriver;
@property (nonatomic, readonly, nullable) id <SUStandardUserDriver> userDriver;
/*!
Explicitly checks for updates and displays a progress dialog while doing so.
+30 -4
View File
@@ -20,6 +20,7 @@ static NSString *const SUUpdaterDefaultsObservationContext = @"SUUpdaterDefaults
@property (nonatomic) SUUpdater *updater;
@property (nonatomic) id <SUStandardUserDriver> userDriver;
@property (nonatomic) BOOL awokeFromNib;
@end
@@ -27,20 +28,45 @@ static NSString *const SUUpdaterDefaultsObservationContext = @"SUUpdaterDefaults
@synthesize updater = _updater;
@synthesize userDriver = _userDriver;
@synthesize updaterDelegate = _updaterDelegate;
@synthesize userDriverDelegate = _userDriverDelegate;
@synthesize awokeFromNib = _awokeFromNib;
- (instancetype)initWithUpdater:(SUUpdater *)updater userDriver:(id<SUUserDriver, SUStandardUserDriver>)userDriver
{
self = [self init]; // note: call our own init here rather than super's
if (self != nil) {
self.updater = updater;
self.userDriver = userDriver;
}
return self;
}
// Invoked from being instantiated in a nib
- (instancetype)init
{
self = [super init];
if (self != nil) {
// Register as an observer here to match unregistering in -dealloc
[self registerAsObserver];
}
return self;
}
- (void)awakeFromNib
{
// awakeFromNib might be called more than once; guard against that
// We have to use awakeFromNib otherwise the delegate outlets may not be connected yet,
// and we aren't a proper window or view controller or anything like that
if (!self.awokeFromNib) {
self.awokeFromNib = YES;
NSBundle *hostBundle = [NSBundle mainBundle];
id <SUUserDriver, SUStandardUserDriver> userDriver = [[SUStandardUserDriver alloc] initWithHostBundle:hostBundle delegate:nil];
_updater = [[SUUpdater alloc] initWithHostBundle:hostBundle userDriver:userDriver delegate:nil];
_userDriver = userDriver;
id <SUUserDriver, SUStandardUserDriver> userDriver = [[SUStandardUserDriver alloc] initWithHostBundle:hostBundle delegate:self.userDriverDelegate];
self.updater = [[SUUpdater alloc] initWithHostBundle:hostBundle userDriver:userDriver delegate:self.updaterDelegate];
self.userDriver = userDriver;
}
return self;
}
- (void)dealloc
+1 -1
View File
@@ -20,7 +20,7 @@
/*!
Readable and writable property for this user driver's delegate
*/
@property (nonatomic, weak, nullable) id <SUStandardUserDriverDelegate> delegate;
@property (nonatomic, weak, nullable, readonly) id <SUStandardUserDriverDelegate> delegate;
/*!
Indicates whether or not an update is in progress as far as the user's perspective is concerned
+1 -1
View File
@@ -45,7 +45,7 @@ SU_EXPORT @interface SUUpdater : NSObject
*/
- (instancetype)initWithHostBundle:(NSBundle *)hostBundle userDriver:(id <SUUserDriver>)userDriver delegate:(id <SUUpdaterDelegate>)delegate;
@property (weak) id<SUUpdaterDelegate> delegate;
@property (weak, readonly) id<SUUpdaterDelegate> delegate;
@property (nonatomic, readonly) id<SUUserDriver> userDriver;
@property (readonly, strong) NSBundle *hostBundle;