Add checknow flag to check for updates immediately

What is new is that we can now disable checking for updates immediately.
sparkle-cli is not intended to be run for a long time, so if the next update check is not soon, we exit.
A client can now launch sparkle-cli without having to necessarily check for updates, so that they don't check for updates too soon.
This commit is contained in:
Zorg committed 2016-05-01 02:46:22 -04:00
1 parent 9bea84b29e
commit a4157e5989
4 files changed
+31 -10

No files matched your search

+1 -1
View File
@@ -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
+5 -3
View File
@@ -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]) {
+18 -4
View File
@@ -9,6 +9,8 @@
#import "SUCommandLineUserDriver.h"
#import <AppKit/AppKit.h>
#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);
});
+7 -2
View File
@@ -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 <update-bundle-path> [--%s <path-to-application>] [--%s] [--%s]\n", argv[0], APPLICATION_FLAG, DEFER_FLAG, VERBOSE_FLAG);
fprintf(stderr, "Usage: %s <update-bundle-path> [--%s <path-to-application>] [--%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];
}