diff --git a/Sparkle.xcodeproj/project.pbxproj b/Sparkle.xcodeproj/project.pbxproj index 5a196eb9..b321dcc2 100644 --- a/Sparkle.xcodeproj/project.pbxproj +++ b/Sparkle.xcodeproj/project.pbxproj @@ -186,6 +186,8 @@ 7275F9C11B5F1F2900B1D19E /* SUFileManager.h in Headers */ = {isa = PBXBuildFile; fileRef = 7275F9BF1B5F1F2900B1D19E /* SUFileManager.h */; }; 7275F9C21B5F1F2900B1D19E /* SUFileManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 7275F9C01B5F1F2900B1D19E /* SUFileManager.m */; }; 7275F9C31B5F1F2900B1D19E /* SUFileManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 7275F9C01B5F1F2900B1D19E /* SUFileManager.m */; }; + 72A450531C69A68900D67EEA /* SUUpdatePermissionPromptResult.h in Headers */ = {isa = PBXBuildFile; fileRef = 72A450511C69A68900D67EEA /* SUUpdatePermissionPromptResult.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 72A450541C69A68900D67EEA /* SUUpdatePermissionPromptResult.m in Sources */ = {isa = PBXBuildFile; fileRef = 72A450521C69A68900D67EEA /* SUUpdatePermissionPromptResult.m */; }; 72A4A2401BB6567D00E7820D /* SUFileManagerTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 72A4A23F1BB6567D00E7820D /* SUFileManagerTest.swift */; }; 72AC6B261B9AAC8800F62325 /* SparkleTestCodeSignApp.tar.gz in Resources */ = {isa = PBXBuildFile; fileRef = 72AC6B251B9AAC8800F62325 /* SparkleTestCodeSignApp.tar.gz */; }; 72AC6B281B9AAD6700F62325 /* SparkleTestCodeSignApp.tar in Resources */ = {isa = PBXBuildFile; fileRef = 72AC6B271B9AAD6700F62325 /* SparkleTestCodeSignApp.tar */; }; @@ -635,6 +637,8 @@ 729F10FE1C65A9B500DFCCC5 /* ConfigUITestCoverage.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = ConfigUITestCoverage.xcconfig; sourceTree = ""; }; 729F10FF1C65A9B500DFCCC5 /* ConfigUITestDebug.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = ConfigUITestDebug.xcconfig; sourceTree = ""; }; 729F11001C65A9B500DFCCC5 /* ConfigUITestRelease.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = ConfigUITestRelease.xcconfig; sourceTree = ""; }; + 72A450511C69A68900D67EEA /* SUUpdatePermissionPromptResult.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SUUpdatePermissionPromptResult.h; sourceTree = ""; }; + 72A450521C69A68900D67EEA /* SUUpdatePermissionPromptResult.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SUUpdatePermissionPromptResult.m; sourceTree = ""; }; 72A4A23F1BB6567D00E7820D /* SUFileManagerTest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SUFileManagerTest.swift; sourceTree = ""; }; 72AC6B251B9AAC8800F62325 /* SparkleTestCodeSignApp.tar.gz */ = {isa = PBXFileReference; lastKnownFileType = archive.gzip; path = SparkleTestCodeSignApp.tar.gz; sourceTree = ""; }; 72AC6B271B9AAD6700F62325 /* SparkleTestCodeSignApp.tar */ = {isa = PBXFileReference; lastKnownFileType = archive.tar; path = SparkleTestCodeSignApp.tar; sourceTree = ""; }; @@ -995,6 +999,8 @@ 6196CFE409C71ADE000DC222 /* SUStatusController.m */, 61B5FCA009C5228F00B25A18 /* SUUpdateAlert.h */, 61B5FCA109C5228F00B25A18 /* SUUpdateAlert.m */, + 72A450511C69A68900D67EEA /* SUUpdatePermissionPromptResult.h */, + 72A450521C69A68900D67EEA /* SUUpdatePermissionPromptResult.m */, 612DCBAD0D488BC60015DBEA /* SUUpdatePermissionPrompt.h */, 612DCBAE0D488BC60015DBEA /* SUUpdatePermissionPrompt.m */, 61180BC80D64138900B4E0D1 /* SUWindowController.h */, @@ -1158,6 +1164,7 @@ isa = PBXHeadersBuildPhase; buildActionMask = 2147483647; files = ( + 72A450531C69A68900D67EEA /* SUUpdatePermissionPromptResult.h in Headers */, 611142E910FB1BE5009810AA /* bspatch.h in Headers */, 6160E7E10D3B4A8800E9CD71 /* NTSynchronousTask.h in Headers */, 61299B3609CB04E000B7442F /* Sparkle.h in Headers */, @@ -1679,6 +1686,7 @@ 61299A6009CA6EB100B7442F /* SUConstants.m in Sources */, 6102FE4B0E07803800F85D09 /* SUDiskImageUnarchiver.m in Sources */, 61299A3009CA2DAB00B7442F /* SUDSAVerifier.m in Sources */, + 72A450541C69A68900D67EEA /* SUUpdatePermissionPromptResult.m in Sources */, 7275F9C21B5F1F2900B1D19E /* SUFileManager.m in Sources */, 767B61AD1972D488004E0C3C /* SUGuidedPackageInstaller.m in Sources */, 61EF67560E25B58D00F754E0 /* SUHost.m in Sources */, diff --git a/Sparkle/SUUpdatePermissionPrompt.h b/Sparkle/SUUpdatePermissionPrompt.h index 2320df88..0632d927 100644 --- a/Sparkle/SUUpdatePermissionPrompt.h +++ b/Sparkle/SUUpdatePermissionPrompt.h @@ -11,23 +11,14 @@ #import "SUWindowController.h" -typedef NS_ENUM(NSInteger, SUPermissionPromptResult) { - SUAutomaticallyCheck, - SUDoNotAutomaticallyCheck -}; +@class SUHost, SUUpdatePermissionPromptResult; -@protocol SUUpdatePermissionPromptDelegate; - -@class SUHost; @interface SUUpdatePermissionPrompt : SUWindowController -+ (void)promptWithHost:(SUHost *)aHost systemProfile:(NSArray *)profile delegate:(id)d; ++ (void)promptWithHost:(SUHost *)host systemProfile:(NSArray *)systemProfile reply:(void (^)(SUUpdatePermissionPromptResult *))reply; + - (IBAction)toggleMoreInfo:(id)sender; - (IBAction)finishPrompt:(id)sender; @end -@protocol SUUpdatePermissionPromptDelegate -- (void)updatePermissionPromptFinishedWithResult:(SUPermissionPromptResult)result; -@end - #endif diff --git a/Sparkle/SUUpdatePermissionPrompt.m b/Sparkle/SUUpdatePermissionPrompt.m index 4a338dba..9ebd6697 100644 --- a/Sparkle/SUUpdatePermissionPrompt.m +++ b/Sparkle/SUUpdatePermissionPrompt.m @@ -7,6 +7,7 @@ // #import "SUUpdatePermissionPrompt.h" +#import "SUUpdatePermissionPromptResult.h" #import "SUHost.h" #import "SUConstants.h" @@ -18,57 +19,53 @@ @property (strong) SUHost *host; @property (strong) NSArray *systemProfileInformationArray; -@property (weak) id delegate; @property (weak) IBOutlet NSTextField *descriptionTextField; @property (weak) IBOutlet NSView *moreInfoView; @property (weak) IBOutlet NSButton *moreInfoButton; @property (weak) IBOutlet NSTableView *profileTableView; +@property (nonatomic, readonly) void (^reply)(SUUpdatePermissionPromptResult *); + @end @implementation SUUpdatePermissionPrompt +@synthesize reply = _reply; @synthesize isShowingMoreInfo = _isShowingMoreInfo; @synthesize shouldSendProfile = _shouldSendProfile; @synthesize host; @synthesize systemProfileInformationArray; -@synthesize delegate; @synthesize descriptionTextField; @synthesize moreInfoView; @synthesize moreInfoButton; @synthesize profileTableView; -- (BOOL)shouldAskAboutProfile -{ - return [[self.host objectForInfoDictionaryKey:SUEnableSystemProfilingKey] boolValue]; -} - -- (instancetype)initWithHost:(SUHost *)aHost systemProfile:(NSArray *)profile delegate:(id)d +- (instancetype)initPromptWithHost:(SUHost *)theHost systemProfile:(NSArray *)systemProfile reply:(void (^)(SUUpdatePermissionPromptResult *))reply { self = [super initWithWindowNibName:@"SUUpdatePermissionPrompt"]; - if (self) - { - host = aHost; - delegate = d; + if (self) + { + _reply = reply; + self.host = theHost; self.isShowingMoreInfo = NO; self.shouldSendProfile = [self shouldAskAboutProfile]; - systemProfileInformationArray = profile; + self.systemProfileInformationArray = systemProfile; [self setShouldCascadeWindows:NO]; } return self; } -+ (void)promptWithHost:(SUHost *)aHost systemProfile:(NSArray *)profile delegate:(id)d ++ (void)promptWithHost:(SUHost *)host systemProfile:(NSArray *)systemProfile reply:(void (^)(SUUpdatePermissionPromptResult *))reply { // If this is a background application we need to focus it in order to bring the prompt // to the user's attention. Otherwise the prompt would be hidden behind other applications and // the user would not know why the application was paused. - if ([aHost isBackgroundApplication]) { + if ([host isBackgroundApplication]) { [[NSApplication sharedApplication] activateIgnoringOtherApps:YES]; } - + if (![NSApp modalWindow]) { // do not prompt if there is is another modal window on screen - SUUpdatePermissionPrompt *prompt = [[[self class] alloc] initWithHost:aHost systemProfile:profile delegate:d]; + SUUpdatePermissionPrompt *prompt = [[[self class] alloc] initPromptWithHost:host systemProfile:systemProfile reply:reply]; NSWindow *window = [prompt window]; if (window) { [NSApp runModalForWindow:window]; @@ -76,6 +73,11 @@ } } +- (BOOL)shouldAskAboutProfile +{ + return [[self.host objectForInfoDictionaryKey:SUEnableSystemProfilingKey] boolValue]; +} + - (NSString *)description { return [NSString stringWithFormat:@"%@ <%@>", [self class], [self.host bundlePath]]; } - (void)windowDidLoad @@ -149,11 +151,8 @@ - (IBAction)finishPrompt:(id)sender { - if (![self.delegate respondsToSelector:@selector(updatePermissionPromptFinishedWithResult:)]) { - [NSException raise:@"SUInvalidDelegate" format:@"SUUpdatePermissionPrompt's delegate (%@) doesn't respond to updatePermissionPromptFinishedWithResult:!", self.delegate]; - } - [self.host setBool:self.shouldSendProfile forUserDefaultsKey:SUSendProfileInfoKey]; - [self.delegate updatePermissionPromptFinishedWithResult:([sender tag] == 1 ? SUAutomaticallyCheck : SUDoNotAutomaticallyCheck)]; + self.reply([SUUpdatePermissionPromptResult updatePermissionPromptResultWithChoice:([sender tag] == 1 ? SUAutomaticallyCheck : SUDoNotAutomaticallyCheck) shouldSendProfile:self.shouldSendProfile]); + [[self window] close]; [NSApp stopModal]; } diff --git a/Sparkle/SUUpdatePermissionPromptResult.h b/Sparkle/SUUpdatePermissionPromptResult.h new file mode 100644 index 00000000..2a072590 --- /dev/null +++ b/Sparkle/SUUpdatePermissionPromptResult.h @@ -0,0 +1,23 @@ +// +// SUUpdatePermissionPromptResult.h +// Sparkle +// +// Created by Mayur Pawashe on 2/8/16. +// Copyright © 2016 Sparkle Project. All rights reserved. +// + +#import + +typedef NS_ENUM(NSInteger, SUCheckUpdatesChoice) { + SUAutomaticallyCheck, + SUDoNotAutomaticallyCheck +}; + +@interface SUUpdatePermissionPromptResult : NSObject + ++ (instancetype)updatePermissionPromptResultWithChoice:(SUCheckUpdatesChoice)choice shouldSendProfile:(BOOL)shouldSendProfile; + +@property (nonatomic, readonly) SUCheckUpdatesChoice choice; +@property (nonatomic, readonly) BOOL shouldSendProfile; + +@end diff --git a/Sparkle/SUUpdatePermissionPromptResult.m b/Sparkle/SUUpdatePermissionPromptResult.m new file mode 100644 index 00000000..57b122ec --- /dev/null +++ b/Sparkle/SUUpdatePermissionPromptResult.m @@ -0,0 +1,31 @@ +// +// SUUpdatePermissionPromptResult.m +// Sparkle +// +// Created by Mayur Pawashe on 2/8/16. +// Copyright © 2016 Sparkle Project. All rights reserved. +// + +#import "SUUpdatePermissionPromptResult.h" + +@implementation SUUpdatePermissionPromptResult + +@synthesize choice = _choice; +@synthesize shouldSendProfile = _shouldSendProfile; + +- (instancetype)initWithCheckUpdatesChoice:(SUCheckUpdatesChoice)choice shouldSendProfile:(BOOL)shouldSendProfile +{ + self = [super init]; + if (self != nil) { + _choice = choice; + _shouldSendProfile = shouldSendProfile; + } + return self; +} + ++ (instancetype)updatePermissionPromptResultWithChoice:(SUCheckUpdatesChoice)choice shouldSendProfile:(BOOL)shouldSendProfile +{ + return [[self alloc] initWithCheckUpdatesChoice:choice shouldSendProfile:shouldSendProfile]; +} + +@end diff --git a/Sparkle/SUUpdater.h b/Sparkle/SUUpdater.h index 86024858..cb53bdb4 100644 --- a/Sparkle/SUUpdater.h +++ b/Sparkle/SUUpdater.h @@ -14,7 +14,7 @@ #import "SUVersionComparisonProtocol.h" #import "SUVersionDisplayProtocol.h" -@class SUAppcastItem, SUAppcast; +@class SUAppcastItem, SUAppcast, SUHost, SUUpdatePermissionPromptResult; @protocol SUUpdaterDelegate; @@ -361,6 +361,8 @@ SU_EXPORT extern NSString *const SUUpdaterAppcastNotificationKey; */ - (void)updater:(SUUpdater *)updater didAbortWithError:(NSError *)error; +- (BOOL)handlePermissionForUpdater:(SUUpdater *)updater host:(SUHost *)host systemProfile:(NSArray *)systemProfile reply:(void (^)(SUUpdatePermissionPromptResult *))reply; + @end #endif diff --git a/Sparkle/SUUpdater.m b/Sparkle/SUUpdater.m index 0a00d6cd..d3f708a8 100644 --- a/Sparkle/SUUpdater.m +++ b/Sparkle/SUUpdater.m @@ -10,6 +10,7 @@ #import "SUHost.h" #import "SUUpdatePermissionPrompt.h" +#import "SUUpdatePermissionPromptResult.h" #import "SUAutomaticUpdateDriver.h" #import "SUProbingUpdateDriver.h" @@ -27,7 +28,7 @@ NSString *const SUUpdaterWillRestartNotification = @"SUUpdaterWillRestartNotific NSString *const SUUpdaterAppcastItemNotificationKey = @"SUUpdaterAppcastItemNotificationKey"; NSString *const SUUpdaterAppcastNotificationKey = @"SUUpdaterAppCastNotificationKey"; -@interface SUUpdater () +@interface SUUpdater () @property (strong) NSTimer *checkTimer; @property (strong) NSBundle *sparkleBundle; @@ -186,7 +187,20 @@ static NSString *const SUUpdaterDefaultsObservationContext = @"SUUpdaterDefaults if ([self.delegate respondsToSelector:@selector(feedParametersForUpdater:sendingSystemProfile:)]) { profileInfo = [profileInfo arrayByAddingObjectsFromArray:[self.delegate feedParametersForUpdater:self sendingSystemProfile:YES]]; } - [SUUpdatePermissionPrompt promptWithHost:self.host systemProfile:profileInfo delegate:self]; + + BOOL handledPermissionPrompt = NO; + if ([self.delegate respondsToSelector:@selector(handlePermissionForUpdater:host:systemProfile:reply:)]) { + handledPermissionPrompt = [self.delegate handlePermissionForUpdater:self host:self.host systemProfile:profileInfo reply:^(SUUpdatePermissionPromptResult *result) { + [self updatePermissionPromptFinishedWithResult:result]; + }]; + } + + if (!handledPermissionPrompt) { + [SUUpdatePermissionPrompt promptWithHost:self.host systemProfile:profileInfo reply:^(SUUpdatePermissionPromptResult *result) { + [self updatePermissionPromptFinishedWithResult:result]; + }]; + } + // We start the update checks and register as observer for changes after the prompt finishes } else { // We check if the user's said they want updates, or they haven't said anything, and the default is set to checking. @@ -194,9 +208,10 @@ static NSString *const SUUpdaterDefaultsObservationContext = @"SUUpdaterDefaults } } -- (void)updatePermissionPromptFinishedWithResult:(SUPermissionPromptResult)result +- (void)updatePermissionPromptFinishedWithResult:(SUUpdatePermissionPromptResult *)result { - [self setAutomaticallyChecksForUpdates:(result == SUAutomaticallyCheck)]; + [self.host setBool:result.shouldSendProfile forUserDefaultsKey:SUSendProfileInfoKey]; + [self setAutomaticallyChecksForUpdates:(result.choice == SUAutomaticallyCheck)]; // Schedule checks, but make sure we ignore the delayed call from KVO [self resetUpdateCycle]; } @@ -335,7 +350,7 @@ static NSString *const SUUpdaterDefaultsObservationContext = @"SUUpdaterDefaults [self.driver abortUpdate]; } - SUUIBasedUpdateDriver *theUpdateDriver = [[SUUserInitiatedUpdateDriver alloc] initWithUpdater:self]; + SUUserInitiatedUpdateDriver *theUpdateDriver = [[SUUserInitiatedUpdateDriver alloc] initWithUpdater:self]; theUpdateDriver.automaticallyInstallUpdates = YES; [self checkForUpdatesWithDriver:theUpdateDriver]; }