mirror of
https://github.com/sparkle-project/Sparkle
synced 2026-11-27 05:04:27 +00:00
Add --grant-automatic-checks and --send-profile flags
If an update permission request comes up, this alows us to make a decision. Also I renamed the defer and checknow flags to defer-install and check-immediately
This commit is contained in:
1 parent
235e93f0c1
commit
1356024b25
5 files changed
+41
-13
No files matched your search
@@ -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;
|
||||
|
||||
|
||||
@@ -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 <SUUserDriver> userDriver = [[SUCommandLineUserDriver alloc] initWithApplicationBundle:applicationBundle deferInstallation:deferInstallation verbose:verbose];
|
||||
id <SUUserDriver> userDriver = [[SUCommandLineUserDriver alloc] initWithApplicationBundle:applicationBundle updatePermission:updatePermission deferInstallation:deferInstallation verbose:verbose];
|
||||
_updater = [[SUUpdater alloc] initWithHostBundle:updateBundle userDriver:userDriver delegate:self];
|
||||
}
|
||||
return self;
|
||||
|
||||
@@ -13,7 +13,7 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface SUCommandLineUserDriver : NSObject <SUUserDriver>
|
||||
|
||||
- (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
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
+20
-4
@@ -7,17 +7,20 @@
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import <Sparkle/Sparkle.h>
|
||||
#import "SUCommandLineDriver.h"
|
||||
#include <getopt.h>
|
||||
|
||||
#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 <update-bundle-path> [--%s <path-to-application>] [--%s] [--%s] [--%s]\n", argv[0], APPLICATION_FLAG, CHECK_NOW_FLAG, DEFER_FLAG, VERBOSE_FLAG);
|
||||
fprintf(stderr, "Usage: %s <update-bundle-path> [--%s <path-to-application>] [--%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);
|
||||
|
||||
Reference in new issue
Block a user