diff --git a/Sparkle.xcodeproj/project.pbxproj b/Sparkle.xcodeproj/project.pbxproj index d420883a..bf45e535 100644 --- a/Sparkle.xcodeproj/project.pbxproj +++ b/Sparkle.xcodeproj/project.pbxproj @@ -165,6 +165,8 @@ 726E07691CA616A4001A286B /* libxar.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = 726E07681CA616A4001A286B /* libxar.tbd */; }; 726E076B1CA616B3001A286B /* libbz2.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = 726E076A1CA616B3001A286B /* libbz2.tbd */; }; 726E076D1CA66180001A286B /* SUBinaryDeltaUnarchiver.m in Sources */ = {isa = PBXBuildFile; fileRef = 5D06E9380FD69271005AE3F6 /* SUBinaryDeltaUnarchiver.m */; }; + 726E078D1CA891E9001A286B /* SUUpdaterSettings.h in Headers */ = {isa = PBXBuildFile; fileRef = 726E078B1CA891E9001A286B /* SUUpdaterSettings.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 726E078E1CA891E9001A286B /* SUUpdaterSettings.m in Sources */ = {isa = PBXBuildFile; fileRef = 726E078C1CA891E9001A286B /* SUUpdaterSettings.m */; }; 726E4A0E1C86881600C57C6A /* SUStandardUserDriverUIDelegate.h in Headers */ = {isa = PBXBuildFile; fileRef = 726E4A0D1C86881600C57C6A /* SUStandardUserDriverUIDelegate.h */; settings = {ATTRIBUTES = (Public, ); }; }; 726E4A101C86B5A200C57C6A /* SUStandardUserDriverRemoteDelegate.h in Headers */ = {isa = PBXBuildFile; fileRef = 726E4A0F1C86B5A200C57C6A /* SUStandardUserDriverRemoteDelegate.h */; settings = {ATTRIBUTES = (Public, ); }; }; 726E4A1B1C86C88F00C57C6A /* TestAppHelper.m in Sources */ = {isa = PBXBuildFile; fileRef = 726E4A1A1C86C88F00C57C6A /* TestAppHelper.m */; }; @@ -674,6 +676,8 @@ 726E07681CA616A4001A286B /* libxar.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = libxar.tbd; path = usr/lib/libxar.tbd; sourceTree = SDKROOT; }; 726E076A1CA616B3001A286B /* libbz2.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = libbz2.tbd; path = usr/lib/libbz2.tbd; sourceTree = SDKROOT; }; 726E076C1CA64B9C001A286B /* SUUnarchiverProtocol.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SUUnarchiverProtocol.h; sourceTree = ""; }; + 726E078B1CA891E9001A286B /* SUUpdaterSettings.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SUUpdaterSettings.h; sourceTree = ""; }; + 726E078C1CA891E9001A286B /* SUUpdaterSettings.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SUUpdaterSettings.m; sourceTree = ""; }; 726E4A0D1C86881600C57C6A /* SUStandardUserDriverUIDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SUStandardUserDriverUIDelegate.h; sourceTree = ""; }; 726E4A0F1C86B5A200C57C6A /* SUStandardUserDriverRemoteDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SUStandardUserDriverRemoteDelegate.h; sourceTree = ""; }; 726E4A111C86C44A00C57C6A /* Sparkle-Test-App.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.xml; path = "Sparkle-Test-App.entitlements"; sourceTree = ""; }; @@ -1224,6 +1228,8 @@ 61CFB2C20E38496B007A1735 /* Drivers */, 61B5F8E309C4CE3C00B25A18 /* SUUpdater.h */, 61B5F8E409C4CE3C00B25A18 /* SUUpdater.m */, + 726E078B1CA891E9001A286B /* SUUpdaterSettings.h */, + 726E078C1CA891E9001A286B /* SUUpdaterSettings.m */, 72A6F9891C94E2D6005F404C /* SUUpdaterDelegate.h */, ); name = "Update Control"; @@ -1346,6 +1352,7 @@ isa = PBXHeadersBuildPhase; buildActionMask = 2147483647; files = ( + 726E078D1CA891E9001A286B /* SUUpdaterSettings.h in Headers */, 72A6F98A1C94E2D6005F404C /* SUUpdaterDelegate.h in Headers */, 726E4A371C89116000C57C6A /* SUStandardUserDriverDelegate.h in Headers */, 726E4A0E1C86881600C57C6A /* SUStandardUserDriverUIDelegate.h in Headers */, @@ -1951,6 +1958,7 @@ 7297463C1C8FF6AE00FC134E /* SUCodeSigningVerifier.m in Sources */, 72B767E71C9CFD7200A07552 /* SUAutomaticUpdateDriver.m in Sources */, 61B5FBB709C4FAFF00B25A18 /* SUAppcast.m in Sources */, + 726E078E1CA891E9001A286B /* SUUpdaterSettings.m in Sources */, 7229E1BE1C98EFF200CB50D0 /* SUDownloadDriver.m in Sources */, 61B5FC6F09C51F4900B25A18 /* SUAppcastItem.m in Sources */, 72B767D71C9C8B5C00A07552 /* SUBasicUpdateDriver.m in Sources */, diff --git a/Sparkle/SUUpdater.h b/Sparkle/SUUpdater.h index 74f791b5..837d5aed 100644 --- a/Sparkle/SUUpdater.h +++ b/Sparkle/SUUpdater.h @@ -50,9 +50,9 @@ SU_EXPORT @interface SUUpdater : NSObject @property (readonly, strong) NSBundle *hostBundle; @property (strong, readonly) NSBundle *sparkleBundle; -@property BOOL automaticallyChecksForUpdates; +@property (nonatomic) BOOL automaticallyChecksForUpdates; -@property NSTimeInterval updateCheckInterval; +@property (nonatomic) NSTimeInterval updateCheckInterval; /*! * The URL of the appcast used to download update information. @@ -65,11 +65,11 @@ SU_EXPORT @interface SUUpdater : NSObject @property (copy) NSDictionary *httpHeaders; -@property BOOL sendsSystemProfile; +@property (nonatomic) BOOL sendsSystemProfile; @property (nonatomic, readonly) BOOL allowsAutomaticUpdates; -@property BOOL automaticallyDownloadsUpdates; +@property (nonatomic) BOOL automaticallyDownloadsUpdates; /*! Checks for updates, and displays progress while doing so diff --git a/Sparkle/SUUpdater.m b/Sparkle/SUUpdater.m index b5f65317..f88bc480 100644 --- a/Sparkle/SUUpdater.m +++ b/Sparkle/SUUpdater.m @@ -8,6 +8,7 @@ #import "SUUpdater.h" #import "SUUpdaterDelegate.h" +#import "SUUpdaterSettings.h" #import "SUHost.h" #import "SUUpdatePermissionPromptResult.h" #import "SUUpdateDriver.h" @@ -41,6 +42,7 @@ NSString *const SUUpdaterAppcastNotificationKey = @"SUUpdaterAppCastNotification @property (strong) id driver; @property (strong) SUHost *host; +@property (nonatomic, readonly) SUUpdaterSettings *updaterSettings; @end @@ -52,6 +54,7 @@ NSString *const SUUpdaterAppcastNotificationKey = @"SUUpdaterAppCastNotification @synthesize httpHeaders; @synthesize driver; @synthesize host; +@synthesize updaterSettings = _updaterSettings; @synthesize sparkleBundle; - (instancetype)initWithHostBundle:(NSBundle *)bundle userDriver:(id )userDriver delegate:(id )theDelegate @@ -68,6 +71,8 @@ NSString *const SUUpdaterAppcastNotificationKey = @"SUUpdaterAppCastNotification host = [[SUHost alloc] initWithBundle:bundle]; + _updaterSettings = [[SUUpdaterSettings alloc] initWithHostBundle:bundle]; + _userDriver = userDriver; delegate = theDelegate; @@ -425,11 +430,7 @@ static void SUCheckForUpdatesInBgReachabilityCheck(__weak SUUpdater *updater, id - (BOOL)automaticallyChecksForUpdates { - // Don't automatically update when the check interval is 0, to be compatible with 1.1 settings. - if ((NSInteger)[self updateCheckInterval] == 0) { - return NO; - } - return [self.host boolForKey:SUEnableAutomaticChecksKey]; + return [self.updaterSettings automaticallyChecksForUpdates]; } - (void)setAutomaticallyDownloadsUpdates:(BOOL)automaticallyUpdates @@ -439,7 +440,7 @@ static void SUCheckForUpdatesInBgReachabilityCheck(__weak SUUpdater *updater, id - (BOOL)automaticallyDownloadsUpdates { - return [self.host boolForUserDefaultsKey:SUAutomaticallyUpdateKey]; + return [self.updaterSettings automaticallyDownloadsUpdates]; } - (BOOL)allowsAutomaticUpdates @@ -494,7 +495,7 @@ static void SUCheckForUpdatesInBgReachabilityCheck(__weak SUUpdater *updater, id - (BOOL)sendsSystemProfile { - return [self.host boolForKey:SUSendProfileInfoKey]; + return [self.updaterSettings sendsSystemProfile]; } - (NSURL *)parameterizedFeedURL @@ -554,12 +555,7 @@ static void SUCheckForUpdatesInBgReachabilityCheck(__weak SUUpdater *updater, id - (NSTimeInterval)updateCheckInterval { - // Find the stored check interval. User defaults override Info.plist. - NSNumber *intervalValue = [self.host objectForKey:SUScheduledCheckIntervalKey]; - if (intervalValue) - return [intervalValue doubleValue]; - else - return SUDefaultUpdateCheckInterval; + return [self.updaterSettings updateCheckInterval]; } // This may not return the same update check interval as the developer has configured diff --git a/Sparkle/SUUpdaterSettings.h b/Sparkle/SUUpdaterSettings.h new file mode 100644 index 00000000..0394572b --- /dev/null +++ b/Sparkle/SUUpdaterSettings.h @@ -0,0 +1,48 @@ +// +// SUUpdaterSettings.h +// Sparkle +// +// Created by Mayur Pawashe on 3/27/16. +// Copyright © 2016 Sparkle Project. All rights reserved. +// + +#import + +NS_ASSUME_NONNULL_BEGIN + +/*! + This class can be used for reading certain updater settings. + + It retrieves the settings by first looking into the host's user defaults. + If the setting is not found in there, then the host's Info.plist file is looked at. + */ +@interface SUUpdaterSettings : NSObject + +- (instancetype)initWithHostBundle:(NSBundle *)hostBundle; + +/*! + * Indicates whether or not automatic update checks are enabled. + */ +@property (readonly, nonatomic) BOOL automaticallyChecksForUpdates; + +/*! + * The regular update check interval. + */ +@property (readonly, nonatomic) NSTimeInterval updateCheckInterval; + +/*! + * Indicates whether or not automatically downloading updates is enabled by the user or developer. + * + * Note this does not indicate whether or not automatic downloading of updates is allowable. + * See SUUpdater to retrieve that information. + */ +@property (readonly, nonatomic) BOOL automaticallyDownloadsUpdates; + +/*! + * Indicates whether or not anonymous system profile information is sent when checking for updates. + */ +@property (readonly, nonatomic) BOOL sendsSystemProfile; + +@end + +NS_ASSUME_NONNULL_END diff --git a/Sparkle/SUUpdaterSettings.m b/Sparkle/SUUpdaterSettings.m new file mode 100644 index 00000000..b13a6c40 --- /dev/null +++ b/Sparkle/SUUpdaterSettings.m @@ -0,0 +1,65 @@ +// +// SUUpdaterSettings.m +// Sparkle +// +// Created by Mayur Pawashe on 3/27/16. +// Copyright © 2016 Sparkle Project. All rights reserved. +// + +#import "SUUpdaterSettings.h" +#import "SUHost.h" +#import "SUConstants.h" + +#ifdef _APPKITDEFINES_H +#error This is a "core" class and should NOT import AppKit +#endif + +@interface SUUpdaterSettings () + +@property (nonatomic, readonly) SUHost *host; + +@end + +@implementation SUUpdaterSettings + +@synthesize host = _host; + +- (instancetype)initWithHostBundle:(NSBundle *)hostBundle +{ + self = [super init]; + if (self != nil) { + _host = [[SUHost alloc] initWithBundle:hostBundle]; + } + return self; +} + +- (BOOL)automaticallyChecksForUpdates +{ + // Don't automatically update when the check interval is 0, to be compatible with 1.1 settings. + if ((NSInteger)[self updateCheckInterval] == 0) { + return NO; + } + return [self.host boolForKey:SUEnableAutomaticChecksKey]; +} + +- (NSTimeInterval)updateCheckInterval +{ + // Find the stored check interval. User defaults override Info.plist. + NSNumber *intervalValue = [self.host objectForKey:SUScheduledCheckIntervalKey]; + if (intervalValue) + return [intervalValue doubleValue]; + else + return SUDefaultUpdateCheckInterval; +} + +- (BOOL)automaticallyDownloadsUpdates +{ + return [self.host boolForUserDefaultsKey:SUAutomaticallyUpdateKey]; +} + +- (BOOL)sendsSystemProfile +{ + return [self.host boolForKey:SUSendProfileInfoKey]; +} + +@end diff --git a/Sparkle/Sparkle.h b/Sparkle/Sparkle.h index 1aaa9886..e982e494 100644 --- a/Sparkle/Sparkle.h +++ b/Sparkle/Sparkle.h @@ -17,6 +17,7 @@ #import "SUStandardVersionComparator.h" #import "SUUpdaterDelegate.h" #import "SUUpdater.h" +#import "SUUpdaterSettings.h" #import "SUStandardUpdaterController.h" #import "SUVersionComparisonProtocol.h" #import "SUVersionDisplayProtocol.h" diff --git a/TestAppHelper/TestAppHelper.m b/TestAppHelper/TestAppHelper.m index 2be9bab3..cfd35e4f 100644 --- a/TestAppHelper/TestAppHelper.m +++ b/TestAppHelper/TestAppHelper.m @@ -69,14 +69,6 @@ }); } -- (void)retrieveUpdateSettings:(void (^)(BOOL automaticallyCheckForUpdates, BOOL automaticallyDownloadUpdates, BOOL sendSystemProfile, NSTimeInterval updateCheckInterval))reply -{ - dispatch_async(dispatch_get_main_queue(), ^{ - [self startSparkleIfNeeded]; - reply(self.updater.automaticallyChecksForUpdates, self.updater.automaticallyDownloadsUpdates, self.updater.sendsSystemProfile, self.updater.updateCheckInterval); - }); -} - - (void)setAutomaticallyChecksForUpdates:(BOOL)automaticallyChecksForUpdates { dispatch_async(dispatch_get_main_queue(), ^{ diff --git a/TestAppHelper/TestAppHelperProtocol.h b/TestAppHelper/TestAppHelperProtocol.h index d2e2e4c8..fa96cac4 100644 --- a/TestAppHelper/TestAppHelperProtocol.h +++ b/TestAppHelper/TestAppHelperProtocol.h @@ -22,8 +22,6 @@ // Check for updates, only bringing a prompt when an update is available and not skipped - (void)checkForUpdates; -- (void)retrieveUpdateSettings:(void (^)(BOOL automaticallyCheckForUpdates, BOOL automaticallyDownloadUpdates, BOOL sendSystemProfile, NSTimeInterval updateCheckInterval))reply; - - (void)setAutomaticallyChecksForUpdates:(BOOL)automaticallyChecksForUpdates; - (void)setAutomaticallyDownloadsUpdates:(BOOL)automaticallyDownloadsUpdates; - (void)setSendsSystemProfile:(BOOL)sendsSystemProfile; diff --git a/TestApplication/SURemoteUpdateSettingsWindowController.m b/TestApplication/SURemoteUpdateSettingsWindowController.m index 3972b9b5..1d8398f0 100644 --- a/TestApplication/SURemoteUpdateSettingsWindowController.m +++ b/TestApplication/SURemoteUpdateSettingsWindowController.m @@ -53,6 +53,24 @@ return NSStringFromClass([self class]); } +- (void)reloadSettings +{ + SUUpdaterSettings *settings = [[SUUpdaterSettings alloc] initWithHostBundle:[NSBundle mainBundle]]; + + // Make sure window is loaded + [self window]; + + self.automaticallyChecksForUpdatesButton.state = settings.automaticallyChecksForUpdates ? NSOnState : NSOffState; + self.automaticallyDownloadUpdatesButton.state = settings.automaticallyDownloadsUpdates ? NSOnState : NSOffState; + self.sendsSystemProfileButton.state = settings.sendsSystemProfile ? NSOnState : NSOffState; + self.updateCheckIntervalTextField.doubleValue = settings.updateCheckInterval; +} + +- (void)windowDidLoad +{ + [self reloadSettings]; +} + - (void)setUpConnection { self.connection = [[NSXPCConnection alloc] initWithServiceName:@"org.sparkle-project.TestAppHelper"]; @@ -113,6 +131,7 @@ NSLog(@"Rebooting connection.."); if (weakSelf != nil && weakSelf.connection == nil) { [weakSelf setUpConnection]; + [weakSelf reloadSettings]; } }); }); @@ -121,27 +140,6 @@ [self.connection resume]; [self.connection.remoteObjectProxy startSparkle]; - - // Retrieving the settings really takes a while, perhaps a smarter app may also store defaults locally and sync them - [self.connection.remoteObjectProxy retrieveUpdateSettings:^(BOOL automaticallyCheckForUpdates, BOOL automaticallyDownloadUpdates, BOOL sendSystemProfile, NSTimeInterval updateCheckInterval) { - dispatch_async(dispatch_get_main_queue(), ^{ - SURemoteUpdateSettingsWindowController *strongSelf = weakSelf; - if (strongSelf != nil) { - // Load the window before referencing our outlets - [strongSelf window]; - - strongSelf.automaticallyChecksForUpdatesButton.state = automaticallyCheckForUpdates ? NSOnState : NSOffState; - strongSelf.automaticallyDownloadUpdatesButton.state = automaticallyDownloadUpdates ? NSOnState : NSOffState; - strongSelf.sendsSystemProfileButton.state = sendSystemProfile ? NSOnState : NSOffState; - strongSelf.updateCheckIntervalTextField.doubleValue = updateCheckInterval; - - // Ready to show our window - if (!strongSelf.window.isVisible) { - [strongSelf showWindow:nil]; - } - } - }); - }]; } #pragma mark UI Actions diff --git a/TestApplication/SUTestApplicationDelegate.m b/TestApplication/SUTestApplicationDelegate.m index 29277cac..70739f6a 100644 --- a/TestApplication/SUTestApplicationDelegate.m +++ b/TestApplication/SUTestApplicationDelegate.m @@ -15,8 +15,7 @@ @interface SUTestApplicationDelegate () -@property (nonatomic) SUUpdateSettingsWindowController *updateSettingsWindowController; -@property (nonatomic) SURemoteUpdateSettingsWindowController *remoteUpdateSettingsWindowController; +@property (nonatomic) NSWindowController *updateSettingsWindowController; @property (nonatomic) SUTestWebServer *webServer; @end @@ -24,7 +23,6 @@ @implementation SUTestApplicationDelegate @synthesize updateSettingsWindowController = _updateSettingsWindowController; -@synthesize remoteUpdateSettingsWindowController = _remoteUpdateSettingsWindowController; @synthesize webServer = _webServer; static NSString * const UPDATED_VERSION = @"2.0"; @@ -205,12 +203,10 @@ static NSString * const UPDATED_VERSION = @"2.0"; self.webServer = webServer; // Show the Settings window - - // SURemoteUpdateSettingsWindowController will show its window by itself - self.remoteUpdateSettingsWindowController = [[SURemoteUpdateSettingsWindowController alloc] init]; - + self.updateSettingsWindowController = [[SURemoteUpdateSettingsWindowController alloc] init]; //self.updateSettingsWindowController = [[SUUpdateSettingsWindowController alloc] init]; - //[self.updateSettingsWindowController showWindow:nil]; + + [self.updateSettingsWindowController showWindow:nil]; }); }]; }