Remove/modernize a bunch of cruft

Yeah, this isn't backwards compatible with older code that uses Sparkle

Few notes:
* Mostly everything from *.pch has been moved out for saner dependency tracking
* 10.7 compatibility has been removed out so I don't import Cocoa when I don't have to
* sharedUpdaters/SUUpdater singletons has been removed out so updaters can actually be deallocated properly
 (and since singletons are generally horrible idea anyway)
* SUUpdater doesn't have UI/cocoa/bindings/menu validation code. Its new initializer method takes a user driver
 (perhaps in the future I'll create another class that "binds" the UI and core)
This commit is contained in:
Zorg committed 2016-02-28 01:39:15 -05:00
1 parent b5a1826a47
commit f630188255
27 files changed
+110 -175

No files matched your search

+8
View File
@@ -171,6 +171,8 @@
720B16441C66433D006985FB /* UITests-Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = 720B16421C66433D006985FB /* UITests-Info.plist */; };
720B16451C66433D006985FB /* SUTestApplicationTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 720B16431C66433D006985FB /* SUTestApplicationTest.swift */; };
7210C7681B9A9A1500EB90AC /* SUUnarchiverTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7210C7671B9A9A1500EB90AC /* SUUnarchiverTest.swift */; };
72162B061C82C8B30013C1C5 /* SUParameterAssert.h in Headers */ = {isa = PBXBuildFile; fileRef = 72162B051C82C8B30013C1C5 /* SUParameterAssert.h */; };
72162B081C82C9600013C1C5 /* SULocalizations.h in Headers */ = {isa = PBXBuildFile; fileRef = 72162B071C82C9600013C1C5 /* SULocalizations.h */; };
721CF1A71AD7643600D9AC09 /* bsdiff.c in Sources */ = {isa = PBXBuildFile; fileRef = 5D06E8DB0FD68CB9005AE3F6 /* bsdiff.c */; settings = {COMPILER_FLAGS = "-w"; }; };
721CF1A81AD7644100D9AC09 /* bspatch.c in Sources */ = {isa = PBXBuildFile; fileRef = 5D06E8DC0FD68CB9005AE3F6 /* bspatch.c */; settings = {COMPILER_FLAGS = "-w"; }; };
721CF1A91AD7644C00D9AC09 /* sais.c in Sources */ = {isa = PBXBuildFile; fileRef = 7223E7611AD1AEFF008E3161 /* sais.c */; settings = {COMPILER_FLAGS = "-w"; }; };
@@ -633,6 +635,8 @@
720B16421C66433D006985FB /* UITests-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = "UITests-Info.plist"; path = "UITests/UITests-Info.plist"; sourceTree = SOURCE_ROOT; };
720B16431C66433D006985FB /* SUTestApplicationTest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = SUTestApplicationTest.swift; path = UITests/SUTestApplicationTest.swift; sourceTree = SOURCE_ROOT; };
7210C7671B9A9A1500EB90AC /* SUUnarchiverTest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SUUnarchiverTest.swift; sourceTree = "<group>"; };
72162B051C82C8B30013C1C5 /* SUParameterAssert.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SUParameterAssert.h; sourceTree = "<group>"; };
72162B071C82C9600013C1C5 /* SULocalizations.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SULocalizations.h; sourceTree = "<group>"; };
7223E7611AD1AEFF008E3161 /* sais.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = sais.c; sourceTree = "<group>"; };
7223E7621AD1AEFF008E3161 /* sais.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = sais.h; sourceTree = "<group>"; };
725CB9561C7120410064365A /* SUUserUpdaterDriver.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SUUserUpdaterDriver.h; sourceTree = "<group>"; };
@@ -1051,6 +1055,8 @@
children = (
61299B3509CB04E000B7442F /* Sparkle.h */,
61CFB3280E385186007A1735 /* Sparkle.pch */,
72162B071C82C9600013C1C5 /* SULocalizations.h */,
72162B051C82C8B30013C1C5 /* SUParameterAssert.h */,
61299A5B09CA6D4500B7442F /* SUConstants.h */,
61299A5F09CA6EB100B7442F /* SUConstants.m */,
55E6F33219EC9F6C00005E76 /* SUErrors.h */,
@@ -1189,12 +1195,14 @@
725CB95A1C7121830064365A /* SUSparkleUserUpdaterDriver.h in Headers */,
61EF67590E25C5B400F754E0 /* SUHost.h in Headers */,
725CB9571C7120410064365A /* SUUserUpdaterDriver.h in Headers */,
72162B061C82C8B30013C1C5 /* SUParameterAssert.h in Headers */,
72A450561C6FC10400D67EEA /* SUUpdateAlertChoice.h in Headers */,
72A450531C69A68900D67EEA /* SUUpdatePermissionPromptResult.h in Headers */,
611142E910FB1BE5009810AA /* bspatch.h in Headers */,
6160E7E10D3B4A8800E9CD71 /* NTSynchronousTask.h in Headers */,
61299B3609CB04E000B7442F /* Sparkle.h in Headers */,
61CFB3290E385186007A1735 /* Sparkle.pch in Headers */,
72162B081C82C9600013C1C5 /* SULocalizations.h in Headers */,
61B5FC0D09C4FC8200B25A18 /* SUAppcast.h in Headers */,
61B5FC7009C51F4A00B25A18 /* SUAppcastItem.h in Headers */,
6120721209CC5C4B007FE0F6 /* SUAutomaticUpdateAlert.h in Headers */,
+1
View File
@@ -4,6 +4,7 @@
#import "SUStandardVersionComparator.h"
#import "SUStatusController.h"
#import "SULog.h"
#import "SULocalizations.h"
#include <unistd.h>
+2
View File
@@ -14,6 +14,8 @@
#import "SUAppcast.h"
#import "SUConstants.h"
#import "SULog.h"
#import "SUErrors.h"
#import "SULocalizations.h"
@interface NSXMLElement (SUAppcastExtensions)
@property (readonly, copy) NSDictionary *attributesAsDictionary;
+1
View File
@@ -13,6 +13,7 @@
#import "SUVersionComparisonProtocol.h"
#import "SUAppcastItem.h"
#import "SULog.h"
#import "SUConstants.h"
@interface SUAppcastItem ()
@property (copy, readwrite) NSString *title;
+1
View File
@@ -9,6 +9,7 @@
#import "SUAutomaticUpdateAlert.h"
#import "SUHost.h"
#import "SULocalizations.h"
@interface SUAutomaticUpdateAlert ()
@property (strong) void(^completionBlock)(SUAutomaticInstallationChoice);
+2 -1
View File
@@ -7,10 +7,11 @@
//
#import "SUAutomaticUpdateDriver.h"
#import "SULocalizations.h"
#import "SUUpdater.h"
#import "SUHost.h"
#import "SUConstants.h"
#import "SUErrors.h"
// If the user hasn't quit in a week, ask them if they want to relaunch to get the latest bits. It doesn't matter that this measure of "one day" is imprecise.
static const NSTimeInterval SUAutomaticUpdatePromptImpatienceTimer = 60 * 60 * 24 * 7;
+2
View File
@@ -20,6 +20,8 @@
#import "SUCodeSigningVerifier.h"
#import "SUUpdater_Private.h"
#import "SUFileManager.h"
#import "SUErrors.h"
#import "SULocalizations.h"
@interface SUBasicUpdateDriver ()
+2
View File
@@ -9,6 +9,8 @@
#ifndef SUBINARYDELTAAPPLY_H
#define SUBINARYDELTAAPPLY_H
#import <Foundation/Foundation.h>
@class NSString;
BOOL applyBinaryDelta(NSString *source, NSString *destination, NSString *patchFile, BOOL verbose, NSError * __autoreleasing *error);
-1
View File
@@ -12,7 +12,6 @@
#import "SUUnarchiver_Private.h"
#import "SUHost.h"
#import "SULog.h"
#import "NTSynchronousTask.h"
@implementation SUBinaryDeltaUnarchiver
+1
View File
@@ -12,6 +12,7 @@
#import "SUAppcastItem.h"
#import "SUVersionComparisonProtocol.h"
#import "SUConstants.h"
#import "SUErrors.h"
#ifndef DEBUG
#define DEBUG 0
+7 -34
View File
@@ -7,7 +7,8 @@
//
#import "SUFileManager.h"
#import "SUOperatingSystem.h"
#import <Foundation/Foundation.h>
#import "SUErrors.h"
#include <sys/xattr.h>
#include <sys/errno.h>
@@ -841,21 +842,7 @@ static BOOL SUMakeRefFromURL(NSURL *url, FSRef *ref, NSError **error) {
return NO;
}
NSURL *trashURL = nil;
BOOL canUseNewTrashAPI = YES;
#if __MAC_OS_X_VERSION_MIN_REQUIRED < 1080
canUseNewTrashAPI = [SUOperatingSystem isOperatingSystemAtLeastVersion:(NSOperatingSystemVersion){10, 8, 0}];
if (!canUseNewTrashAPI) {
FSRef trashRef;
if (FSFindFolder(kUserDomain, kTrashFolderType, kDontCreateFolder, &trashRef) == noErr) {
trashURL = CFBridgingRelease(CFURLCreateFromFSRef(kCFAllocatorDefault, &trashRef));
}
}
#endif
if (canUseNewTrashAPI) {
trashURL = [_fileManager URLForDirectory:NSTrashDirectory inDomain:NSUserDomainMask appropriateForURL:nil create:NO error:nil];
}
NSURL *trashURL = [_fileManager URLForDirectory:NSTrashDirectory inDomain:NSUserDomainMask appropriateForURL:nil create:NO error:nil];
if (trashURL == nil) {
if (error != NULL) {
@@ -889,24 +876,10 @@ static BOOL SUMakeRefFromURL(NSURL *url, FSRef *ref, NSError **error) {
}
// If we get here, we should be able to trash the item normally without authentication
BOOL success = NO;
#if __MAC_OS_X_VERSION_MIN_REQUIRED < 1080
if (!canUseNewTrashAPI) {
NSString *tempParentPath = tempItemURL.URLByDeletingLastPathComponent.path;
success = [[NSWorkspace sharedWorkspace] performFileOperation:NSWorkspaceRecycleOperation source:tempParentPath destination:@"" files:@[tempItemURL.lastPathComponent] tag:NULL];
if (!success && error != NULL) {
*error = [NSError errorWithDomain:NSCocoaErrorDomain code:NSFileNoSuchFileError userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Failed to move file %@ into the trash.", tempItemURL.lastPathComponent] }];
}
}
#endif
if (canUseNewTrashAPI) {
NSError *trashError = nil;
success = [_fileManager trashItemAtURL:tempItemURL resultingItemURL:NULL error:&trashError];
if (!success && error != NULL) {
*error = trashError;
}
NSError *trashError = nil;
BOOL success = [_fileManager trashItemAtURL:tempItemURL resultingItemURL:NULL error:&trashError];
if (!success && error != NULL) {
*error = trashError;
}
[self removeItemAtURL:tempDirectory error:NULL];
+1 -1
View File
@@ -8,7 +8,7 @@
#import <sys/stat.h>
#import <Security/Security.h>
#import "SUParameterAssert.h"
#import "SUGuidedPackageInstaller.h"
static BOOL AuthorizationExecuteWithPrivilegesAndWait(AuthorizationRef authorization, const char* executablePath, AuthorizationFlags options, char* const* arguments)
+1
View File
@@ -11,6 +11,7 @@
#import "SUSystemProfiler.h"
#include <sys/mount.h> // For statfs for isRunningOnReadOnlyVolume
#import "SULog.h"
#import "SUParameterAssert.h"
@interface SUHost ()
+1
View File
@@ -13,6 +13,7 @@
#import "SUHost.h"
#import "SUConstants.h"
#import "SULog.h"
#import "SUParameterAssert.h"
@implementation SUInstaller
+16
View File
@@ -0,0 +1,16 @@
//
// SULocalizations.h
// Sparkle
//
// Created by Mayur Pawashe on 2/28/16.
// Copyright © 2016 Sparkle Project. All rights reserved.
//
#ifndef SULocalizations_h
#define SULocalizations_h
#import "SUConstants.h"
#define SULocalizedString(key, comment) NSLocalizedStringFromTableInBundle(key, @"Sparkle", (NSBundle *__nonnull)([NSBundle bundleWithIdentifier:SUBundleIdentifier] ? [NSBundle bundleWithIdentifier:SUBundleIdentifier] : [NSBundle mainBundle]), comment)
#endif /* SULocalizations_h */
+1
View File
@@ -9,6 +9,7 @@
#import "SUPackageInstaller.h"
#import <Cocoa/Cocoa.h>
#import "SUConstants.h"
#import "SUErrors.h"
@implementation SUPackageInstaller
+17
View File
@@ -0,0 +1,17 @@
//
// SUParameterAssert.h
// Sparkle
//
// Created by Mayur Pawashe on 2/28/16.
// Copyright © 2016 Sparkle Project. All rights reserved.
//
#ifndef SUParameterAssert_h
#define SUParameterAssert_h
// Work around a warning generated by some versions of Xcode that we still support,
// when using NSParameterAssert
#define SUParameterAssert(condition) \
NSAssert((condition), @"Invalid parameter not satisfying: %@", @(#condition))
#endif /* SUParameterAssert_h */
+2
View File
@@ -12,6 +12,8 @@
#import "SUConstants.h"
#import "SUHost.h"
#import "SULog.h"
#import "SUErrors.h"
#import "SUParameterAssert.h"
@implementation SUPlainInstaller
+1
View File
@@ -15,6 +15,7 @@
#import "SUUpdateAlert.h"
#import "SUAutomaticUpdateAlert.h"
#import "SUOperatingSystem.h"
#import "SULocalizations.h"
#if __MAC_OS_X_VERSION_MAX_ALLOWED < 1080
@interface NSByteCountFormatter : NSFormatter {
+1
View File
@@ -13,6 +13,7 @@
#import "SUVersionComparisonProtocol.h"
#import "SUStatusController.h"
#import "SUHost.h"
#import "SULocalizations.h"
@interface SUStatusController ()
@property (copy) NSString *title, *buttonTitle;
+1
View File
@@ -17,6 +17,7 @@
#import "SUConstants.h"
#import "SULog.h"
#import "SULocalizations.h"
// WebKit protocols are not explicitly declared until 10.11 SDK, so
// declare dummy protocols to keep the build working on earlier SDKs.
+1
View File
@@ -8,6 +8,7 @@
#import "SUUpdatePermissionPrompt.h"
#import "SUUpdatePermissionPromptResult.h"
#import "SULocalizations.h"
#import "SUHost.h"
#import "SUConstants.h"
+2 -4
View File
@@ -29,11 +29,9 @@
SU_EXPORT @interface SUUpdater : NSObject
@property (unsafe_unretained) IBOutlet id<SUUpdaterDelegate> delegate;
@property (nonatomic) id<SUUserUpdaterDriver> userUpdaterDriver;
@property (nonatomic, readonly) id<SUUserUpdaterDriver> userUpdaterDriver;
+ (SUUpdater *)sharedUpdater;
+ (SUUpdater *)updaterForBundle:(NSBundle *)bundle;
- (instancetype)initForBundle:(NSBundle *)bundle;
- (instancetype)initWithHostBundle:(NSBundle *)bundle userUpdaterDriver:(id <SUUserUpdaterDriver>)userUpdaterDriver;
@property (readonly, strong) NSBundle *hostBundle;
@property (strong, readonly) NSBundle *sparkleBundle;
+35 -122
View File
@@ -33,12 +33,9 @@ NSString *const SUUpdaterAppcastNotificationKey = @"SUUpdaterAppCastNotification
@interface SUUpdater ()
@property (strong) NSBundle *sparkleBundle;
- (instancetype)initForBundle:(NSBundle *)bundle;
- (void)startUpdateCycle;
- (void)checkForUpdatesWithDriver:(SUUpdateDriver *)updateDriver;
- (void)scheduleNextUpdateCheck;
- (void)registerAsObserver;
- (void)unregisterAsObserver;
- (void)updateDriverDidFinish:(NSNotification *)note;
@property (readonly, copy) NSURL *parameterizedFeedURL;
@@ -58,30 +55,9 @@ NSString *const SUUpdaterAppcastNotificationKey = @"SUUpdaterAppCastNotification
@synthesize sparkleBundle;
@synthesize decryptionPassword;
static NSMutableDictionary *sharedUpdaters = nil;
static NSString *const SUUpdaterDefaultsObservationContext = @"SUUpdaterDefaultsObservationContext";
+ (SUUpdater *)sharedUpdater
{
return [self updaterForBundle:[NSBundle mainBundle]];
}
// SUUpdater has a singleton for each bundle. We use the fact that NSBundle instances are also singletons, so we can use them as keys. If you don't trust that you can also use the identifier as key
+ (SUUpdater *)updaterForBundle:(NSBundle *)bundle
{
if (bundle == nil) bundle = [NSBundle mainBundle];
id updater = sharedUpdaters[[NSValue valueWithNonretainedObject:bundle]];
if (updater == nil) {
updater = [[[self class] alloc] initForBundle:bundle];
}
return updater;
}
// This is the designated initializer for SUUpdater, important for subclasses
- (instancetype)initForBundle:(NSBundle *)bundle
- (instancetype)initWithHostBundle:(NSBundle *)bundle userUpdaterDriver:(id <SUUserUpdaterDriver>)userUpdaterDriver
{
self = [super init];
if (bundle == nil) bundle = [NSBundle mainBundle];
// Use explicit class to use the correct bundle even when subclassed
self.sparkleBundle = [NSBundle bundleForClass:[SUUpdater class]];
@@ -90,29 +66,13 @@ static NSString *const SUUpdaterDefaultsObservationContext = @"SUUpdaterDefaults
return nil;
}
// Register as observer straight away to avoid exceptions on -dealloc when -unregisterAsObserver is called:
if (self) {
[self registerAsObserver];
}
id updater = sharedUpdaters[[NSValue valueWithNonretainedObject:bundle]];
if (updater)
{
self = updater;
}
else if (self)
{
if (sharedUpdaters == nil) {
sharedUpdaters = [[NSMutableDictionary alloc] init];
}
sharedUpdaters[[NSValue valueWithNonretainedObject:bundle]] = self;
host = [[SUHost alloc] initWithBundle:bundle];
_userUpdaterDriver = [[SUSparkleUserUpdaterDriver alloc] initWithHost:host handlesTermination:YES delegate:nil];
// This runs the permission prompt if needed, but never before the app has finished launching because the runloop won't run before that
[self performSelector:@selector(startUpdateCycle) withObject:nil afterDelay:0];
}
host = [[SUHost alloc] initWithBundle:bundle];
_userUpdaterDriver = userUpdaterDriver;
// This runs the permission prompt if needed, but never before the app has finished launching because the runloop won't run before that
[self performSelector:@selector(startUpdateCycle) withObject:nil afterDelay:0];
return self;
}
@@ -141,13 +101,6 @@ static NSString *const SUUpdaterDefaultsObservationContext = @"SUUpdaterDefaults
#endif
}
// This will be used when the updater is instantiated in a nib such as MainMenu
- (instancetype)init
{
return [self initForBundle:[NSBundle mainBundle]];
}
- (NSString *)description { return [NSString stringWithFormat:@"%@ <%@, %@>", [self class], [self.host bundlePath], [self.host installationPath]]; }
- (void)startUpdateCycle
@@ -257,13 +210,9 @@ static NSString *const SUUpdaterDefaultsObservationContext = @"SUUpdaterDefaults
}
}
- (void)putFeedURLIntoDictionary:(NSMutableDictionary *)theDict // You release this.
{
theDict[@"feedURL"] = [self feedURL];
}
- (void)checkForUpdatesInBgReachabilityCheckWithDriver:(SUUpdateDriver *)inDriver /* RUNS ON ITS OWN THREAD */
// RUNS ON ITS OWN THREAD
// updater should be passed as a weak reference
static void SUCheckForUpdatesInBgReachabilityCheck(SUUpdater *updater, SUUpdateDriver *inDriver)
{
@try {
// This method *must* be called on its own thread. SCNetworkReachabilityCheckByName
@@ -271,17 +220,23 @@ static NSString *const SUUpdaterDefaultsObservationContext = @"SUUpdaterDefaults
// wouldn't want to beachball the main thread for a background operation.
// We could use asynchronous reachability callbacks, but those aren't
// reliable enough and can 'get lost' sometimes, which we don't want.
@autoreleasepool {
@autoreleasepool {
SCNetworkConnectionFlags flags = 0;
BOOL isNetworkReachable = YES;
// Don't perform automatic checks on unconnected laptops or dial-up connections that aren't online:
NSMutableDictionary *theDict = [NSMutableDictionary dictionary];
dispatch_sync(dispatch_get_main_queue(), ^{
[self putFeedURLIntoDictionary:theDict]; // Get feed URL on main thread, it's not safe to call elsewhere.
// Get feed URL on main thread, it's not safe to call elsewhere.
theDict[@"feedURL"] = [updater feedURL];;
});
// Did the updater get deallocated already?
if (theDict.count == 0 || updater == nil) {
return;
}
const char *hostname = [[(NSURL *)theDict[@"feedURL"] host] cStringUsingEncoding:NSUTF8StringEncoding];
SCNetworkReachabilityRef reachability = SCNetworkReachabilityCreateWithName(NULL, hostname);
Boolean reachabilityResult = NO;
@@ -290,30 +245,31 @@ static NSString *const SUUpdaterDefaultsObservationContext = @"SUUpdaterDefaults
SCNetworkReachabilityGetFlags(reachability, &flags);
CFRelease(reachability);
}
if( reachabilityResult )
{
if( reachabilityResult )
{
BOOL reachable = (flags & kSCNetworkFlagsReachable) == kSCNetworkFlagsReachable;
BOOL automatic = (flags & kSCNetworkFlagsConnectionAutomatic) == kSCNetworkFlagsConnectionAutomatic;
BOOL local = (flags & kSCNetworkFlagsIsLocalAddress) == kSCNetworkFlagsIsLocalAddress;
if (!(reachable || automatic || local))
isNetworkReachable = NO;
}
// If the network's not reachable, we pass a nil driver into checkForUpdatesWithDriver, which will then reschedule the next update so we try again later.
dispatch_async(dispatch_get_main_queue(), ^{
[self checkForUpdatesWithDriver: isNetworkReachable ? inDriver : nil];
// Is the updater still alive?
if (updater != nil) {
[updater checkForUpdatesWithDriver: isNetworkReachable ? inDriver : nil];
}
});
}
} @catch (NSException *localException) {
} @catch (NSException *localException) {
SULog(@"UNCAUGHT EXCEPTION IN UPDATE CHECK TIMER: %@", [localException reason]);
// Don't propagate the exception beyond here. In Carbon apps that would trash the stack.
}
}
- (void)checkForUpdatesInBackground
{
// Background update checks should only happen if we have a network connection.
@@ -321,8 +277,10 @@ static NSString *const SUUpdaterDefaultsObservationContext = @"SUUpdaterDefaults
// hour or so:
SUUpdateDriver *theUpdateDriver = [[([self automaticallyDownloadsUpdates] ? [SUAutomaticUpdateDriver class] : [SUScheduledUpdateDriver class])alloc] initWithUpdater:self];
// We don't want the rechability check to act on the driver if the updater is going near death
__weak SUUpdater *updater = self;
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
[self checkForUpdatesInBgReachabilityCheckWithDriver:theUpdateDriver];
SUCheckForUpdatesInBgReachabilityCheck(updater, theUpdateDriver);
});
}
@@ -389,42 +347,6 @@ static NSString *const SUUpdaterDefaultsObservationContext = @"SUUpdaterDefaults
[self.driver abortUpdate];
}
- (void)registerAsObserver
{
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(updateDriverDidFinish:) name:SUUpdateDriverFinishedNotification object:nil];
[[NSUserDefaultsController sharedUserDefaultsController] addObserver:self forKeyPath:[@"values." stringByAppendingString:SUScheduledCheckIntervalKey] options:(NSKeyValueObservingOptions)0 context:(__bridge void *)(SUUpdaterDefaultsObservationContext)];
[[NSUserDefaultsController sharedUserDefaultsController] addObserver:self forKeyPath:[@"values." stringByAppendingString:SUEnableAutomaticChecksKey] options:(NSKeyValueObservingOptions)0 context:(__bridge void *)(SUUpdaterDefaultsObservationContext)];
}
- (void)unregisterAsObserver
{
@try
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
[[NSUserDefaultsController sharedUserDefaultsController] removeObserver:self forKeyPath:[@"values." stringByAppendingString:SUScheduledCheckIntervalKey]];
[[NSUserDefaultsController sharedUserDefaultsController] removeObserver:self forKeyPath:[@"values." stringByAppendingString:SUEnableAutomaticChecksKey]];
}
@catch (NSException *)
{
SULog(@"Error: [SUUpdater unregisterAsObserver] called, but the updater wasn't registered as an observer.");
}
}
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
if (context == (__bridge void *)(SUUpdaterDefaultsObservationContext))
{
// Allow a small delay, because perhaps the user or developer wants to change both preferences. This allows the developer to interpret a zero check interval as a sign to disable automatic checking.
// Or we may get this from the developer and from our own KVO observation, this will effectively coalesce them.
[[self class] cancelPreviousPerformRequestsWithTarget:self selector:@selector(resetUpdateCycle) object:nil];
[self performSelector:@selector(resetUpdateCycle) withObject:nil afterDelay:1];
}
else
{
[super observeValueForKeyPath:keyPath ofObject:object change:change context:context];
}
}
- (void)resetUpdateCycle
{
[[self class] cancelPreviousPerformRequestsWithTarget:self selector:@selector(resetUpdateCycle) object:nil];
@@ -584,18 +506,9 @@ static NSString *const SUUpdaterDefaultsObservationContext = @"SUUpdaterDefaults
- (void)dealloc
{
[self unregisterAsObserver];
[self.userUpdaterDriver invalidateUpdateCheckTimer];
}
- (BOOL)validateMenuItem:(NSMenuItem *)item
{
if ([item action] == @selector(checkForUpdates:)) {
return ![self updateInProgress];
}
return YES;
}
- (BOOL)updateInProgress
{
return self.driver && ([self.driver finished] == NO);
+1 -1
View File
@@ -6,7 +6,7 @@
// Copyright © 2016 Sparkle Project. All rights reserved.
//
#import <Foundation/Foundation.h>
#import <Cocoa/Cocoa.h>
#import "SUUpdateAlertChoice.h"
#import "SUAutomaticInstallationChoice.h"
-11
View File
@@ -13,15 +13,4 @@
#define __nullable
#endif
#import <Cocoa/Cocoa.h>
#import "SUConstants.h"
#import "SUErrors.h"
#define SULocalizedString(key, comment) NSLocalizedStringFromTableInBundle(key, @"Sparkle", (NSBundle *__nonnull)([NSBundle bundleWithIdentifier:SUBundleIdentifier] ? [NSBundle bundleWithIdentifier:SUBundleIdentifier] : [NSBundle mainBundle]), comment)
// Work around a warning generated by some versions of Xcode that we still support,
// when using NSParameterAssert
#define SUParameterAssert(condition) \
NSAssert((condition), @"Invalid parameter not satisfying: %@", @(#condition))
#endif
+2
View File
@@ -9,6 +9,8 @@
#ifndef NTSYNCHRONOUSTASK_H
#define NTSYNCHRONOUSTASK_H
#import <Cocoa/Cocoa.h>
@interface NTSynchronousTask : NSObject
@property (readonly, strong) NSData *output;
@property (readonly) int result;