diff --git a/sparkle-cli/SUCommandLineDriver.h b/sparkle-cli/SUCommandLineDriver.h index 675c6963..c05e120d 100644 --- a/sparkle-cli/SUCommandLineDriver.h +++ b/sparkle-cli/SUCommandLineDriver.h @@ -14,7 +14,7 @@ NS_ASSUME_NONNULL_BEGIN - (nullable instancetype)initWithUpdateBundlePath:(NSString *)updateBundlePath applicationBundlePath:(nullable NSString *)applicationBundlePath deferInstallation:(BOOL)deferInstallation verbose:(BOOL)verbose; -- (void)run; +- (void)runAndCheckForUpdatesNow:(BOOL)checkForUpdatesNow; @end diff --git a/sparkle-cli/SUCommandLineDriver.m b/sparkle-cli/SUCommandLineDriver.m index 11ab496f..60bc983a 100644 --- a/sparkle-cli/SUCommandLineDriver.m +++ b/sparkle-cli/SUCommandLineDriver.m @@ -59,10 +59,12 @@ return self.applicationBundlePath; } -- (void)run +- (void)runAndCheckForUpdatesNow:(BOOL)checkForUpdatesNow { - // Kick off a scheduled update check once we start the updater later - [self.updater checkForUpdates]; + if (checkForUpdatesNow) { + // When we start the updater, this scheduled check will start afterwards too + [self.updater checkForUpdates]; + } NSError *updaterError = nil; if (![self.updater startUpdater:&updaterError]) { diff --git a/sparkle-cli/SUCommandLineUserDriver.m b/sparkle-cli/SUCommandLineUserDriver.m index 615dda13..c5d579d0 100644 --- a/sparkle-cli/SUCommandLineUserDriver.m +++ b/sparkle-cli/SUCommandLineUserDriver.m @@ -9,6 +9,8 @@ #import "SUCommandLineUserDriver.h" #import +#define SCHEDULED_UPDATE_TIMER_THRESHOLD 2.0 // seconds + @interface SUCommandLineUserDriver () @property (nonatomic, readonly) NSBundle *applicationBundle; @@ -51,6 +53,11 @@ - (void)idleOnUpdateChecks:(BOOL)shouldIdleOnUpdateChecks { dispatch_async(dispatch_get_main_queue(), ^{ + if (shouldIdleOnUpdateChecks) { + fprintf(stderr, "Error: Automatic update checking has been disabled.\n"); + exit(EXIT_FAILURE); + } + [self.coreComponent idleOnUpdateChecks:shouldIdleOnUpdateChecks]; }); } @@ -58,7 +65,14 @@ - (void)startUpdateCheckTimerWithNextTimeInterval:(NSTimeInterval)timeInterval reply:(void (^)(SUUpdateCheckTimerStatus))reply { dispatch_async(dispatch_get_main_queue(), ^{ - [self.coreComponent startUpdateCheckTimerWithNextTimeInterval:timeInterval reply:reply]; + if (timeInterval > SCHEDULED_UPDATE_TIMER_THRESHOLD) { + if (self.verbose) { + fprintf(stderr, "Too early to check for new updates. Next check is in %f seconds. Exiting.\n", timeInterval); + } + exit(EXIT_SUCCESS); + } else { + [self.coreComponent startUpdateCheckTimerWithNextTimeInterval:timeInterval reply:reply]; + } }); } @@ -73,8 +87,8 @@ { 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, "Asked about making update permission decision.. Aborting because this decision should not be made.\n"); - abort(); + fprintf(stderr, "Error: Asked about making update permission decision. Aborting because this decision should not be made.\n"); + exit(EXIT_FAILURE); }); } @@ -215,7 +229,7 @@ { dispatch_async(dispatch_get_main_queue(), ^{ if (self.verbose) { - fprintf(stderr, "Exiting...\n"); + fprintf(stderr, "Exiting.\n"); } exit(EXIT_SUCCESS); }); diff --git a/sparkle-cli/main.m b/sparkle-cli/main.m index 9a6ce016..dd62d940 100644 --- a/sparkle-cli/main.m +++ b/sparkle-cli/main.m @@ -13,10 +13,11 @@ #define APPLICATION_FLAG "application" #define DEFER_FLAG "defer" #define VERBOSE_FLAG "verbose" +#define CHECK_NOW_FLAG "checknow" static void printUsage(char **argv) { - fprintf(stderr, "Usage: %s [--%s ] [--%s] [--%s]\n", argv[0], APPLICATION_FLAG, DEFER_FLAG, VERBOSE_FLAG); + fprintf(stderr, "Usage: %s [--%s ] [--%s] [--%s] [--%s]\n", argv[0], APPLICATION_FLAG, CHECK_NOW_FLAG, DEFER_FLAG, VERBOSE_FLAG); } int main(int argc, char **argv) @@ -27,12 +28,14 @@ int main(int argc, char **argv) {APPLICATION_FLAG, required_argument, NULL, 0}, {DEFER_FLAG, no_argument, NULL, 0}, {VERBOSE_FLAG, no_argument, NULL, 0}, + {CHECK_NOW_FLAG, no_argument, NULL, 0}, {0, 0, 0, 0} }; NSString *applicationPath = nil; BOOL deferInstall = NO; BOOL verbose = NO; + BOOL checkForUpdatesNow = NO; while (YES) { int optionIndex = 0; @@ -54,6 +57,8 @@ int main(int argc, char **argv) deferInstall = YES; } else if (strcmp(VERBOSE_FLAG, longOptions[optionIndex].name) == 0) { verbose = YES; + } else if (strcmp(CHECK_NOW_FLAG, longOptions[optionIndex].name) == 0) { + checkForUpdatesNow = YES; } case ':': break; @@ -82,7 +87,7 @@ int main(int argc, char **argv) return EXIT_FAILURE; } - [driver run]; + [driver runAndCheckForUpdatesNow:checkForUpdatesNow]; [[NSRunLoop currentRunLoop] run]; }