diff --git a/Sparkle.xcodeproj/project.pbxproj b/Sparkle.xcodeproj/project.pbxproj index 88fee4fb..abffc068 100644 --- a/Sparkle.xcodeproj/project.pbxproj +++ b/Sparkle.xcodeproj/project.pbxproj @@ -269,8 +269,8 @@ 7293A1B01CEE9B9800B957A7 /* SPUURLRequest.m in Sources */ = {isa = PBXBuildFile; fileRef = 7293A1AD1CEE933800B957A7 /* SPUURLRequest.m */; }; 7293A1B11CEE9B9F00B957A7 /* SPUURLRequest.m in Sources */ = {isa = PBXBuildFile; fileRef = 7293A1AD1CEE933800B957A7 /* SPUURLRequest.m */; }; 72A1C2631CD6849C004CD282 /* SPUUpdatePermissionPrompt.h in Headers */ = {isa = PBXBuildFile; fileRef = 612DCBAD0D488BC60015DBEA /* SPUUpdatePermissionPrompt.h */; }; - 72A450531C69A68900D67EEA /* SPUUpdatePermission.h in Headers */ = {isa = PBXBuildFile; fileRef = 72A450511C69A68900D67EEA /* SPUUpdatePermission.h */; settings = {ATTRIBUTES = (Public, ); }; }; - 72A450541C69A68900D67EEA /* SPUUpdatePermission.m in Sources */ = {isa = PBXBuildFile; fileRef = 72A450521C69A68900D67EEA /* SPUUpdatePermission.m */; }; + 72A450531C69A68900D67EEA /* SPUUpdatePermissionResponse.h in Headers */ = {isa = PBXBuildFile; fileRef = 72A450511C69A68900D67EEA /* SPUUpdatePermissionResponse.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 72A450541C69A68900D67EEA /* SPUUpdatePermissionResponse.m in Sources */ = {isa = PBXBuildFile; fileRef = 72A450521C69A68900D67EEA /* SPUUpdatePermissionResponse.m */; }; 72A4A2401BB6567D00E7820D /* SUFileManagerTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 72A4A23F1BB6567D00E7820D /* SUFileManagerTest.swift */; }; 72A6F98A1C94E2D6005F404C /* SUUpdaterDelegate.h in Headers */ = {isa = PBXBuildFile; fileRef = 72A6F9891C94E2D6005F404C /* SUUpdaterDelegate.h */; settings = {ATTRIBUTES = (Public, ); }; }; 72AC6B261B9AAC8800F62325 /* SparkleTestCodeSignApp.tar.gz in Resources */ = {isa = PBXBuildFile; fileRef = 72AC6B251B9AAC8800F62325 /* SparkleTestCodeSignApp.tar.gz */; }; @@ -305,6 +305,8 @@ 72D954B31CBB42DA006F28BD /* Sparkle.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 8DC2EF5B0486A6940098B216 /* Sparkle.framework */; }; 72D954B51CBB447A006F28BD /* Sparkle.framework in Copy Sparkle */ = {isa = PBXBuildFile; fileRef = 8DC2EF5B0486A6940098B216 /* Sparkle.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; 72D954B81CBB467F006F28BD /* SPUCommandLineUserDriver.m in Sources */ = {isa = PBXBuildFile; fileRef = 72D954B71CBB467F006F28BD /* SPUCommandLineUserDriver.m */; }; + 72DBA37D1D60CC34002594A8 /* SPUUpdatePermissionRequest.h in Headers */ = {isa = PBXBuildFile; fileRef = 72DBA37B1D60CC34002594A8 /* SPUUpdatePermissionRequest.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 72DBA37E1D60CC34002594A8 /* SPUUpdatePermissionRequest.m in Sources */ = {isa = PBXBuildFile; fileRef = 72DBA37C1D60CC34002594A8 /* SPUUpdatePermissionRequest.m */; }; 72E45CF31B640CDD005C701A /* SUTestApplicationDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 72E45CF21B640CDD005C701A /* SUTestApplicationDelegate.m */; }; 72E45CF71B640DAE005C701A /* SUUpdateSettingsWindowController.m in Sources */ = {isa = PBXBuildFile; fileRef = 72E45CF51B640DAE005C701A /* SUUpdateSettingsWindowController.m */; }; 72E45CF81B640DAE005C701A /* SUUpdateSettingsWindowController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 72E45CF61B640DAE005C701A /* SUUpdateSettingsWindowController.xib */; }; @@ -974,8 +976,8 @@ 729BB3D21D503834007C4276 /* org.sparkle-project.TemporaryDownloader.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.xml; name = "org.sparkle-project.TemporaryDownloader.entitlements"; path = "TemporaryDownloader/org.sparkle-project.TemporaryDownloader.entitlements"; sourceTree = SOURCE_ROOT; }; 729F10FD1C65A9B500DFCCC5 /* ConfigUITest.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = ConfigUITest.xcconfig; sourceTree = ""; }; 729F10FE1C65A9B500DFCCC5 /* ConfigUITestCoverage.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = ConfigUITestCoverage.xcconfig; sourceTree = ""; }; - 72A450511C69A68900D67EEA /* SPUUpdatePermission.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SPUUpdatePermission.h; sourceTree = ""; }; - 72A450521C69A68900D67EEA /* SPUUpdatePermission.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SPUUpdatePermission.m; sourceTree = ""; }; + 72A450511C69A68900D67EEA /* SPUUpdatePermissionResponse.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SPUUpdatePermissionResponse.h; sourceTree = ""; }; + 72A450521C69A68900D67EEA /* SPUUpdatePermissionResponse.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SPUUpdatePermissionResponse.m; sourceTree = ""; }; 72A4A23F1BB6567D00E7820D /* SUFileManagerTest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SUFileManagerTest.swift; sourceTree = ""; }; 72A6F9891C94E2D6005F404C /* SUUpdaterDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SUUpdaterDelegate.h; sourceTree = ""; }; 72AC6B251B9AAC8800F62325 /* SparkleTestCodeSignApp.tar.gz */ = {isa = PBXFileReference; lastKnownFileType = archive.gzip; path = SparkleTestCodeSignApp.tar.gz; sourceTree = ""; }; @@ -1018,6 +1020,8 @@ 72D954B01CBB41E2006F28BD /* ConfigSparkleTool.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = ConfigSparkleTool.xcconfig; sourceTree = ""; }; 72D954B61CBB467F006F28BD /* SPUCommandLineUserDriver.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SPUCommandLineUserDriver.h; sourceTree = ""; }; 72D954B71CBB467F006F28BD /* SPUCommandLineUserDriver.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SPUCommandLineUserDriver.m; sourceTree = ""; }; + 72DBA37B1D60CC34002594A8 /* SPUUpdatePermissionRequest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SPUUpdatePermissionRequest.h; sourceTree = ""; }; + 72DBA37C1D60CC34002594A8 /* SPUUpdatePermissionRequest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SPUUpdatePermissionRequest.m; sourceTree = ""; }; 72E45CF11B640CDD005C701A /* SUTestApplicationDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SUTestApplicationDelegate.h; sourceTree = ""; }; 72E45CF21B640CDD005C701A /* SUTestApplicationDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SUTestApplicationDelegate.m; sourceTree = ""; }; 72E45CF41B640DAE005C701A /* SUUpdateSettingsWindowController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SUUpdateSettingsWindowController.h; sourceTree = ""; }; @@ -1596,8 +1600,10 @@ 726E078B1CA891E9001A286B /* SPUUpdaterSettings.h */, 726E078C1CA891E9001A286B /* SPUUpdaterSettings.m */, 72F9EC471D5EA7D3004AC8B6 /* SPUUpdaterDelegate.h */, - 72A450511C69A68900D67EEA /* SPUUpdatePermission.h */, - 72A450521C69A68900D67EEA /* SPUUpdatePermission.m */, + 72DBA37B1D60CC34002594A8 /* SPUUpdatePermissionRequest.h */, + 72DBA37C1D60CC34002594A8 /* SPUUpdatePermissionRequest.m */, + 72A450511C69A68900D67EEA /* SPUUpdatePermissionResponse.h */, + 72A450521C69A68900D67EEA /* SPUUpdatePermissionResponse.m */, 720E21791D0D00BF003A311C /* SPUUpdaterCycle.h */, 720E217A1D0D00BF003A311C /* SPUUpdaterCycle.m */, 72F9EC3D1D5E823F004AC8B6 /* SPUUpdaterTimer.h */, @@ -1867,6 +1873,7 @@ isa = PBXHeadersBuildPhase; buildActionMask = 2147483647; files = ( + 72DBA37D1D60CC34002594A8 /* SPUUpdatePermissionRequest.h in Headers */, 72F9EC4B1D5F53A7004AC8B6 /* SPUUserDriverUIComponent.h in Headers */, 72F9EC441D5E9ED8004AC8B6 /* SPUDownloadData.h in Headers */, 725F977B1C8A896F00265BE4 /* SPUUserDriverCoreComponent.h in Headers */, @@ -1883,7 +1890,7 @@ 725CB9571C7120410064365A /* SPUUserDriver.h in Headers */, 72162B061C82C8B30013C1C5 /* SUParameterAssert.h in Headers */, 726DF88E1C84277600188804 /* SPUStatusCompletionResults.h in Headers */, - 72A450531C69A68900D67EEA /* SPUUpdatePermission.h in Headers */, + 72A450531C69A68900D67EEA /* SPUUpdatePermissionResponse.h in Headers */, 7267E5B61D3D8AEE00D1BF90 /* SPUInstallationInfo.h in Headers */, 7229E1B61C97C91100CB50D0 /* SUUpdateDriver.h in Headers */, 61299B3609CB04E000B7442F /* Sparkle.h in Headers */, @@ -2853,8 +2860,9 @@ 72F9EBE31D517E2F004AC8B6 /* SUUpdater.m in Sources */, 72B767CF1C9B924900A07552 /* SUInstallerDriver.m in Sources */, 720E217C1D0D00BF003A311C /* SPUUpdaterCycle.m in Sources */, - 72A450541C69A68900D67EEA /* SPUUpdatePermission.m in Sources */, + 72A450541C69A68900D67EEA /* SPUUpdatePermissionResponse.m in Sources */, 724BB3881D32A167005D534A /* SUXPCInstallerConnection.m in Sources */, + 72DBA37E1D60CC34002594A8 /* SPUUpdatePermissionRequest.m in Sources */, 7214B8821D456A8500CB5CED /* SPUBundleIcon.m in Sources */, 72F9EC401D5E823F004AC8B6 /* SPUUpdaterTimer.m in Sources */, 7229E1BA1C97CC4D00CB50D0 /* SUScheduledUpdateDriver.m in Sources */, diff --git a/Sparkle/SPUStandardUserDriver.m b/Sparkle/SPUStandardUserDriver.m index d0e4997d..c7645ec5 100644 --- a/Sparkle/SPUStandardUserDriver.m +++ b/Sparkle/SPUStandardUserDriver.m @@ -18,7 +18,6 @@ #import "SUUpdateAlert.h" #import "SULocalizations.h" #import "SPUApplicationInfo.h" -#import "SPUDownloadData.h" @interface SPUStandardUserDriver () @@ -83,13 +82,14 @@ #pragma mark Update Permission -- (void)requestUpdatePermissionWithSystemProfile:(NSArray *)systemProfile reply:(void (^)(SPUUpdatePermission *))reply +- (void)showUpdatePermissionRequest:(SPUUpdatePermissionRequest *)request reply:(void (^)(SPUUpdatePermissionResponse *))reply { dispatch_async(dispatch_get_main_queue(), ^{ // This shows a modal alert dialog which unlike other alerts cannot be closed until the user makes a decision // This means that we can never programatically close the dialog if something goes horribly wrong // But this dialog should only show up once in the application's lifetime so this may be an OK decision - [SPUUpdatePermissionPrompt promptWithHost:self.host systemProfile:systemProfile reply:reply]; + + [SPUUpdatePermissionPrompt promptWithHost:self.host request:request reply:reply]; }); } diff --git a/Sparkle/SPUUpdatePermission.h b/Sparkle/SPUUpdatePermission.h deleted file mode 100644 index 9ccdf633..00000000 --- a/Sparkle/SPUUpdatePermission.h +++ /dev/null @@ -1,24 +0,0 @@ -// -// SPUUpdatePermission.h -// Sparkle -// -// Created by Mayur Pawashe on 2/8/16. -// Copyright © 2016 Sparkle Project. All rights reserved. -// - -#import -#import "SUExport.h" - -typedef NS_ENUM(NSInteger, SPUCheckUpdatesChoice) { - SUAutomaticallyCheck, - SUDoNotAutomaticallyCheck -}; - -SU_EXPORT @interface SPUUpdatePermission : NSObject - -+ (instancetype)updatePermissionWithChoice:(SPUCheckUpdatesChoice)choice sendProfile:(BOOL)sendProfile; - -@property (nonatomic, readonly) SPUCheckUpdatesChoice choice; -@property (nonatomic, readonly) BOOL sendProfile; - -@end diff --git a/Sparkle/SPUUpdatePermission.m b/Sparkle/SPUUpdatePermission.m deleted file mode 100644 index 3a557f88..00000000 --- a/Sparkle/SPUUpdatePermission.m +++ /dev/null @@ -1,56 +0,0 @@ -// -// SPUUpdatePermission.m -// Sparkle -// -// Created by Mayur Pawashe on 2/8/16. -// Copyright © 2016 Sparkle Project. All rights reserved. -// - -#import "SPUUpdatePermission.h" - -#ifdef _APPKITDEFINES_H -#error This is a "core" class and should NOT import AppKit -#endif - -static NSString *SPUUpdatePermissionChoiceKey = @"SPUUpdatePermissionChoice"; -static NSString *SPUUpdatePermissionSendProfileKey = @"SPUUpdatePermissionSendProfile"; - -@implementation SPUUpdatePermission - -@synthesize choice = _choice; -@synthesize sendProfile = _sendProfile; - -+ (BOOL)supportsSecureCoding -{ - return YES; -} - -- (instancetype)initWithCoder:(NSCoder *)decoder -{ - NSInteger choice = [decoder decodeIntegerForKey:SPUUpdatePermissionChoiceKey]; - BOOL sendProfile = [decoder decodeBoolForKey:SPUUpdatePermissionSendProfileKey]; - return [[self class] updatePermissionWithChoice:choice sendProfile:sendProfile]; -} - -- (void)encodeWithCoder:(NSCoder *)encoder -{ - [encoder encodeInteger:self.choice forKey:SPUUpdatePermissionChoiceKey]; - [encoder encodeBool:self.sendProfile forKey:SPUUpdatePermissionSendProfileKey]; -} - -- (instancetype)initWithCheckUpdatesChoice:(SPUCheckUpdatesChoice)choice sendProfile:(BOOL)sendProfile -{ - self = [super init]; - if (self != nil) { - _choice = choice; - _sendProfile = sendProfile; - } - return self; -} - -+ (instancetype)updatePermissionWithChoice:(SPUCheckUpdatesChoice)choice sendProfile:(BOOL)sendProfile -{ - return [[self alloc] initWithCheckUpdatesChoice:choice sendProfile:sendProfile]; -} - -@end diff --git a/Sparkle/SPUUpdatePermissionPrompt.h b/Sparkle/SPUUpdatePermissionPrompt.h index 6d2835ce..7e3958c4 100644 --- a/Sparkle/SPUUpdatePermissionPrompt.h +++ b/Sparkle/SPUUpdatePermissionPrompt.h @@ -11,11 +11,11 @@ #import -@class SUHost, SPUUpdatePermission; +@class SUHost, SPUUpdatePermissionRequest, SPUUpdatePermissionResponse; @interface SPUUpdatePermissionPrompt : NSWindowController -+ (void)promptWithHost:(SUHost *)host systemProfile:(NSArray *)systemProfile reply:(void (^)(SPUUpdatePermission *))reply; ++ (void)promptWithHost:(SUHost *)host request:(SPUUpdatePermissionRequest *)request reply:(void (^)(SPUUpdatePermissionResponse *))reply; - (IBAction)toggleMoreInfo:(id)sender; - (IBAction)finishPrompt:(id)sender; diff --git a/Sparkle/SPUUpdatePermissionPrompt.m b/Sparkle/SPUUpdatePermissionPrompt.m index 736c1b93..8cc28a03 100644 --- a/Sparkle/SPUUpdatePermissionPrompt.m +++ b/Sparkle/SPUUpdatePermissionPrompt.m @@ -7,7 +7,8 @@ // #import "SPUUpdatePermissionPrompt.h" -#import "SPUUpdatePermission.h" +#import "SPUUpdatePermissionRequest.h" +#import "SPUUpdatePermissionResponse.h" #import "SULocalizations.h" #import "SUHost.h" @@ -26,7 +27,7 @@ @property (weak) IBOutlet NSButton *moreInfoButton; @property (weak) IBOutlet NSTableView *profileTableView; -@property (nonatomic, readonly) void (^reply)(SPUUpdatePermission *); +@property (nonatomic, readonly) void (^reply)(SPUUpdatePermissionResponse *); @end @@ -42,7 +43,7 @@ @synthesize moreInfoButton; @synthesize profileTableView; -- (instancetype)initPromptWithHost:(SUHost *)theHost systemProfile:(NSArray *)systemProfile reply:(void (^)(SPUUpdatePermission *))reply +- (instancetype)initPromptWithHost:(SUHost *)theHost request:(SPUUpdatePermissionRequest *)request reply:(void (^)(SPUUpdatePermissionResponse *))reply { self = [super initWithWindowNibName:@"SPUUpdatePermissionPrompt"]; if (self) @@ -51,13 +52,13 @@ self.host = theHost; self.isShowingMoreInfo = NO; self.shouldSendProfile = [self shouldAskAboutProfile]; - self.systemProfileInformationArray = systemProfile; + self.systemProfileInformationArray = request.systemProfile; [self setShouldCascadeWindows:NO]; } return self; } -+ (void)promptWithHost:(SUHost *)host systemProfile:(NSArray *)systemProfile reply:(void (^)(SPUUpdatePermission *))reply ++ (void)promptWithHost:(SUHost *)host request:(SPUUpdatePermissionRequest *)request reply:(void (^)(SPUUpdatePermissionResponse *))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 @@ -67,7 +68,7 @@ } if (![NSApp modalWindow]) { // do not prompt if there is is another modal window on screen - SPUUpdatePermissionPrompt *prompt = [[[self class] alloc] initPromptWithHost:host systemProfile:systemProfile reply:reply]; + SPUUpdatePermissionPrompt *prompt = [[[self class] alloc] initPromptWithHost:host request:request reply:reply]; NSWindow *window = [prompt window]; if (window) { [NSApp runModalForWindow:window]; @@ -153,7 +154,8 @@ - (IBAction)finishPrompt:(id)sender { - self.reply([SPUUpdatePermission updatePermissionWithChoice:([sender tag] == 1 ? SUAutomaticallyCheck : SUDoNotAutomaticallyCheck) sendProfile:self.shouldSendProfile]); + SPUUpdatePermissionResponse *response = [[SPUUpdatePermissionResponse alloc] initWithAutomaticUpdateChecks:([sender tag] == 1) sendSystemProfile:self.shouldSendProfile]; + self.reply(response); [[self window] close]; [NSApp stopModal]; diff --git a/Sparkle/SPUUpdatePermissionRequest.h b/Sparkle/SPUUpdatePermissionRequest.h new file mode 100644 index 00000000..d96a79b1 --- /dev/null +++ b/Sparkle/SPUUpdatePermissionRequest.h @@ -0,0 +1,33 @@ +// +// SPUUpdatePermissionRequest.h +// Sparkle +// +// Created by Mayur Pawashe on 8/14/16. +// Copyright © 2016 Sparkle Project. All rights reserved. +// + +#import +#import "SUExport.h" + +NS_ASSUME_NONNULL_BEGIN + +/*! + This class represents information needed to make a permission request for checking updates. + */ +SU_EXPORT @interface SPUUpdatePermissionRequest : NSObject + +/*! + Initializes a new update permission request instance. + + @param systemProfile The system profile information. + */ +- (instancetype)initWithSystemProfile:(NSArray *> *)systemProfile; + +/*! + A read-only property for the user's system profile. + */ +@property (nonatomic, readonly) NSArray *> *systemProfile; + +@end + +NS_ASSUME_NONNULL_END diff --git a/Sparkle/SPUUpdatePermissionRequest.m b/Sparkle/SPUUpdatePermissionRequest.m new file mode 100644 index 00000000..4d747230 --- /dev/null +++ b/Sparkle/SPUUpdatePermissionRequest.m @@ -0,0 +1,46 @@ +// +// SPUUpdatePermissionRequest.m +// Sparkle +// +// Created by Mayur Pawashe on 8/14/16. +// Copyright © 2016 Sparkle Project. All rights reserved. +// + +#import "SPUUpdatePermissionRequest.h" + +static NSString *SPUUpdatePermissionRequestSystemProfileKey = @"SPUUpdatePermissionRequestSystemProfile"; + +@implementation SPUUpdatePermissionRequest + +@synthesize systemProfile = _systemProfile; + ++ (BOOL)supportsSecureCoding +{ + return YES; +} + +- (instancetype)initWithCoder:(NSCoder *)decoder +{ + NSArray *> *systemProfile = [decoder decodeObjectOfClasses:[NSSet setWithArray:@[[NSArray class], [NSDictionary class], [NSString class]]] forKey:SPUUpdatePermissionRequestSystemProfileKey]; + if (systemProfile == nil) { + return nil; + } + + return [self initWithSystemProfile:systemProfile]; +} + +- (void)encodeWithCoder:(NSCoder *)encoder +{ + [encoder encodeObject:self.systemProfile forKey:SPUUpdatePermissionRequestSystemProfileKey]; +} + +- (instancetype)initWithSystemProfile:(NSArray *> *)systemProfile +{ + self = [super init]; + if (self != nil) { + _systemProfile = systemProfile; + } + return self; +} + +@end diff --git a/Sparkle/SPUUpdatePermissionResponse.h b/Sparkle/SPUUpdatePermissionResponse.h new file mode 100644 index 00000000..9d62e894 --- /dev/null +++ b/Sparkle/SPUUpdatePermissionResponse.h @@ -0,0 +1,35 @@ +// +// SPUUpdatePermissionResponse.h +// Sparkle +// +// Created by Mayur Pawashe on 2/8/16. +// Copyright © 2016 Sparkle Project. All rights reserved. +// + +#import +#import "SUExport.h" + +/*! + This class represents a response for permission to check updates. +*/ +SU_EXPORT @interface SPUUpdatePermissionResponse : NSObject + +/*! + Initializes a new update permission response instance. + + @param automaticUpdateChecks Flag for whether to allow automatic update checks. + @param sendSystemProfile Flag for if system profile information should be sent to the server hosting the appcast. + */ +- (instancetype)initWithAutomaticUpdateChecks:(BOOL)automaticUpdateChecks sendSystemProfile:(BOOL)sendSystemProfile; + +/*! + A read-only property indicating whether automatic update checks are allowed or not. + */ +@property (nonatomic, readonly) BOOL automaticUpdateChecks; + +/*! + A read-only property indicating if system profile should be sent or not. + */ +@property (nonatomic, readonly) BOOL sendSystemProfile; + +@end diff --git a/Sparkle/SPUUpdatePermissionResponse.m b/Sparkle/SPUUpdatePermissionResponse.m new file mode 100644 index 00000000..ff99f642 --- /dev/null +++ b/Sparkle/SPUUpdatePermissionResponse.m @@ -0,0 +1,51 @@ +// +// SPUUpdatePermissionResponse.m +// Sparkle +// +// Created by Mayur Pawashe on 2/8/16. +// Copyright © 2016 Sparkle Project. All rights reserved. +// + +#import "SPUUpdatePermissionResponse.h" + +#ifdef _APPKITDEFINES_H +#error This is a "core" class and should NOT import AppKit +#endif + +static NSString *SPUUpdatePermissionAutomaticUpdateChecksKey = @"SPUUpdatePermissionAutomaticUpdateChecks"; +static NSString *SPUUpdatePermissionSendSystemProfileKey = @"SPUUpdatePermissionSendSystemProfile"; + +@implementation SPUUpdatePermissionResponse + +@synthesize automaticUpdateChecks = _automaticUpdateChecks; +@synthesize sendSystemProfile = _sendSystemProfile; + ++ (BOOL)supportsSecureCoding +{ + return YES; +} + +- (instancetype)initWithCoder:(NSCoder *)decoder +{ + BOOL automaticUpdateChecks = [decoder decodeBoolForKey:SPUUpdatePermissionAutomaticUpdateChecksKey]; + BOOL sendSystemProfile = [decoder decodeBoolForKey:SPUUpdatePermissionSendSystemProfileKey]; + return [self initWithAutomaticUpdateChecks:automaticUpdateChecks sendSystemProfile:sendSystemProfile]; +} + +- (void)encodeWithCoder:(NSCoder *)encoder +{ + [encoder encodeBool:self.automaticUpdateChecks forKey:SPUUpdatePermissionAutomaticUpdateChecksKey]; + [encoder encodeBool:self.sendSystemProfile forKey:SPUUpdatePermissionSendSystemProfileKey]; +} + +- (instancetype)initWithAutomaticUpdateChecks:(BOOL)automaticUpdateChecks sendSystemProfile:(BOOL)sendSystemProfile +{ + self = [super init]; + if (self != nil) { + _automaticUpdateChecks = automaticUpdateChecks; + _sendSystemProfile = sendSystemProfile; + } + return self; +} + +@end diff --git a/Sparkle/SPUUpdater.m b/Sparkle/SPUUpdater.m index 7d0ed15c..b7dc2995 100644 --- a/Sparkle/SPUUpdater.m +++ b/Sparkle/SPUUpdater.m @@ -10,7 +10,8 @@ #import "SPUUpdaterDelegate.h" #import "SPUUpdaterSettings.h" #import "SUHost.h" -#import "SPUUpdatePermission.h" +#import "SPUUpdatePermissionRequest.h" +#import "SPUUpdatePermissionResponse.h" #import "SUUpdateDriver.h" #import "SUConstants.h" #import "SULog.h" @@ -290,7 +291,7 @@ NSString *const SUUpdaterAppcastNotificationKey = @"SUUpdaterAppCastNotification } if (shouldPrompt) { - NSArray *profileInfo = [SUSystemProfiler systemProfileArrayForHost:self.host]; + NSArray *> *profileInfo = [SUSystemProfiler systemProfileArrayForHost:self.host]; // Always say we're sending the system profile here so that the delegate displays the parameters it would send. if ([self.delegate respondsToSelector:@selector(feedParametersForUpdater:sendingSystemProfile:)]) { NSArray *feedParameters = [self.delegate feedParametersForUpdater:self sendingSystemProfile:YES]; @@ -299,12 +300,14 @@ NSString *const SUUpdaterAppcastNotificationKey = @"SUUpdaterAppCastNotification } } + SPUUpdatePermissionRequest *updatePermissionRequest = [[SPUUpdatePermissionRequest alloc] initWithSystemProfile:profileInfo]; + __weak SPUUpdater *weakSelf = self; - [self.userDriver requestUpdatePermissionWithSystemProfile:profileInfo reply:^(SPUUpdatePermission *result) { + [self.userDriver showUpdatePermissionRequest:updatePermissionRequest reply:^(SPUUpdatePermissionResponse *response) { dispatch_async(dispatch_get_main_queue(), ^{ SPUUpdater *strongSelf = weakSelf; if (strongSelf != nil) { - [strongSelf updatePermissionPromptFinishedWithResult:result]; + [strongSelf updatePermissionRequestFinishedWithResponse:response]; // Schedule checks, but make sure we ignore the delayed call from KVO [strongSelf resetUpdateCycle]; } @@ -323,10 +326,10 @@ NSString *const SUUpdaterAppcastNotificationKey = @"SUUpdaterAppCastNotification } } -- (void)updatePermissionPromptFinishedWithResult:(SPUUpdatePermission *)result +- (void)updatePermissionRequestFinishedWithResponse:(SPUUpdatePermissionResponse *)response { - [self.host setBool:result.sendProfile forUserDefaultsKey:SUSendProfileInfoKey]; - [self setAutomaticallyChecksForUpdates:(result.choice == SUAutomaticallyCheck)]; + [self.host setBool:response.sendSystemProfile forUserDefaultsKey:SUSendProfileInfoKey]; + [self setAutomaticallyChecksForUpdates:response.automaticUpdateChecks]; } - (NSDate *)lastUpdateCheckDate diff --git a/Sparkle/SPUUserDriver.h b/Sparkle/SPUUserDriver.h index 5eba6bd1..4948ec5c 100644 --- a/Sparkle/SPUUserDriver.h +++ b/Sparkle/SPUUserDriver.h @@ -12,7 +12,7 @@ NS_ASSUME_NONNULL_BEGIN -@class SPUUpdatePermission, SUAppcastItem, SPUDownloadData; +@class SPUUpdatePermissionRequest, SPUUpdatePermissionResponse, SUAppcastItem, SPUDownloadData; /*! The API in Sparkle for controlling the user interaction. @@ -43,16 +43,17 @@ SU_EXPORT @protocol SPUUserDriver - (void)showCanCheckForUpdates:(BOOL)canCheckForUpdates; /*! - * Request updater permission from the user + * Show an updater permission request to the user * - * Ask the user if they want automatic update checks to be on or off, and if they want to send an anonymous system profile + * Ask the user for their permission regarding update checks. * This is typically only called once per app installation. * - * @param reply A reply supplying whether the user wants automatic update checks off or on, and whether they want to send their system profile + * @param request The update permission request. + * @param reply A reply with a update permission response. * * This can be called from any thread */ -- (void)requestUpdatePermissionWithSystemProfile:(NSArray *)systemProfile reply:(void (^)(SPUUpdatePermission *))reply; +- (void)showUpdatePermissionRequest:(SPUUpdatePermissionRequest *)request reply:(void (^)(SPUUpdatePermissionResponse *))reply; /*! * Show the user initating an update check diff --git a/Sparkle/SUSystemProfiler.h b/Sparkle/SUSystemProfiler.h index 29a7d60d..4b535163 100644 --- a/Sparkle/SUSystemProfiler.h +++ b/Sparkle/SUSystemProfiler.h @@ -14,7 +14,7 @@ @class SUHost; @interface SUSystemProfiler : NSObject -+ (NSMutableArray *)systemProfileArrayForHost:(SUHost *)host; ++ (NSArray *> *)systemProfileArrayForHost:(SUHost *)host; @end diff --git a/Sparkle/SUSystemProfiler.m b/Sparkle/SUSystemProfiler.m index b0e99658..1d73d793 100644 --- a/Sparkle/SUSystemProfiler.m +++ b/Sparkle/SUSystemProfiler.m @@ -31,19 +31,19 @@ static NSString *const SUSystemProfilerPreferredLanguageKey = @"lang"; @implementation SUSystemProfiler -+ (NSDictionary *)modelTranslationTable ++ (NSDictionary *)modelTranslationTable { // Use explicit class to use the correct bundle even when subclassed NSString *path = [[NSBundle bundleForClass:[SUSystemProfiler class]] pathForResource:@"SUModelTranslation" ofType:@"plist"]; return [[NSDictionary alloc] initWithContentsOfFile:path]; } -+ (NSMutableArray *)systemProfileArrayForHost:(SUHost *)host ++ (NSArray *> *)systemProfileArrayForHost:(SUHost *)host { - NSDictionary *modelTranslation = [self modelTranslationTable]; + NSDictionary *modelTranslation = [self modelTranslationTable]; // Gather profile information and append it to the URL. - NSMutableArray *profileArray = [NSMutableArray array]; + NSMutableArray *> *profileArray = [NSMutableArray array]; NSArray *profileDictKeys = @[@"key", @"displayKey", @"value", @"displayValue"]; int error = 0; int value = 0; @@ -161,7 +161,7 @@ static NSString *const SUSystemProfilerPreferredLanguageKey = @"lang"; [profileArray addObject:[NSDictionary dictionaryWithObjects:@[SUSystemProfilerMemoryKey, @"Memory (MB)", @(megabytes), @(megabytes)] forKeys:profileDictKeys]]; } - return profileArray; + return [profileArray copy]; } @end diff --git a/Sparkle/Sparkle.h b/Sparkle/Sparkle.h index 9ecd866a..b5ecd8d1 100644 --- a/Sparkle/Sparkle.h +++ b/Sparkle/Sparkle.h @@ -22,7 +22,8 @@ #import "SUVersionComparisonProtocol.h" #import "SUVersionDisplayProtocol.h" #import "SUErrors.h" -#import "SPUUpdatePermission.h" +#import "SPUUpdatePermissionRequest.h" +#import "SPUUpdatePermissionResponse.h" #import "SPUUserDriver.h" #import "SPUStandardUserDriver.h" #import "SPUStandardUserDriverDelegate.h" diff --git a/TestApplication/SUPopUpTitlebarUserDriver.m b/TestApplication/SUPopUpTitlebarUserDriver.m index 050c3a0a..fd20630d 100644 --- a/TestApplication/SUPopUpTitlebarUserDriver.m +++ b/TestApplication/SUPopUpTitlebarUserDriver.m @@ -121,11 +121,12 @@ #pragma mark Update Permission -- (void)requestUpdatePermissionWithSystemProfile:(NSArray *)__unused systemProfile reply:(void (^)(SPUUpdatePermission *))reply +- (void)showUpdatePermissionRequest:(SPUUpdatePermissionRequest *)__unused request reply:(void (^)(SPUUpdatePermissionResponse *))reply { // Just make a decision.. dispatch_async(dispatch_get_main_queue(), ^{ - reply([SPUUpdatePermission updatePermissionWithChoice:SUAutomaticallyCheck sendProfile:NO]); + SPUUpdatePermissionResponse *response = [[SPUUpdatePermissionResponse alloc] initWithAutomaticUpdateChecks:YES sendSystemProfile:NO]; + reply(response); }); } diff --git a/sparkle-cli/SPUCommandLineDriver.h b/sparkle-cli/SPUCommandLineDriver.h index 60cea990..e70efc28 100644 --- a/sparkle-cli/SPUCommandLineDriver.h +++ b/sparkle-cli/SPUCommandLineDriver.h @@ -10,11 +10,11 @@ NS_ASSUME_NONNULL_BEGIN -@class SPUUpdatePermission; +@class SPUUpdatePermissionResponse; @interface SPUCommandLineDriver : NSObject -- (nullable instancetype)initWithUpdateBundlePath:(NSString *)updateBundlePath applicationBundlePath:(nullable NSString *)applicationBundlePath customFeedURL:(nullable NSString *)customFeedURL updatePermission:(nullable SPUUpdatePermission *)updatePermission deferInstallation:(BOOL)deferInstallation interactiveInstallation:(BOOL)interactiveInstallation verbose:(BOOL)verbose; +- (nullable instancetype)initWithUpdateBundlePath:(NSString *)updateBundlePath applicationBundlePath:(nullable NSString *)applicationBundlePath customFeedURL:(nullable NSString *)customFeedURL updatePermissionResponse:(nullable SPUUpdatePermissionResponse *)updatePermissionResponse deferInstallation:(BOOL)deferInstallation interactiveInstallation:(BOOL)interactiveInstallation verbose:(BOOL)verbose; - (void)runAndCheckForUpdatesNow:(BOOL)checkForUpdatesNow; diff --git a/sparkle-cli/SPUCommandLineDriver.m b/sparkle-cli/SPUCommandLineDriver.m index 340af0c2..ccfab029 100644 --- a/sparkle-cli/SPUCommandLineDriver.m +++ b/sparkle-cli/SPUCommandLineDriver.m @@ -30,7 +30,7 @@ void _SULogDisableStandardErrorStream(void); @synthesize interactive = _interactive; @synthesize customFeedURL = _customFeedURL; -- (instancetype)initWithUpdateBundlePath:(NSString *)updateBundlePath applicationBundlePath:(nullable NSString *)applicationBundlePath customFeedURL:(nullable NSString *)customFeedURL updatePermission:(nullable SPUUpdatePermission *)updatePermission deferInstallation:(BOOL)deferInstallation interactiveInstallation:(BOOL)interactiveInstallation verbose:(BOOL)verbose +- (instancetype)initWithUpdateBundlePath:(NSString *)updateBundlePath applicationBundlePath:(nullable NSString *)applicationBundlePath customFeedURL:(nullable NSString *)customFeedURL updatePermissionResponse:(nullable SPUUpdatePermissionResponse *)updatePermissionResponse deferInstallation:(BOOL)deferInstallation interactiveInstallation:(BOOL)interactiveInstallation verbose:(BOOL)verbose { self = [super init]; if (self != nil) { @@ -57,7 +57,7 @@ void _SULogDisableStandardErrorStream(void); _SULogDisableStandardErrorStream(); #endif - id userDriver = [[SPUCommandLineUserDriver alloc] initWithApplicationBundle:applicationBundle updatePermission:updatePermission deferInstallation:deferInstallation verbose:verbose]; + id userDriver = [[SPUCommandLineUserDriver alloc] initWithApplicationBundle:applicationBundle updatePermissionResponse:updatePermissionResponse deferInstallation:deferInstallation verbose:verbose]; _updater = [[SPUUpdater alloc] initWithHostBundle:updateBundle applicationBundle:applicationBundle userDriver:userDriver delegate:self]; } return self; diff --git a/sparkle-cli/SPUCommandLineUserDriver.h b/sparkle-cli/SPUCommandLineUserDriver.h index fc99841b..102d04f4 100644 --- a/sparkle-cli/SPUCommandLineUserDriver.h +++ b/sparkle-cli/SPUCommandLineUserDriver.h @@ -13,7 +13,7 @@ NS_ASSUME_NONNULL_BEGIN @interface SPUCommandLineUserDriver : NSObject -- (instancetype)initWithApplicationBundle:(NSBundle *)applicationBundle updatePermission:(nullable SPUUpdatePermission *)updatePermission deferInstallation:(BOOL)deferInstallation verbose:(BOOL)verbose; +- (instancetype)initWithApplicationBundle:(NSBundle *)applicationBundle updatePermissionResponse:(nullable SPUUpdatePermissionResponse *)updatePermissionResponse deferInstallation:(BOOL)deferInstallation verbose:(BOOL)verbose; @end diff --git a/sparkle-cli/SPUCommandLineUserDriver.m b/sparkle-cli/SPUCommandLineUserDriver.m index 94fbac12..86a44db2 100644 --- a/sparkle-cli/SPUCommandLineUserDriver.m +++ b/sparkle-cli/SPUCommandLineUserDriver.m @@ -14,7 +14,7 @@ @interface SPUCommandLineUserDriver () @property (nonatomic, readonly) NSBundle *applicationBundle; -@property (nonatomic, nullable, readonly) SPUUpdatePermission *updatePermission; +@property (nonatomic, nullable, readonly) SPUUpdatePermissionResponse *updatePermissionResponse; @property (nonatomic, readonly) BOOL deferInstallation; @property (nonatomic, readonly) BOOL verbose; @property (nonatomic, readonly) SPUUserDriverCoreComponent *coreComponent; @@ -27,7 +27,7 @@ @implementation SPUCommandLineUserDriver @synthesize applicationBundle = _applicationBundle; -@synthesize updatePermission = _updatePermission; +@synthesize updatePermissionResponse = _updatePermissionResponse; @synthesize deferInstallation = _deferInstallation; @synthesize verbose = _verbose; @synthesize coreComponent = _coreComponent; @@ -35,12 +35,12 @@ @synthesize bytesDownloaded = _bytesDownloaded; @synthesize bytesToDownload = _bytesToDownload; -- (instancetype)initWithApplicationBundle:(NSBundle *)applicationBundle updatePermission:(nullable SPUUpdatePermission *)updatePermission deferInstallation:(BOOL)deferInstallation verbose:(BOOL)verbose +- (instancetype)initWithApplicationBundle:(NSBundle *)applicationBundle updatePermissionResponse:(nullable SPUUpdatePermissionResponse *)updatePermissionResponse deferInstallation:(BOOL)deferInstallation verbose:(BOOL)verbose { self = [super init]; if (self != nil) { _applicationBundle = applicationBundle; - _updatePermission = updatePermission; + _updatePermissionResponse = updatePermissionResponse; _deferInstallation = deferInstallation; _verbose = verbose; _coreComponent = [[SPUUserDriverCoreComponent alloc] init]; @@ -56,18 +56,18 @@ }); } -- (void)requestUpdatePermissionWithSystemProfile:(NSArray *)__unused systemProfile reply:(void (^)(SPUUpdatePermission *))reply +- (void)showUpdatePermissionRequest:(SPUUpdatePermissionRequest *)__unused request reply:(void (^)(SPUUpdatePermissionResponse *))reply { dispatch_async(dispatch_get_main_queue(), ^{ - if (self.updatePermission == nil) { + if (self.updatePermissionResponse == nil) { // We don't want to make this decision on behalf of the user. fprintf(stderr, "Error: Asked to grant update permission. Exiting.\n"); exit(EXIT_FAILURE); } else { if (self.verbose) { - fprintf(stderr, "Granting permission for automatic update checks with sending system profile %s...\n", self.updatePermission.sendProfile ? "enabled" : "disabled"); + fprintf(stderr, "Granting permission for automatic update checks with sending system profile %s...\n", self.updatePermissionResponse.sendSystemProfile ? "enabled" : "disabled"); } - reply(self.updatePermission); + reply(self.updatePermissionResponse); } }); } diff --git a/sparkle-cli/main.m b/sparkle-cli/main.m index ac92ff3a..85f8efcb 100644 --- a/sparkle-cli/main.m +++ b/sparkle-cli/main.m @@ -141,12 +141,12 @@ int main(int argc, char **argv) return EXIT_FAILURE; } - SPUUpdatePermission *updatePermission = nil; + SPUUpdatePermissionResponse *updatePermissionResponse = nil; if (grantAutomaticChecking) { - updatePermission = [SPUUpdatePermission updatePermissionWithChoice:SUAutomaticallyCheck sendProfile:sendProfile]; + updatePermissionResponse = [[SPUUpdatePermissionResponse alloc] initWithAutomaticUpdateChecks:YES sendSystemProfile:sendProfile]; } - SPUCommandLineDriver *driver = [[SPUCommandLineDriver alloc] initWithUpdateBundlePath:updatePath applicationBundlePath:applicationPath customFeedURL:feedURL updatePermission:updatePermission deferInstallation:deferInstall interactiveInstallation:interactive verbose:verbose]; + SPUCommandLineDriver *driver = [[SPUCommandLineDriver alloc] initWithUpdateBundlePath:updatePath applicationBundlePath:applicationPath customFeedURL:feedURL updatePermissionResponse:updatePermissionResponse deferInstallation:deferInstall interactiveInstallation:interactive verbose:verbose]; if (driver == nil) { fprintf(stderr, "Error: Failed to initialize updater. Are the bundle paths provided valid?\n"); return EXIT_FAILURE;