mirror of
https://github.com/sparkle-project/Sparkle
synced 2026-11-26 04:57:54 +00:00
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:
1 parent
dec088b9ad
commit
aee0b6f7d8
2 files changed
+34
-10
No files matched your search
Vendored
+6
-4
@@ -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;
|
||||
|
||||
Vendored
+28
-6
@@ -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];
|
||||
|
||||
Reference in new issue
Block a user