Allow user driver's delegate to handle initiating update checks

In a XPC environment, a delegate may handle update checks by sending a message
to the XPC process that tells it to reset the sparkle updater's check cycle.
If the user driver delegate can do this, the XPC process will not need to wait
for a reply, allowing the system to kill the XPC process when it becomes idle.
This commit is contained in:
Zorg committed 2016-02-27 17:54:19 -05:00
1 parent dec088b9ad
commit aee0b6f7d8
2 files changed
+34 -10

No files matched your search

+6 -4
View File
@@ -11,21 +11,23 @@
@class SUHost;
@protocol SUModalAlertDelegate <NSObject>
@protocol SUSparkleUserUpdaterDriverDelegate <NSObject>
@optional
- (void)userUpdaterDriverWillShowModalAlert:(id <SUUserUpdaterDriver>)userUpdaterDriver;
- (BOOL)responsibleForInitiatingUpdateCheckForUserDriver:(id <SUUserUpdaterDriver>)userUpdaterDriver;
- (void)initiateUpdateCheckForUserDriver:(id <SUUserUpdaterDriver>)userUpdaterDriver;
- (void)userUpdaterDriverWillShowModalAlert:(id <SUUserUpdaterDriver>)userUpdaterDriver;
- (void)userUpdaterDriverDidShowModalAlert:(id <SUUserUpdaterDriver>)userUpdaterDriver;
@end
@interface SUSparkleUserUpdaterDriver : NSObject <SUUserUpdaterDriver>
- (instancetype)initWithHost:(SUHost *)host handlesTermination:(BOOL)handlesTermination delegate:(id <SUModalAlertDelegate>)delegate;
- (instancetype)initWithHost:(SUHost *)host handlesTermination:(BOOL)handlesTermination delegate:(id <SUSparkleUserUpdaterDriverDelegate>)delegate;
@property (nonatomic, readonly, weak) id <SUModalAlertDelegate> delegate;
@property (nonatomic, readonly, weak) id <SUSparkleUserUpdaterDriverDelegate> delegate;
@property (nonatomic, readonly, getter = isInstallingUpdateOnTermination) BOOL installingUpdateOnTermination;
- (void)sendTerminationSignalWithCompletion:(void (^)(void))finishTermination;
+28 -6
View File
@@ -74,7 +74,7 @@
#pragma mark Birth
- (instancetype)initWithHost:(SUHost *)host handlesTermination:(BOOL)handlesTermination delegate:(id<SUModalAlertDelegate>)delegate
- (instancetype)initWithHost:(SUHost *)host handlesTermination:(BOOL)handlesTermination delegate:(id<SUSparkleUserUpdaterDriverDelegate>)delegate
{
self = [super init];
if (self != nil) {
@@ -87,18 +87,40 @@
#pragma mark Check Updates Timer
- (BOOL)isDelegateResponsibleForUpdateChecking
{
BOOL result = NO;
if ([self.delegate respondsToSelector:@selector(responsibleForInitiatingUpdateCheckForUserDriver:)]) {
result = [self.delegate responsibleForInitiatingUpdateCheckForUserDriver:self];
}
return result;
}
- (void)checkForUpdates:(NSTimer *)__unused timer
{
if (self.checkForUpdatesReply != nil) {
self.checkForUpdatesReply(SUCheckForUpdateNow);
self.checkForUpdatesReply = nil;
if ([self isDelegateResponsibleForUpdateChecking]) {
if ([self.delegate respondsToSelector:@selector(initiateUpdateCheckForUserDriver:)]) {
[self.delegate initiateUpdateCheckForUserDriver:self];
} else {
NSLog(@"Error: Delegate %@ for user driver %@ must implement initiateUpdateCheckForUserDriver: because it returned YES from responsibleForInitiatingUpdateCheckForUserDriver:", self.delegate, self);
}
} else {
if (self.checkForUpdatesReply != nil) {
self.checkForUpdatesReply(SUCheckForUpdateNow);
self.checkForUpdatesReply = nil;
}
}
}
- (void)startUpdateCheckTimerWithNextTimeInterval:(NSTimeInterval)timeInterval reply:(void (^)(SUUpdateCheckTimerStatus))reply
{
dispatch_async(dispatch_get_main_queue(), ^{
self.checkForUpdatesReply = reply;
if ([self isDelegateResponsibleForUpdateChecking]) {
reply(SUCheckForUpdateWillOccurLater);
} else {
self.checkForUpdatesReply = reply;
}
self.checkUpdateTimer = [NSTimer scheduledTimerWithTimeInterval:timeInterval target:self selector:@selector(checkForUpdates:) userInfo:nil repeats:NO];
});
}
@@ -308,7 +330,7 @@
- (void)showAlert:(NSAlert *)alert
{
dispatch_async(dispatch_get_main_queue(), ^{
id <SUModalAlertDelegate> delegate = self.delegate;
id <SUSparkleUserUpdaterDriverDelegate> delegate = self.delegate;
if ([delegate respondsToSelector:@selector(userUpdaterDriverWillShowModalAlert:)]) {
[delegate userUpdaterDriverWillShowModalAlert:self];