diff --git a/sparkle-cli/SUCommandLineDriver.h b/sparkle-cli/SUCommandLineDriver.h index c05e120d..2d51d754 100644 --- a/sparkle-cli/SUCommandLineDriver.h +++ b/sparkle-cli/SUCommandLineDriver.h @@ -10,9 +10,11 @@ NS_ASSUME_NONNULL_BEGIN +@class SUUpdatePermissionPromptResult; + @interface SUCommandLineDriver : NSObject -- (nullable instancetype)initWithUpdateBundlePath:(NSString *)updateBundlePath applicationBundlePath:(nullable NSString *)applicationBundlePath deferInstallation:(BOOL)deferInstallation verbose:(BOOL)verbose; +- (nullable instancetype)initWithUpdateBundlePath:(NSString *)updateBundlePath applicationBundlePath:(nullable NSString *)applicationBundlePath updatePermission:(nullable SUUpdatePermissionPromptResult *)updatePermission deferInstallation:(BOOL)deferInstallation verbose:(BOOL)verbose; - (void)runAndCheckForUpdatesNow:(BOOL)checkForUpdatesNow; diff --git a/sparkle-cli/SUCommandLineDriver.m b/sparkle-cli/SUCommandLineDriver.m index 60bc983a..2cff11ab 100644 --- a/sparkle-cli/SUCommandLineDriver.m +++ b/sparkle-cli/SUCommandLineDriver.m @@ -22,7 +22,7 @@ @synthesize updater = _updater; @synthesize applicationBundlePath = _applicationBundlePath; -- (instancetype)initWithUpdateBundlePath:(NSString *)updateBundlePath applicationBundlePath:(nullable NSString *)applicationBundlePath deferInstallation:(BOOL)deferInstallation verbose:(BOOL)verbose +- (instancetype)initWithUpdateBundlePath:(NSString *)updateBundlePath applicationBundlePath:(nullable NSString *)applicationBundlePath updatePermission:(nullable SUUpdatePermissionPromptResult *)updatePermission deferInstallation:(BOOL)deferInstallation verbose:(BOOL)verbose { self = [super init]; if (self != nil) { @@ -43,7 +43,7 @@ _applicationBundlePath = applicationBundle.bundlePath; - id userDriver = [[SUCommandLineUserDriver alloc] initWithApplicationBundle:applicationBundle deferInstallation:deferInstallation verbose:verbose]; + id userDriver = [[SUCommandLineUserDriver alloc] initWithApplicationBundle:applicationBundle updatePermission:updatePermission deferInstallation:deferInstallation verbose:verbose]; _updater = [[SUUpdater alloc] initWithHostBundle:updateBundle userDriver:userDriver delegate:self]; } return self; diff --git a/sparkle-cli/SUCommandLineUserDriver.h b/sparkle-cli/SUCommandLineUserDriver.h index 18446593..64790cbb 100644 --- a/sparkle-cli/SUCommandLineUserDriver.h +++ b/sparkle-cli/SUCommandLineUserDriver.h @@ -13,7 +13,7 @@ NS_ASSUME_NONNULL_BEGIN @interface SUCommandLineUserDriver : NSObject -- (instancetype)initWithApplicationBundle:(NSBundle *)applicationBundle deferInstallation:(BOOL)deferInstallation verbose:(BOOL)verbose; +- (instancetype)initWithApplicationBundle:(NSBundle *)applicationBundle updatePermission:(nullable SUUpdatePermissionPromptResult *)updatePermission deferInstallation:(BOOL)deferInstallation verbose:(BOOL)verbose; @end diff --git a/sparkle-cli/SUCommandLineUserDriver.m b/sparkle-cli/SUCommandLineUserDriver.m index b3bf58a3..334bde7c 100644 --- a/sparkle-cli/SUCommandLineUserDriver.m +++ b/sparkle-cli/SUCommandLineUserDriver.m @@ -14,6 +14,7 @@ @interface SUCommandLineUserDriver () @property (nonatomic, readonly) NSBundle *applicationBundle; +@property (nonatomic, nullable, readonly) SUUpdatePermissionPromptResult *updatePermission; @property (nonatomic, readonly) BOOL deferInstallation; @property (nonatomic, readonly) BOOL verbose; @property (nonatomic, readonly) SUUserDriverCoreComponent *coreComponent; @@ -25,17 +26,19 @@ @implementation SUCommandLineUserDriver @synthesize applicationBundle = _applicationBundle; +@synthesize updatePermission = _updatePermission; @synthesize deferInstallation = _deferInstallation; @synthesize verbose = _verbose; @synthesize coreComponent = _coreComponent; @synthesize bytesDownloaded = _bytesDownloaded; @synthesize bytesToDownload = _bytesToDownload; -- (instancetype)initWithApplicationBundle:(NSBundle *)applicationBundle deferInstallation:(BOOL)deferInstallation verbose:(BOOL)verbose +- (instancetype)initWithApplicationBundle:(NSBundle *)applicationBundle updatePermission:(nullable SUUpdatePermissionPromptResult *)updatePermission deferInstallation:(BOOL)deferInstallation verbose:(BOOL)verbose { self = [super init]; if (self != nil) { _applicationBundle = applicationBundle; + _updatePermission = updatePermission; _deferInstallation = deferInstallation; _verbose = verbose; _coreComponent = [[SUUserDriverCoreComponent alloc] initWithDelegate:nil]; @@ -83,12 +86,19 @@ }); } -- (void)requestUpdatePermissionWithSystemProfile:(NSArray *)__unused systemProfile reply:(void (^)(SUUpdatePermissionPromptResult *))__unused reply +- (void)requestUpdatePermissionWithSystemProfile:(NSArray *)__unused systemProfile reply:(void (^)(SUUpdatePermissionPromptResult *))reply { dispatch_async(dispatch_get_main_queue(), ^{ - // We really shouldn't get here. If we do, we would be in trouble. We don't want to make this decision on behalf of the user. - fprintf(stderr, "Error: Asked about making update permission decision. Aborting because this decision should not be made.\n"); - exit(EXIT_FAILURE); + if (self.updatePermission == 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.shouldSendProfile ? "enabled" : "disabled"); + } + reply(self.updatePermission); + } }); } diff --git a/sparkle-cli/main.m b/sparkle-cli/main.m index ab8fbe60..a0c82fbc 100644 --- a/sparkle-cli/main.m +++ b/sparkle-cli/main.m @@ -7,17 +7,20 @@ // #import +#import #import "SUCommandLineDriver.h" #include #define APPLICATION_FLAG "application" -#define DEFER_FLAG "defer" +#define DEFER_FLAG "defer-install" #define VERBOSE_FLAG "verbose" -#define CHECK_NOW_FLAG "checknow" +#define CHECK_NOW_FLAG "check-immediately" +#define GRANT_AUTOMATIC_CHECKING_FLAG "grant-automatic-checks" +#define SEND_PROFILE_FLAG "send-profile" static void printUsage(char **argv) { - fprintf(stderr, "Usage: %s [--%s ] [--%s] [--%s] [--%s]\n", argv[0], APPLICATION_FLAG, CHECK_NOW_FLAG, DEFER_FLAG, VERBOSE_FLAG); + fprintf(stderr, "Usage: %s [--%s ] [--%s] [--%s] [--%s] [--%s] [--%s]\n", argv[0], APPLICATION_FLAG, CHECK_NOW_FLAG, GRANT_AUTOMATIC_CHECKING_FLAG, SEND_PROFILE_FLAG, DEFER_FLAG, VERBOSE_FLAG); } int main(int argc, char **argv) @@ -29,6 +32,8 @@ int main(int argc, char **argv) {DEFER_FLAG, no_argument, NULL, 0}, {VERBOSE_FLAG, no_argument, NULL, 0}, {CHECK_NOW_FLAG, no_argument, NULL, 0}, + {GRANT_AUTOMATIC_CHECKING_FLAG, no_argument, NULL, 0}, + {SEND_PROFILE_FLAG, no_argument, NULL, 0}, {0, 0, 0, 0} }; @@ -36,6 +41,8 @@ int main(int argc, char **argv) BOOL deferInstall = NO; BOOL verbose = NO; BOOL checkForUpdatesNow = NO; + BOOL grantAutomaticChecking = NO; + BOOL sendProfile = NO; while (YES) { int optionIndex = 0; @@ -59,6 +66,10 @@ int main(int argc, char **argv) verbose = YES; } else if (strcmp(CHECK_NOW_FLAG, longOptions[optionIndex].name) == 0) { checkForUpdatesNow = YES; + } else if (strcmp(GRANT_AUTOMATIC_CHECKING_FLAG, longOptions[optionIndex].name) == 0) { + grantAutomaticChecking = YES; + } else if (strcmp(SEND_PROFILE_FLAG, longOptions[optionIndex].name) == 0) { + sendProfile = YES; } case ':': break; @@ -81,7 +92,12 @@ int main(int argc, char **argv) return EXIT_FAILURE; } - SUCommandLineDriver *driver = [[SUCommandLineDriver alloc] initWithUpdateBundlePath:updatePath applicationBundlePath:applicationPath deferInstallation:deferInstall verbose:verbose]; + SUUpdatePermissionPromptResult *updatePermission = nil; + if (grantAutomaticChecking) { + updatePermission = [SUUpdatePermissionPromptResult updatePermissionPromptResultWithChoice:SUAutomaticallyCheck shouldSendProfile:sendProfile]; + } + + SUCommandLineDriver *driver = [[SUCommandLineDriver alloc] initWithUpdateBundlePath:updatePath applicationBundlePath:applicationPath updatePermission:updatePermission deferInstallation:deferInstall verbose:verbose]; if (driver == nil) { fprintf(stderr, "Error: Failed to initialize updater. Are the bundle paths provided valid?\n"); printUsage(argv);