From 578e78876cde439836f93520c7fe432a803d10df Mon Sep 17 00:00:00 2001 From: Zorg Date: Sun, 25 Dec 2016 18:25:42 -0500 Subject: [PATCH 1/4] Separate SUUpdater delegate methods into different file Also create SUUpdaterPrivate protocol to expose as little as possible to the internal update drivers. Ideally this would be minimized and not even exist at all, but I don't want to make the architectural and potential backwards-incompatible changes required to do that. --- Sparkle.xcodeproj/project.pbxproj | 12 +- Sparkle/SUAutomaticUpdateDriver.m | 9 +- Sparkle/SUBasicUpdateDriver.m | 36 ++-- Sparkle/SUProbingUpdateDriver.m | 7 +- Sparkle/SUScheduledUpdateDriver.m | 7 +- Sparkle/SUUIBasedUpdateDriver.m | 17 +- Sparkle/SUUpdateDriver.h | 7 +- Sparkle/SUUpdateDriver.m | 5 +- Sparkle/SUUpdater.h | 248 ---------------------------- Sparkle/SUUpdater.m | 9 +- Sparkle/SUUpdaterDelegate.h | 266 ++++++++++++++++++++++++++++++ Sparkle/SUUpdaterPrivate.h | 23 +++ Sparkle/SUUpdater_Private.h | 15 -- Sparkle/Sparkle.h | 1 + Tests/SUUpdaterTest.m | 1 + 15 files changed, 352 insertions(+), 311 deletions(-) create mode 100644 Sparkle/SUUpdaterDelegate.h create mode 100644 Sparkle/SUUpdaterPrivate.h delete mode 100644 Sparkle/SUUpdater_Private.h diff --git a/Sparkle.xcodeproj/project.pbxproj b/Sparkle.xcodeproj/project.pbxproj index b14a1470..869025d9 100644 --- a/Sparkle.xcodeproj/project.pbxproj +++ b/Sparkle.xcodeproj/project.pbxproj @@ -119,7 +119,7 @@ 61299B3609CB04E000B7442F /* Sparkle.h in Headers */ = {isa = PBXBuildFile; fileRef = 61299B3509CB04E000B7442F /* Sparkle.h */; settings = {ATTRIBUTES = (Public, ); }; }; 612DCBAF0D488BC60015DBEA /* SUUpdatePermissionPrompt.h in Headers */ = {isa = PBXBuildFile; fileRef = 612DCBAD0D488BC60015DBEA /* SUUpdatePermissionPrompt.h */; settings = {ATTRIBUTES = (); }; }; 612DCBB00D488BC60015DBEA /* SUUpdatePermissionPrompt.m in Sources */ = {isa = PBXBuildFile; fileRef = 612DCBAE0D488BC60015DBEA /* SUUpdatePermissionPrompt.m */; }; - 6158A1C5137904B300487EC1 /* SUUpdater_Private.h in Headers */ = {isa = PBXBuildFile; fileRef = 6158A1C4137904B300487EC1 /* SUUpdater_Private.h */; }; + 6158A1C5137904B300487EC1 /* SUUpdaterPrivate.h in Headers */ = {isa = PBXBuildFile; fileRef = 6158A1C4137904B300487EC1 /* SUUpdaterPrivate.h */; }; 615AE3D00D64DC40001CA7BD /* SUModelTranslation.plist in Resources */ = {isa = PBXBuildFile; fileRef = 615AE3CF0D64DC40001CA7BD /* SUModelTranslation.plist */; }; 618FA5010DAE88B40026945C /* SUInstaller.h in Headers */ = {isa = PBXBuildFile; fileRef = 618FA4FF0DAE88B40026945C /* SUInstaller.h */; settings = {ATTRIBUTES = (); }; }; 618FA5020DAE88B40026945C /* SUInstaller.m in Sources */ = {isa = PBXBuildFile; fileRef = 618FA5000DAE88B40026945C /* SUInstaller.m */; }; @@ -198,6 +198,7 @@ 72316BE01E0E17910039EFD9 /* SUApplicationInfo.m in Sources */ = {isa = PBXBuildFile; fileRef = 72316BDD1E0E17910039EFD9 /* SUApplicationInfo.m */; }; 72316BE31E0E1C7F0039EFD9 /* SUSystemUpdateInfo.h in Headers */ = {isa = PBXBuildFile; fileRef = 72316BE11E0E1C7F0039EFD9 /* SUSystemUpdateInfo.h */; }; 72316BE41E0E1C7F0039EFD9 /* SUSystemUpdateInfo.m in Sources */ = {isa = PBXBuildFile; fileRef = 72316BE21E0E1C7F0039EFD9 /* SUSystemUpdateInfo.m */; }; + 72316BE61E1087060039EFD9 /* SUUpdaterDelegate.h in Headers */ = {isa = PBXBuildFile; fileRef = 72316BE51E1087060039EFD9 /* SUUpdaterDelegate.h */; settings = {ATTRIBUTES = (Public, ); }; }; 723A920E1D722438004A9DED /* SUSpotlightImporterTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 723A920D1D722438004A9DED /* SUSpotlightImporterTest.swift */; }; 723B252D1CEAB3A600909873 /* bscommon.c in Sources */ = {isa = PBXBuildFile; fileRef = 723B252B1CEAB3A600909873 /* bscommon.c */; }; 723B252E1CEAB3A600909873 /* bscommon.c in Sources */ = {isa = PBXBuildFile; fileRef = 723B252B1CEAB3A600909873 /* bscommon.c */; }; @@ -615,7 +616,7 @@ 6158A1BE1378F8BB00487EC1 /* tr */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = tr; path = tr.lproj/SUAutomaticUpdateAlert.xib; sourceTree = ""; }; 6158A1BF1378F8BB00487EC1 /* tr */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = tr; path = tr.lproj/SUUpdateAlert.xib; sourceTree = ""; }; 6158A1C01378F8BB00487EC1 /* tr */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = tr; path = tr.lproj/SUUpdatePermissionPrompt.xib; sourceTree = ""; }; - 6158A1C4137904B300487EC1 /* SUUpdater_Private.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SUUpdater_Private.h; sourceTree = ""; }; + 6158A1C4137904B300487EC1 /* SUUpdaterPrivate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SUUpdaterPrivate.h; sourceTree = ""; }; 615AE3CF0D64DC40001CA7BD /* SUModelTranslation.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = SUModelTranslation.plist; sourceTree = ""; }; 6186554310D7484E00B1E074 /* pt_PT */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.strings; name = pt_PT; path = pt_PT.lproj/Sparkle.strings; sourceTree = ""; }; 618915730E35937600B5E981 /* sv */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.strings; name = sv; path = sv.lproj/Sparkle.strings; sourceTree = ""; }; @@ -701,6 +702,7 @@ 72316BDD1E0E17910039EFD9 /* SUApplicationInfo.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SUApplicationInfo.m; sourceTree = ""; }; 72316BE11E0E1C7F0039EFD9 /* SUSystemUpdateInfo.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SUSystemUpdateInfo.h; sourceTree = ""; }; 72316BE21E0E1C7F0039EFD9 /* SUSystemUpdateInfo.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SUSystemUpdateInfo.m; sourceTree = ""; }; + 72316BE51E1087060039EFD9 /* SUUpdaterDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SUUpdaterDelegate.h; sourceTree = ""; }; 723A920D1D722438004A9DED /* SUSpotlightImporterTest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SUSpotlightImporterTest.swift; sourceTree = ""; }; 723B252B1CEAB3A600909873 /* bscommon.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = bscommon.c; sourceTree = ""; }; 723B252C1CEAB3A600909873 /* bscommon.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = bscommon.h; sourceTree = ""; }; @@ -1203,7 +1205,8 @@ 61CFB2C10E384958007A1735 /* Support */, 61B5F8E309C4CE3C00B25A18 /* SUUpdater.h */, 61B5F8E409C4CE3C00B25A18 /* SUUpdater.m */, - 6158A1C4137904B300487EC1 /* SUUpdater_Private.h */, + 72316BE51E1087060039EFD9 /* SUUpdaterDelegate.h */, + 6158A1C4137904B300487EC1 /* SUUpdaterPrivate.h */, ); name = "Update Control"; sourceTree = ""; @@ -1281,6 +1284,7 @@ 61B5FC7009C51F4A00B25A18 /* SUAppcastItem.h in Headers */, 6120721209CC5C4B007FE0F6 /* SUAutomaticUpdateAlert.h in Headers */, 61B93B270DD0FDD300DCD2F8 /* SUAutomaticUpdateDriver.h in Headers */, + 72316BE61E1087060039EFD9 /* SUUpdaterDelegate.h in Headers */, 61F83F740DBFE141006FDD30 /* SUBasicUpdateDriver.h in Headers */, 5D06E9390FD69271005AE3F6 /* SUBinaryDeltaUnarchiver.h in Headers */, 61B078CE15A5FB6100600039 /* SUCodeSigningVerifier.h in Headers */, @@ -1315,7 +1319,7 @@ 72316BD91E0E17180039EFD9 /* SUBundleIcon.h in Headers */, 612DCBAF0D488BC60015DBEA /* SUUpdatePermissionPrompt.h in Headers */, 61B5F8ED09C4CE3C00B25A18 /* SUUpdater.h in Headers */, - 6158A1C5137904B300487EC1 /* SUUpdater_Private.h in Headers */, + 6158A1C5137904B300487EC1 /* SUUpdaterPrivate.h in Headers */, 72316BDE1E0E17910039EFD9 /* SUApplicationInfo.h in Headers */, 61A354550DF113C70076ECB1 /* SUUserInitiatedUpdateDriver.h in Headers */, 61A2259E0D1C495D00430CCD /* SUVersionComparisonProtocol.h in Headers */, diff --git a/Sparkle/SUAutomaticUpdateDriver.m b/Sparkle/SUAutomaticUpdateDriver.m index 973ccfd7..a8df1a4d 100644 --- a/Sparkle/SUAutomaticUpdateDriver.m +++ b/Sparkle/SUAutomaticUpdateDriver.m @@ -7,7 +7,8 @@ // #import "SUAutomaticUpdateDriver.h" -#import "SUUpdater.h" +#import "SUUpdaterPrivate.h" +#import "SUUpdaterDelegate.h" #import "SULocalizations.h" #import "SUErrors.h" #import "SUAutomaticUpdateAlert.h" @@ -88,7 +89,7 @@ static const NSTimeInterval SUAutomaticUpdatePromptImpatienceTimer = 60 * 60 * 2 [invocation setArgument:&showUI atIndex:3]; [invocation setTarget:self]; - [updaterDelegate updater:self.updater willInstallUpdateOnQuit:self.updateItem immediateInstallationInvocation:invocation]; + [updaterDelegate updater:(id)self.updater willInstallUpdateOnQuit:self.updateItem immediateInstallationInvocation:invocation]; } // If this is marked as a critical update, we'll prompt the user to install it right away. @@ -119,7 +120,7 @@ static const NSTimeInterval SUAutomaticUpdatePromptImpatienceTimer = 60 * 60 * 2 id updaterDelegate = [self.updater delegate]; if ([updaterDelegate respondsToSelector:@selector(updater:didCancelInstallUpdateOnQuit:)]) - [updaterDelegate updater:self.updater didCancelInstallUpdateOnQuit:self.updateItem]; + [updaterDelegate updater:(id)self.updater didCancelInstallUpdateOnQuit:self.updateItem]; } } @@ -216,7 +217,7 @@ static const NSTimeInterval SUAutomaticUpdatePromptImpatienceTimer = 60 * 60 * 2 // Normally this gets called by the superclass id updaterDelegate = [self.updater delegate]; if ([updaterDelegate respondsToSelector:@selector(updater:didAbortWithError:)]) { - [updaterDelegate updater:self.updater didAbortWithError:error]; + [updaterDelegate updater:(id)self.updater didAbortWithError:error]; } [self abortUpdate]; diff --git a/Sparkle/SUBasicUpdateDriver.m b/Sparkle/SUBasicUpdateDriver.m index 267dfe27..4d0487b4 100644 --- a/Sparkle/SUBasicUpdateDriver.m +++ b/Sparkle/SUBasicUpdateDriver.m @@ -16,7 +16,8 @@ #import "SUConstants.h" #import "SULog.h" #import "SUBinaryDeltaCommon.h" -#import "SUUpdater_Private.h" +#import "SUUpdaterPrivate.h" +#import "SUUpdaterDelegate.h" #import "SUFileManager.h" #import "SUUpdateValidator.h" #import "SULocalizations.h" @@ -78,7 +79,7 @@ // Give the delegate a chance to provide a custom version comparator if ([[self.updater delegate] respondsToSelector:@selector(versionComparatorForUpdater:)]) { - comparator = [[self.updater delegate] versionComparatorForUpdater:self.updater]; + comparator = [[self.updater delegate] versionComparatorForUpdater:(id)self.updater]; } // If we don't get a comparator from the delegate, use the default comparator @@ -149,7 +150,7 @@ - (void)appcastDidFinishLoading:(SUAppcast *)ac { if ([[self.updater delegate] respondsToSelector:@selector(updater:didFinishLoadingAppcast:)]) { - [[self.updater delegate] updater:self.updater didFinishLoadingAppcast:ac]; + [[self.updater delegate] updater:(id)self.updater didFinishLoadingAppcast:ac]; } NSDictionary *userInfo = (ac != nil) ? @{ SUUpdaterAppcastNotificationKey: ac } : nil; @@ -160,9 +161,9 @@ // Now we have to find the best valid update in the appcast. if ([[self.updater delegate] respondsToSelector:@selector(bestValidUpdateInAppcast:forUpdater:)]) // Does the delegate want to handle it? { - item = [[self.updater delegate] bestValidUpdateInAppcast:ac forUpdater:self.updater]; + item = [[self.updater delegate] bestValidUpdateInAppcast:ac forUpdater:(id)self.updater]; if ([item isDeltaUpdate]) { - self.nonDeltaUpdateItem = [[self.updater delegate] bestValidUpdateInAppcast:[ac copyWithoutDeltaUpdates] forUpdater:self.updater]; + self.nonDeltaUpdateItem = [[self.updater delegate] bestValidUpdateInAppcast:[ac copyWithoutDeltaUpdates] forUpdater:(id)self.updater]; } } else // If not, we'll take care of it ourselves. @@ -191,7 +192,7 @@ assert(self.updateItem); if ([[self.updater delegate] respondsToSelector:@selector(updater:didFindValidUpdate:)]) { - [[self.updater delegate] updater:self.updater didFindValidUpdate:self.updateItem]; + [[self.updater delegate] updater:(id)self.updater didFindValidUpdate:self.updateItem]; } [[NSNotificationCenter defaultCenter] postNotificationName:SUUpdaterDidFindValidUpdateNotification @@ -203,7 +204,7 @@ - (void)didNotFindUpdate { if ([[self.updater delegate] respondsToSelector:@selector(updaterDidNotFindUpdate:)]) { - [[self.updater delegate] updaterDidNotFindUpdate:self.updater]; + [[self.updater delegate] updaterDidNotFindUpdate:(id)self.updater]; } [[NSNotificationCenter defaultCenter] postNotificationName:SUUpdaterDidNotFindUpdateNotification object:self.updater]; @@ -248,7 +249,7 @@ NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[self.updateItem fileURL]]; [request setValue:[self.updater userAgentString] forHTTPHeaderField:@"User-Agent"]; if ([[self.updater delegate] respondsToSelector:@selector(updater:willDownloadUpdate:withRequest:)]) { - [[self.updater delegate] updater:self.updater + [[self.updater delegate] updater:(id)self.updater willDownloadUpdate:self.updateItem withRequest:request]; } @@ -296,7 +297,7 @@ } if ([[self.updater delegate] respondsToSelector:@selector(updater:failedToDownloadUpdate:error:)]) { - [[self.updater delegate] updater:self.updater + [[self.updater delegate] updater:(id)self.updater failedToDownloadUpdate:self.updateItem error:error]; } @@ -420,6 +421,11 @@ return YES; } +- (BOOL)mayUpdateAndRestart +{ + return (!self.updater.delegate || ![self.updater.delegate respondsToSelector:@selector(updaterShouldRelaunchApplication:)] || [self.updater.delegate updaterShouldRelaunchApplication:(id)self.updater]); +} + - (void)installWithToolAndRelaunch:(BOOL)relaunch displayingUserInterface:(BOOL)showUI { assert(self.updateItem); @@ -435,7 +441,7 @@ return; } - if (![self.updater mayUpdateAndRestart]) + if (![self mayUpdateAndRestart]) { [self abortUpdate]; return; @@ -451,14 +457,14 @@ [invocation setArgument:&relaunch atIndex:2]; [invocation setTarget:self]; postponedOnce = YES; - if ([updaterDelegate updater:self.updater shouldPostponeRelaunchForUpdate:self.updateItem untilInvoking:invocation]) { + if ([updaterDelegate updater:(id)self.updater shouldPostponeRelaunchForUpdate:self.updateItem untilInvoking:invocation]) { return; } } if ([updaterDelegate respondsToSelector:@selector(updater:willInstallUpdate:)]) { - [updaterDelegate updater:self.updater willInstallUpdate:self.updateItem]; + [updaterDelegate updater:(id)self.updater willInstallUpdate:self.updateItem]; } NSBundle *sparkleBundle = self.updater.sparkleBundle; @@ -505,7 +511,7 @@ self.relaunchPath = relaunchCopyTargetPath; // Set for backwards compatibility, in case any delegates modify it [[NSNotificationCenter defaultCenter] postNotificationName:SUUpdaterWillRestartNotification object:self]; if ([updaterDelegate respondsToSelector:@selector(updaterWillRelaunchApplication:)]) - [updaterDelegate updaterWillRelaunchApplication:self.updater]; + [updaterDelegate updaterWillRelaunchApplication:(id)self.updater]; NSString *relaunchToolPath = [[NSBundle bundleWithPath:self.relaunchPath] executablePath]; if (!relaunchToolPath || ![[NSFileManager defaultManager] fileExistsAtPath:self.relaunchPath]) { @@ -519,7 +525,7 @@ NSString *pathToRelaunch = [self.host bundlePath]; if ([updaterDelegate respondsToSelector:@selector(pathToRelaunchForUpdater:)]) { - pathToRelaunch = [updaterDelegate pathToRelaunchForUpdater:self.updater]; + pathToRelaunch = [updaterDelegate pathToRelaunchForUpdater:(id)self.updater]; } [NSTask launchedTaskWithLaunchPath:relaunchToolPath arguments:@[[self.host bundlePath], @@ -588,7 +594,7 @@ // Notify host app that update has aborted id updaterDelegate = [self.updater delegate]; if ([updaterDelegate respondsToSelector:@selector(updater:didAbortWithError:)]) { - [updaterDelegate updater:self.updater didAbortWithError:error]; + [updaterDelegate updater:(id)self.updater didAbortWithError:error]; } [self abortUpdate]; diff --git a/Sparkle/SUProbingUpdateDriver.m b/Sparkle/SUProbingUpdateDriver.m index 1fde6c6d..872225de 100644 --- a/Sparkle/SUProbingUpdateDriver.m +++ b/Sparkle/SUProbingUpdateDriver.m @@ -7,7 +7,8 @@ // #import "SUProbingUpdateDriver.h" -#import "SUUpdater.h" +#import "SUUpdaterPrivate.h" +#import "SUUpdaterDelegate.h" @implementation SUProbingUpdateDriver @@ -18,7 +19,7 @@ id updaterDelegate = [self.updater delegate]; if ([updaterDelegate respondsToSelector:@selector(updater:didFindValidUpdate:)]) - [updaterDelegate updater:self.updater didFindValidUpdate:self.updateItem]; + [updaterDelegate updater:(id)self.updater didFindValidUpdate:self.updateItem]; NSDictionary *userInfo = (self.updateItem != nil) ? @{ SUUpdaterAppcastItemNotificationKey: self.updateItem } : nil; [[NSNotificationCenter defaultCenter] postNotificationName:SUUpdaterDidFindValidUpdateNotification object:self.updater userInfo:userInfo]; [self abortUpdate]; @@ -29,7 +30,7 @@ id updaterDelegate = [self.updater delegate]; if ([updaterDelegate respondsToSelector:@selector(updaterDidNotFindUpdate:)]) { - [updaterDelegate updaterDidNotFindUpdate:self.updater]; + [updaterDelegate updaterDidNotFindUpdate:(id)self.updater]; } [[NSNotificationCenter defaultCenter] postNotificationName:SUUpdaterDidNotFindUpdateNotification object:self.updater]; diff --git a/Sparkle/SUScheduledUpdateDriver.m b/Sparkle/SUScheduledUpdateDriver.m index b8a3bedb..5a5e2300 100644 --- a/Sparkle/SUScheduledUpdateDriver.m +++ b/Sparkle/SUScheduledUpdateDriver.m @@ -7,7 +7,8 @@ // #import "SUScheduledUpdateDriver.h" -#import "SUUpdater.h" +#import "SUUpdaterPrivate.h" +#import "SUUpdaterDelegate.h" @interface SUScheduledUpdateDriver () @@ -30,7 +31,7 @@ id updaterDelegate = [self.updater delegate]; if ([updaterDelegate respondsToSelector:@selector(updaterDidNotFindUpdate:)]) { - [updaterDelegate updaterDidNotFindUpdate:self.updater]; + [updaterDelegate updaterDidNotFindUpdate:(id)self.updater]; } [[NSNotificationCenter defaultCenter] postNotificationName:SUUpdaterDidNotFindUpdateNotification object:self.updater]; @@ -46,7 +47,7 @@ // Normally this gets called by the superclass id updaterDelegate = [self.updater delegate]; if ([updaterDelegate respondsToSelector:@selector(updater:didAbortWithError:)]) { - [updaterDelegate updater:self.updater didAbortWithError:error]; + [updaterDelegate updater:(id)self.updater didAbortWithError:error]; } [self abortUpdate]; diff --git a/Sparkle/SUUIBasedUpdateDriver.m b/Sparkle/SUUIBasedUpdateDriver.m index a57e5c6c..8fc57b76 100644 --- a/Sparkle/SUUIBasedUpdateDriver.m +++ b/Sparkle/SUUIBasedUpdateDriver.m @@ -9,7 +9,8 @@ #import "SUUIBasedUpdateDriver.h" #import "SUUpdateAlert.h" -#import "SUUpdater_Private.h" +#import "SUUpdaterPrivate.h" +#import "SUUpdaterDelegate.h" #import "SUHost.h" #import "SUOperatingSystem.h" #import "SUStatusController.h" @@ -45,7 +46,7 @@ @synthesize statusController; @synthesize updateAlert; -- (instancetype)initWithUpdater:(SUUpdater *)anUpdater +- (instancetype)initWithUpdater:(id)anUpdater { if ((self = [super initWithUpdater:anUpdater])) { self.automaticallyInstallUpdates = NO; @@ -56,7 +57,7 @@ - (void)didFindValidUpdate { if ([[self.updater delegate] respondsToSelector:@selector(updater:didFindValidUpdate:)]) { - [[self.updater delegate] updater:self.updater didFindValidUpdate:self.updateItem]; + [[self.updater delegate] updater:(id)self.updater didFindValidUpdate:self.updateItem]; } if (self.automaticallyInstallUpdates) { @@ -70,7 +71,7 @@ id versDisp = nil; if ([[self.updater delegate] respondsToSelector:@selector(versionDisplayerForUpdater:)]) { - versDisp = [[self.updater delegate] versionDisplayerForUpdater:self.updater]; + versDisp = [[self.updater delegate] versionDisplayerForUpdater:(id)self.updater]; } [self.updateAlert setVersionDisplayer:versDisp]; @@ -92,7 +93,7 @@ - (void)didNotFindUpdate { if ([[self.updater delegate] respondsToSelector:@selector(updaterDidNotFindUpdate:)]) - [[self.updater delegate] updaterDidNotFindUpdate:self.updater]; + [[self.updater delegate] updaterDidNotFindUpdate:(id)self.updater]; [[NSNotificationCenter defaultCenter] postNotificationName:SUUpdaterDidNotFindUpdateNotification object:self.updater]; if (!self.automaticallyInstallUpdates) { @@ -205,7 +206,7 @@ if (self.download) { [self.download cancel]; if ([[self.updater delegate] respondsToSelector:@selector(userDidCancelDownload:)]) { - [[self.updater delegate] userDidCancelDownload:self.updater]; + [[self.updater delegate] userDidCancelDownload:(id)self.updater]; } } [self abortUpdate]; @@ -293,7 +294,7 @@ - (void)showAlert:(NSAlert *)alert { if ([[self.updater delegate] respondsToSelector:@selector(updaterWillShowModalAlert:)]) { - [[self.updater delegate] updaterWillShowModalAlert:self.updater]; + [[self.updater delegate] updaterWillShowModalAlert:(id)self.updater]; } // When showing a modal alert we need to ensure that background applications @@ -304,7 +305,7 @@ [alert runModal]; if ([[self.updater delegate] respondsToSelector:@selector(updaterDidShowModalAlert:)]) - [[self.updater delegate] updaterDidShowModalAlert:self.updater]; + [[self.updater delegate] updaterDidShowModalAlert:(id)self.updater]; } @end diff --git a/Sparkle/SUUpdateDriver.h b/Sparkle/SUUpdateDriver.h index b490c6d9..05d9547e 100644 --- a/Sparkle/SUUpdateDriver.h +++ b/Sparkle/SUUpdateDriver.h @@ -13,13 +13,14 @@ extern NSString *const SUUpdateDriverFinishedNotification; -@class SUHost, SUUpdater; +@class SUHost; +@protocol SUUpdaterPrivate; @interface SUUpdateDriver : NSObject -@property (readonly, weak) SUUpdater *updater; +@property (readonly, weak) id updater; @property (strong) SUHost *host; -- (instancetype)initWithUpdater:(SUUpdater *)updater; +- (instancetype)initWithUpdater:(id)updater; - (void)checkForUpdatesAtURL:(NSURL *)URL host:(SUHost *)host; - (void)abortUpdate; diff --git a/Sparkle/SUUpdateDriver.m b/Sparkle/SUUpdateDriver.m index 0b98fe3c..0aed1dfe 100644 --- a/Sparkle/SUUpdateDriver.m +++ b/Sparkle/SUUpdateDriver.m @@ -7,6 +7,7 @@ // #import "SUUpdateDriver.h" +#import "SUUpdaterPrivate.h" #import "SUHost.h" #import "SULog.h" @@ -14,7 +15,7 @@ NSString *const SUUpdateDriverFinishedNotification = @"SUUpdateDriverFinished"; @interface SUUpdateDriver () -@property (weak) SUUpdater *updater; +@property (weak) id updater; @property (copy) NSURL *appcastURL; @property (getter=isInterruptible) BOOL interruptible; @@ -29,7 +30,7 @@ NSString *const SUUpdateDriverFinishedNotification = @"SUUpdateDriverFinished"; @synthesize appcastURL; @synthesize automaticallyInstallUpdates; -- (instancetype)initWithUpdater:(SUUpdater *)anUpdater +- (instancetype)initWithUpdater:(id)anUpdater { if ((self = [super init])) { self.updater = anUpdater; diff --git a/Sparkle/SUUpdater.h b/Sparkle/SUUpdater.h index 79be3bd5..f627ed14 100644 --- a/Sparkle/SUUpdater.h +++ b/Sparkle/SUUpdater.h @@ -213,252 +213,4 @@ SU_EXPORT @interface SUUpdater : NSObject @end -// ----------------------------------------------------------------------------- -// SUUpdater Notifications for events that might be interesting to more than just the delegate -// The updater will be the notification object -// ----------------------------------------------------------------------------- -SU_EXPORT extern NSString *const SUUpdaterDidFinishLoadingAppCastNotification; -SU_EXPORT extern NSString *const SUUpdaterDidFindValidUpdateNotification; -SU_EXPORT extern NSString *const SUUpdaterDidNotFindUpdateNotification; -SU_EXPORT extern NSString *const SUUpdaterWillRestartNotification; -#define SUUpdaterWillRelaunchApplicationNotification SUUpdaterWillRestartNotification; -#define SUUpdaterWillInstallUpdateNotification SUUpdaterWillRestartNotification; - -// Key for the SUAppcastItem object in the SUUpdaterDidFindValidUpdateNotification userInfo -SU_EXPORT extern NSString *const SUUpdaterAppcastItemNotificationKey; -// Key for the SUAppcast object in the SUUpdaterDidFinishLoadingAppCastNotification userInfo -SU_EXPORT extern NSString *const SUUpdaterAppcastNotificationKey; - -// ----------------------------------------------------------------------------- -// SUUpdater Delegate: -// ----------------------------------------------------------------------------- - -/*! - Provides methods to control the behavior of an SUUpdater object. - */ -@protocol SUUpdaterDelegate -@optional - -/*! - Returns whether to allow Sparkle to pop up. - - For example, this may be used to prevent Sparkle from interrupting a setup assistant. - - \param updater The SUUpdater instance. - */ -- (BOOL)updaterMayCheckForUpdates:(SUUpdater *)updater; - -/*! - Returns additional parameters to append to the appcast URL's query string. - - This is potentially based on whether or not Sparkle will also be sending along the system profile. - - \param updater The SUUpdater instance. - \param sendingProfile Whether the system profile will also be sent. - - \return An array of dictionaries with keys: "key", "value", "displayKey", "displayValue", the latter two being specifically for display to the user. - */ -- (NSArray *)feedParametersForUpdater:(SUUpdater *)updater sendingSystemProfile:(BOOL)sendingProfile; - -/*! - Returns a custom appcast URL. - - Override this to dynamically specify the entire URL. - - An alternative may be to use SUUpdaterDelegate::feedParametersForUpdater:sendingSystemProfile: - and let the server handle what kind of feed to provide. - - \param updater The SUUpdater instance. - */ -- (NSString *)feedURLStringForUpdater:(SUUpdater *)updater; - -/*! - Returns whether Sparkle should prompt the user about automatic update checks. - - Use this to override the default behavior. - - \param updater The SUUpdater instance. - */ -- (BOOL)updaterShouldPromptForPermissionToCheckForUpdates:(SUUpdater *)updater; - -/*! - Called after Sparkle has downloaded the appcast from the remote server. - - Implement this if you want to do some special handling with the appcast once it finishes loading. - - \param updater The SUUpdater instance. - \param appcast The appcast that was downloaded from the remote server. - */ -- (void)updater:(SUUpdater *)updater didFinishLoadingAppcast:(SUAppcast *)appcast; - -/*! - Returns the item in the appcast corresponding to the update that should be installed. - - If you're using special logic or extensions in your appcast, - implement this to use your own logic for finding a valid update, if any, - in the given appcast. - - \param appcast The appcast that was downloaded from the remote server. - \param updater The SUUpdater instance. - */ -- (SUAppcastItem *)bestValidUpdateInAppcast:(SUAppcast *)appcast forUpdater:(SUUpdater *)updater; - -/*! - Called when a valid update is found by the update driver. - - \param updater The SUUpdater instance. - \param item The appcast item corresponding to the update that is proposed to be installed. - */ -- (void)updater:(SUUpdater *)updater didFindValidUpdate:(SUAppcastItem *)item; - -/*! - Called when a valid update is not found. - - \param updater The SUUpdater instance. - */ -- (void)updaterDidNotFindUpdate:(SUUpdater *)updater; - -/*! - Called immediately before downloading the specified update. - - \param updater The SUUpdater instance. - \param item The appcast item corresponding to the update that is proposed to be downloaded. - \param request The mutable URL request that will be used to download the update. - */ -- (void)updater:(SUUpdater *)updater willDownloadUpdate:(SUAppcastItem *)item withRequest:(NSMutableURLRequest *)request; - -/*! - Called after the specified update failed to download. - - \param updater The SUUpdater instance. - \param item The appcast item corresponding to the update that failed to download. - \param error The error generated by the failed download. - */ -- (void)updater:(SUUpdater *)updater failedToDownloadUpdate:(SUAppcastItem *)item error:(NSError *)error; - -/*! - Called when the user clicks the cancel button while and update is being downloaded. - - \param updater The SUUpdater instance. - */ -- (void)userDidCancelDownload:(SUUpdater *)updater; - -/*! - Called immediately before installing the specified update. - - \param updater The SUUpdater instance. - \param item The appcast item corresponding to the update that is proposed to be installed. - */ -- (void)updater:(SUUpdater *)updater willInstallUpdate:(SUAppcastItem *)item; - -/*! - Returns whether the relaunch should be delayed in order to perform other tasks. - - This is not called if the user didn't relaunch on the previous update, - in that case it will immediately restart. - - \param updater The SUUpdater instance. - \param item The appcast item corresponding to the update that is proposed to be installed. - \param invocation The invocation that must be completed with `[invocation invoke]` before continuing with the relaunch. - - \return \c YES to delay the relaunch until \p invocation is invoked. - */ -- (BOOL)updater:(SUUpdater *)updater shouldPostponeRelaunchForUpdate:(SUAppcastItem *)item untilInvoking:(NSInvocation *)invocation; - -/*! - Returns whether the application should be relaunched at all. - - Some apps \b cannot be relaunched under certain circumstances. - This method can be used to explicitly prevent a relaunch. - - \param updater The SUUpdater instance. - */ -- (BOOL)updaterShouldRelaunchApplication:(SUUpdater *)updater; - -/*! - Called immediately before relaunching. - - \param updater The SUUpdater instance. - */ -- (void)updaterWillRelaunchApplication:(SUUpdater *)updater; - -/*! - Returns an object that compares version numbers to determine their arithmetic relation to each other. - - This method allows you to provide a custom version comparator. - If you don't implement this method or return \c nil, - the standard version comparator will be used. - - \sa SUStandardVersionComparator - - \param updater The SUUpdater instance. - */ -- (id)versionComparatorForUpdater:(SUUpdater *)updater; - -/*! - Returns an object that formats version numbers for display to the user. - - If you don't implement this method or return \c nil, - the standard version formatter will be used. - - \sa SUUpdateAlert - - \param updater The SUUpdater instance. - */ -- (id)versionDisplayerForUpdater:(SUUpdater *)updater; - -/*! - Returns the path which is used to relaunch the client after the update is installed. - - The default is the path of the host bundle. - - \param updater The SUUpdater instance. - */ -- (NSString *)pathToRelaunchForUpdater:(SUUpdater *)updater; - -/*! - Called before an updater shows a modal alert window, - to give the host the opportunity to hide attached windows that may get in the way. - - \param updater The SUUpdater instance. - */ -- (void)updaterWillShowModalAlert:(SUUpdater *)updater; - -/*! - Called after an updater shows a modal alert window, - to give the host the opportunity to hide attached windows that may get in the way. - - \param updater The SUUpdater instance. - */ -- (void)updaterDidShowModalAlert:(SUUpdater *)updater; - -/*! - Called when an update is scheduled to be silently installed on quit. - This is after an update has been automatically downloaded in the background. - (i.e. SUUpdater::automaticallyDownloadsUpdates is YES) - - \param updater The SUUpdater instance. - \param item The appcast item corresponding to the update that is proposed to be installed. - \param invocation Can be used to trigger an immediate silent install and relaunch. - */ -- (void)updater:(SUUpdater *)updater willInstallUpdateOnQuit:(SUAppcastItem *)item immediateInstallationInvocation:(NSInvocation *)invocation; - -/*! - Calls after an update that was scheduled to be silently installed on quit has been canceled. - - \param updater The SUUpdater instance. - \param item The appcast item corresponding to the update that was proposed to be installed. - */ -- (void)updater:(SUUpdater *)updater didCancelInstallUpdateOnQuit:(SUAppcastItem *)item; - -/*! - Called after an update is aborted due to an error. - - \param updater The SUUpdater instance. - \param error The error that caused the abort - */ -- (void)updater:(SUUpdater *)updater didAbortWithError:(NSError *)error; - -@end - #endif diff --git a/Sparkle/SUUpdater.m b/Sparkle/SUUpdater.m index b03d196e..c13974a5 100644 --- a/Sparkle/SUUpdater.m +++ b/Sparkle/SUUpdater.m @@ -7,6 +7,8 @@ // #import "SUUpdater.h" +#import "SUUpdaterDelegate.h" +#import "SUUpdaterPrivate.h" #import "SUHost.h" #import "SUUpdatePermissionPrompt.h" @@ -30,7 +32,7 @@ NSString *const SUUpdaterWillRestartNotification = @"SUUpdaterWillRestartNotific NSString *const SUUpdaterAppcastItemNotificationKey = @"SUUpdaterAppcastItemNotificationKey"; NSString *const SUUpdaterAppcastNotificationKey = @"SUUpdaterAppCastNotificationKey"; -@interface SUUpdater () +@interface SUUpdater () @property (strong) NSTimer *checkTimer; @property (strong) NSBundle *sparkleBundle; @@ -282,11 +284,6 @@ static NSString *const SUUpdaterDefaultsObservationContext = @"SUUpdaterDefaults [self checkForUpdatesWithDriver:theUpdateDriver]; } -- (BOOL)mayUpdateAndRestart -{ - return (!self.delegate || ![self.delegate respondsToSelector:@selector(updaterShouldRelaunchApplication:)] || [self.delegate updaterShouldRelaunchApplication:self]); -} - - (IBAction)checkForUpdates:(id)__unused sender { if (self.driver && [self.driver isInterruptible]) { diff --git a/Sparkle/SUUpdaterDelegate.h b/Sparkle/SUUpdaterDelegate.h new file mode 100644 index 00000000..a6422d62 --- /dev/null +++ b/Sparkle/SUUpdaterDelegate.h @@ -0,0 +1,266 @@ +// +// SUUpdaterDelegate.h +// Sparkle +// +// Created by Mayur Pawashe on 12/25/16. +// Copyright © 2016 Sparkle Project. All rights reserved. +// + +#if __has_feature(modules) +@import Foundation; +#else +#import +#endif + +#import "SUExport.h" + +@protocol SUVersionComparison, SUVersionDisplay; +@class SUUpdater, SUAppcast, SUAppcastItem; + +// ----------------------------------------------------------------------------- +// SUUpdater Notifications for events that might be interesting to more than just the delegate +// The updater will be the notification object +// ----------------------------------------------------------------------------- +SU_EXPORT extern NSString *const SUUpdaterDidFinishLoadingAppCastNotification; +SU_EXPORT extern NSString *const SUUpdaterDidFindValidUpdateNotification; +SU_EXPORT extern NSString *const SUUpdaterDidNotFindUpdateNotification; +SU_EXPORT extern NSString *const SUUpdaterWillRestartNotification; +#define SUUpdaterWillRelaunchApplicationNotification SUUpdaterWillRestartNotification; +#define SUUpdaterWillInstallUpdateNotification SUUpdaterWillRestartNotification; + +// Key for the SUAppcastItem object in the SUUpdaterDidFindValidUpdateNotification userInfo +SU_EXPORT extern NSString *const SUUpdaterAppcastItemNotificationKey; +// Key for the SUAppcast object in the SUUpdaterDidFinishLoadingAppCastNotification userInfo +SU_EXPORT extern NSString *const SUUpdaterAppcastNotificationKey; + +// ----------------------------------------------------------------------------- +// SUUpdater Delegate: +// ----------------------------------------------------------------------------- + +/*! + Provides methods to control the behavior of an SUUpdater object. + */ +@protocol SUUpdaterDelegate +@optional + +/*! + Returns whether to allow Sparkle to pop up. + + For example, this may be used to prevent Sparkle from interrupting a setup assistant. + + \param updater The SUUpdater instance. + */ +- (BOOL)updaterMayCheckForUpdates:(SUUpdater *)updater; + +/*! + Returns additional parameters to append to the appcast URL's query string. + + This is potentially based on whether or not Sparkle will also be sending along the system profile. + + \param updater The SUUpdater instance. + \param sendingProfile Whether the system profile will also be sent. + + \return An array of dictionaries with keys: "key", "value", "displayKey", "displayValue", the latter two being specifically for display to the user. + */ +- (NSArray *)feedParametersForUpdater:(SUUpdater *)updater sendingSystemProfile:(BOOL)sendingProfile; + +/*! + Returns a custom appcast URL. + + Override this to dynamically specify the entire URL. + + An alternative may be to use SUUpdaterDelegate::feedParametersForUpdater:sendingSystemProfile: + and let the server handle what kind of feed to provide. + + \param updater The SUUpdater instance. + */ +- (NSString *)feedURLStringForUpdater:(SUUpdater *)updater; + +/*! + Returns whether Sparkle should prompt the user about automatic update checks. + + Use this to override the default behavior. + + \param updater The SUUpdater instance. + */ +- (BOOL)updaterShouldPromptForPermissionToCheckForUpdates:(SUUpdater *)updater; + +/*! + Called after Sparkle has downloaded the appcast from the remote server. + + Implement this if you want to do some special handling with the appcast once it finishes loading. + + \param updater The SUUpdater instance. + \param appcast The appcast that was downloaded from the remote server. + */ +- (void)updater:(SUUpdater *)updater didFinishLoadingAppcast:(SUAppcast *)appcast; + +/*! + Returns the item in the appcast corresponding to the update that should be installed. + + If you're using special logic or extensions in your appcast, + implement this to use your own logic for finding a valid update, if any, + in the given appcast. + + \param appcast The appcast that was downloaded from the remote server. + \param updater The SUUpdater instance. + */ +- (SUAppcastItem *)bestValidUpdateInAppcast:(SUAppcast *)appcast forUpdater:(SUUpdater *)updater; + +/*! + Called when a valid update is found by the update driver. + + \param updater The SUUpdater instance. + \param item The appcast item corresponding to the update that is proposed to be installed. + */ +- (void)updater:(SUUpdater *)updater didFindValidUpdate:(SUAppcastItem *)item; + +/*! + Called when a valid update is not found. + + \param updater The SUUpdater instance. + */ +- (void)updaterDidNotFindUpdate:(SUUpdater *)updater; + +/*! + Called immediately before downloading the specified update. + + \param updater The SUUpdater instance. + \param item The appcast item corresponding to the update that is proposed to be downloaded. + \param request The mutable URL request that will be used to download the update. + */ +- (void)updater:(SUUpdater *)updater willDownloadUpdate:(SUAppcastItem *)item withRequest:(NSMutableURLRequest *)request; + +/*! + Called after the specified update failed to download. + + \param updater The SUUpdater instance. + \param item The appcast item corresponding to the update that failed to download. + \param error The error generated by the failed download. + */ +- (void)updater:(SUUpdater *)updater failedToDownloadUpdate:(SUAppcastItem *)item error:(NSError *)error; + +/*! + Called when the user clicks the cancel button while and update is being downloaded. + + \param updater The SUUpdater instance. + */ +- (void)userDidCancelDownload:(SUUpdater *)updater; + +/*! + Called immediately before installing the specified update. + + \param updater The SUUpdater instance. + \param item The appcast item corresponding to the update that is proposed to be installed. + */ +- (void)updater:(SUUpdater *)updater willInstallUpdate:(SUAppcastItem *)item; + +/*! + Returns whether the relaunch should be delayed in order to perform other tasks. + + This is not called if the user didn't relaunch on the previous update, + in that case it will immediately restart. + + \param updater The SUUpdater instance. + \param item The appcast item corresponding to the update that is proposed to be installed. + \param invocation The invocation that must be completed with `[invocation invoke]` before continuing with the relaunch. + + \return \c YES to delay the relaunch until \p invocation is invoked. + */ +- (BOOL)updater:(SUUpdater *)updater shouldPostponeRelaunchForUpdate:(SUAppcastItem *)item untilInvoking:(NSInvocation *)invocation; + +/*! + Returns whether the application should be relaunched at all. + + Some apps \b cannot be relaunched under certain circumstances. + This method can be used to explicitly prevent a relaunch. + + \param updater The SUUpdater instance. + */ +- (BOOL)updaterShouldRelaunchApplication:(SUUpdater *)updater; + +/*! + Called immediately before relaunching. + + \param updater The SUUpdater instance. + */ +- (void)updaterWillRelaunchApplication:(SUUpdater *)updater; + +/*! + Returns an object that compares version numbers to determine their arithmetic relation to each other. + + This method allows you to provide a custom version comparator. + If you don't implement this method or return \c nil, + the standard version comparator will be used. + + \sa SUStandardVersionComparator + + \param updater The SUUpdater instance. + */ +- (id)versionComparatorForUpdater:(SUUpdater *)updater; + +/*! + Returns an object that formats version numbers for display to the user. + + If you don't implement this method or return \c nil, + the standard version formatter will be used. + + \sa SUUpdateAlert + + \param updater The SUUpdater instance. + */ +- (id)versionDisplayerForUpdater:(SUUpdater *)updater; + +/*! + Returns the path which is used to relaunch the client after the update is installed. + + The default is the path of the host bundle. + + \param updater The SUUpdater instance. + */ +- (NSString *)pathToRelaunchForUpdater:(SUUpdater *)updater; + +/*! + Called before an updater shows a modal alert window, + to give the host the opportunity to hide attached windows that may get in the way. + + \param updater The SUUpdater instance. + */ +- (void)updaterWillShowModalAlert:(SUUpdater *)updater; + +/*! + Called after an updater shows a modal alert window, + to give the host the opportunity to hide attached windows that may get in the way. + + \param updater The SUUpdater instance. + */ +- (void)updaterDidShowModalAlert:(SUUpdater *)updater; + +/*! + Called when an update is scheduled to be silently installed on quit. + This is after an update has been automatically downloaded in the background. + (i.e. SUUpdater::automaticallyDownloadsUpdates is YES) + + \param updater The SUUpdater instance. + \param item The appcast item corresponding to the update that is proposed to be installed. + \param invocation Can be used to trigger an immediate silent install and relaunch. + */ +- (void)updater:(SUUpdater *)updater willInstallUpdateOnQuit:(SUAppcastItem *)item immediateInstallationInvocation:(NSInvocation *)invocation; + +/*! + Calls after an update that was scheduled to be silently installed on quit has been canceled. + + \param updater The SUUpdater instance. + \param item The appcast item corresponding to the update that was proposed to be installed. + */ +- (void)updater:(SUUpdater *)updater didCancelInstallUpdateOnQuit:(SUAppcastItem *)item; + +/*! + Called after an update is aborted due to an error. + + \param updater The SUUpdater instance. + \param error The error that caused the abort + */ +- (void)updater:(SUUpdater *)updater didAbortWithError:(NSError *)error; + +@end diff --git a/Sparkle/SUUpdaterPrivate.h b/Sparkle/SUUpdaterPrivate.h new file mode 100644 index 00000000..3e7dad26 --- /dev/null +++ b/Sparkle/SUUpdaterPrivate.h @@ -0,0 +1,23 @@ +// +// SUUpdaterPrivate.h +// Sparkle +// +// Created by Andy Matuschak on 5/9/11. +// Copyright 2011 Andy Matuschak. All rights reserved. +// + +@protocol SUUpdaterDelegate; + +@protocol SUUpdaterPrivate + +@property (unsafe_unretained) IBOutlet id delegate; + +@property (nonatomic, copy) NSString *userAgentString; + +@property (copy) NSDictionary *httpHeaders; + +@property (nonatomic, copy) NSString *decryptionPassword; + +@property (strong, readonly) NSBundle *sparkleBundle; + +@end diff --git a/Sparkle/SUUpdater_Private.h b/Sparkle/SUUpdater_Private.h deleted file mode 100644 index 40091549..00000000 --- a/Sparkle/SUUpdater_Private.h +++ /dev/null @@ -1,15 +0,0 @@ -// -// SUUpdater_Private.h -// Sparkle -// -// Created by Andy Matuschak on 5/9/11. -// Copyright 2011 Andy Matuschak. All rights reserved. -// - -#import "SUUpdater.h" - -@interface SUUpdater (Private) - -@property (readonly) BOOL mayUpdateAndRestart; - -@end diff --git a/Sparkle/Sparkle.h b/Sparkle/Sparkle.h index fad7a1cb..d3f6ff2b 100644 --- a/Sparkle/Sparkle.h +++ b/Sparkle/Sparkle.h @@ -16,6 +16,7 @@ #import "SUAppcastItem.h" #import "SUStandardVersionComparator.h" #import "SUUpdater.h" +#import "SUUpdaterDelegate.h" #import "SUVersionComparisonProtocol.h" #import "SUVersionDisplayProtocol.h" #import "SUErrors.h" diff --git a/Tests/SUUpdaterTest.m b/Tests/SUUpdaterTest.m index 0ff7e930..c2c406a7 100644 --- a/Tests/SUUpdaterTest.m +++ b/Tests/SUUpdaterTest.m @@ -9,6 +9,7 @@ #import #import "SUConstants.h" #import "SUUpdater.h" +#import "SUUpdaterDelegate.h" @interface SUUpdaterTest : XCTestCase @property (strong) NSOperationQueue *queue; From 796967cf247a2e76cf645973984ca336679a895a Mon Sep 17 00:00:00 2001 From: Zorg Date: Sun, 25 Dec 2016 18:41:38 -0500 Subject: [PATCH 2/4] Allow delegate methods that return an object to return nil Returning nil from these delegate methods is equivalent to not implementing the delegate method. The caller should be able to make this kind of decision when implementing an optional delegate method. --- Sparkle/SUBasicUpdateDriver.m | 13 ++++++++++--- Sparkle/SUUpdater.m | 8 ++++++-- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/Sparkle/SUBasicUpdateDriver.m b/Sparkle/SUBasicUpdateDriver.m index 4d0487b4..b4f65b22 100644 --- a/Sparkle/SUBasicUpdateDriver.m +++ b/Sparkle/SUBasicUpdateDriver.m @@ -162,11 +162,15 @@ if ([[self.updater delegate] respondsToSelector:@selector(bestValidUpdateInAppcast:forUpdater:)]) // Does the delegate want to handle it? { item = [[self.updater delegate] bestValidUpdateInAppcast:ac forUpdater:(id)self.updater]; + } + + if (item != nil) // Does the delegate want to handle it? + { if ([item isDeltaUpdate]) { self.nonDeltaUpdateItem = [[self.updater delegate] bestValidUpdateInAppcast:[ac copyWithoutDeltaUpdates] forUpdater:(id)self.updater]; } - } - else // If not, we'll take care of it ourselves. + } + else // If not, we'll take care of it ourselves. { // Find the best supported update SUAppcastItem *deltaUpdateItem = nil; @@ -525,7 +529,10 @@ NSString *pathToRelaunch = [self.host bundlePath]; if ([updaterDelegate respondsToSelector:@selector(pathToRelaunchForUpdater:)]) { - pathToRelaunch = [updaterDelegate pathToRelaunchForUpdater:(id)self.updater]; + NSString *delegateRelaunchPath = [updaterDelegate pathToRelaunchForUpdater:(id)self.updater]; + if (delegateRelaunchPath != nil) { + pathToRelaunch = delegateRelaunchPath; + } } [NSTask launchedTaskWithLaunchPath:relaunchToolPath arguments:@[[self.host bundlePath], diff --git a/Sparkle/SUUpdater.m b/Sparkle/SUUpdater.m index c13974a5..522dd24c 100644 --- a/Sparkle/SUUpdater.m +++ b/Sparkle/SUUpdater.m @@ -435,8 +435,12 @@ static NSString *const SUUpdaterDefaultsObservationContext = @"SUUpdaterDefaults // A value in the user defaults overrides one in the Info.plist (so preferences panels can be created wherein users choose between beta / release feeds). NSString *appcastString = [self.host objectForKey:SUFeedURLKey]; - if ([self.delegate respondsToSelector:@selector(feedURLStringForUpdater:)]) - appcastString = [self.delegate feedURLStringForUpdater:self]; + if ([self.delegate respondsToSelector:@selector(feedURLStringForUpdater:)]) { + NSString *delegateAppcastString = [self.delegate feedURLStringForUpdater:self]; + if (delegateAppcastString != nil) { + appcastString = delegateAppcastString; + } + } if (!appcastString) // Can't find an appcast string! [NSException raise:@"SUNoFeedURL" format:@"You must specify the URL of the appcast as the %@ key in either the Info.plist or the user defaults!", SUFeedURLKey]; NSCharacterSet *quoteSet = [NSCharacterSet characterSetWithCharactersInString:@"\"\'"]; // Some feed publishers add quotes; strip 'em. From f016cd8086cccd5eafa9828405c9919f3bf8bad9 Mon Sep 17 00:00:00 2001 From: Zorg Date: Sun, 25 Dec 2016 18:45:49 -0500 Subject: [PATCH 3/4] Add nullability annotations to SUUpdaterDelegate.h --- Sparkle/SUUpdaterDelegate.h | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/Sparkle/SUUpdaterDelegate.h b/Sparkle/SUUpdaterDelegate.h index a6422d62..522764ed 100644 --- a/Sparkle/SUUpdaterDelegate.h +++ b/Sparkle/SUUpdaterDelegate.h @@ -17,6 +17,8 @@ @protocol SUVersionComparison, SUVersionDisplay; @class SUUpdater, SUAppcast, SUAppcastItem; +NS_ASSUME_NONNULL_BEGIN + // ----------------------------------------------------------------------------- // SUUpdater Notifications for events that might be interesting to more than just the delegate // The updater will be the notification object @@ -74,7 +76,7 @@ SU_EXPORT extern NSString *const SUUpdaterAppcastNotificationKey; \param updater The SUUpdater instance. */ -- (NSString *)feedURLStringForUpdater:(SUUpdater *)updater; +- (nullable NSString *)feedURLStringForUpdater:(SUUpdater *)updater; /*! Returns whether Sparkle should prompt the user about automatic update checks. @@ -105,7 +107,7 @@ SU_EXPORT extern NSString *const SUUpdaterAppcastNotificationKey; \param appcast The appcast that was downloaded from the remote server. \param updater The SUUpdater instance. */ -- (SUAppcastItem *)bestValidUpdateInAppcast:(SUAppcast *)appcast forUpdater:(SUUpdater *)updater; +- (nullable SUAppcastItem *)bestValidUpdateInAppcast:(SUAppcast *)appcast forUpdater:(SUUpdater *)updater; /*! Called when a valid update is found by the update driver. @@ -197,7 +199,7 @@ SU_EXPORT extern NSString *const SUUpdaterAppcastNotificationKey; \param updater The SUUpdater instance. */ -- (id)versionComparatorForUpdater:(SUUpdater *)updater; +- (nullable id)versionComparatorForUpdater:(SUUpdater *)updater; /*! Returns an object that formats version numbers for display to the user. @@ -209,7 +211,7 @@ SU_EXPORT extern NSString *const SUUpdaterAppcastNotificationKey; \param updater The SUUpdater instance. */ -- (id)versionDisplayerForUpdater:(SUUpdater *)updater; +- (nullable id)versionDisplayerForUpdater:(SUUpdater *)updater; /*! Returns the path which is used to relaunch the client after the update is installed. @@ -218,7 +220,7 @@ SU_EXPORT extern NSString *const SUUpdaterAppcastNotificationKey; \param updater The SUUpdater instance. */ -- (NSString *)pathToRelaunchForUpdater:(SUUpdater *)updater; +- (nullable NSString *)pathToRelaunchForUpdater:(SUUpdater *)updater; /*! Called before an updater shows a modal alert window, @@ -264,3 +266,5 @@ SU_EXPORT extern NSString *const SUUpdaterAppcastNotificationKey; - (void)updater:(SUUpdater *)updater didAbortWithError:(NSError *)error; @end + +NS_ASSUME_NONNULL_END From 468bcb96406e628a93b07107d85cc9264c0a99b5 Mon Sep 17 00:00:00 2001 From: Zorg Date: Mon, 26 Dec 2016 09:20:52 -0500 Subject: [PATCH 4/4] Remove typecasting self.updater to id --- Sparkle/SUAutomaticUpdateDriver.m | 17 ++++--- Sparkle/SUBasicUpdateDriver.m | 73 +++++++++++++++++++------------ Sparkle/SUProbingUpdateDriver.m | 10 +++-- Sparkle/SUScheduledUpdateDriver.m | 10 +++-- Sparkle/SUUIBasedUpdateDriver.m | 29 +++++++----- Sparkle/SUUpdateDriver.h | 7 ++- 6 files changed, 88 insertions(+), 58 deletions(-) diff --git a/Sparkle/SUAutomaticUpdateDriver.m b/Sparkle/SUAutomaticUpdateDriver.m index a8df1a4d..9ae7eb1e 100644 --- a/Sparkle/SUAutomaticUpdateDriver.m +++ b/Sparkle/SUAutomaticUpdateDriver.m @@ -78,7 +78,8 @@ static const NSTimeInterval SUAutomaticUpdatePromptImpatienceTimer = 60 * 60 * 2 self.willUpdateOnTermination = YES; - id updaterDelegate = [self.updater delegate]; + id updater = self.updater; + id updaterDelegate = [updater delegate]; if ([updaterDelegate respondsToSelector:@selector(updater:willInstallUpdateOnQuit:immediateInstallationInvocation:)]) { BOOL relaunch = YES; @@ -88,8 +89,8 @@ static const NSTimeInterval SUAutomaticUpdatePromptImpatienceTimer = 60 * 60 * 2 [invocation setArgument:&relaunch atIndex:2]; [invocation setArgument:&showUI atIndex:3]; [invocation setTarget:self]; - - [updaterDelegate updater:(id)self.updater willInstallUpdateOnQuit:self.updateItem immediateInstallationInvocation:invocation]; + + [updaterDelegate updater:self.updater willInstallUpdateOnQuit:self.updateItem immediateInstallationInvocation:invocation]; } // If this is marked as a critical update, we'll prompt the user to install it right away. @@ -118,9 +119,10 @@ static const NSTimeInterval SUAutomaticUpdatePromptImpatienceTimer = 60 * 60 * 2 self.willUpdateOnTermination = NO; - id updaterDelegate = [self.updater delegate]; + id updater = self.updater; + id updaterDelegate = [updater delegate]; if ([updaterDelegate respondsToSelector:@selector(updater:didCancelInstallUpdateOnQuit:)]) - [updaterDelegate updater:(id)self.updater didCancelInstallUpdateOnQuit:self.updateItem]; + [updaterDelegate updater:self.updater didCancelInstallUpdateOnQuit:self.updateItem]; } } @@ -215,9 +217,10 @@ static const NSTimeInterval SUAutomaticUpdatePromptImpatienceTimer = 60 * 60 * 2 } else { // Call delegate separately here because otherwise it won't know we stopped. // Normally this gets called by the superclass - id updaterDelegate = [self.updater delegate]; + id updater = self.updater; + id updaterDelegate = [updater delegate]; if ([updaterDelegate respondsToSelector:@selector(updater:didAbortWithError:)]) { - [updaterDelegate updater:(id)self.updater didAbortWithError:error]; + [updaterDelegate updater:self.updater didAbortWithError:error]; } [self abortUpdate]; diff --git a/Sparkle/SUBasicUpdateDriver.m b/Sparkle/SUBasicUpdateDriver.m index b4f65b22..2640f2eb 100644 --- a/Sparkle/SUBasicUpdateDriver.m +++ b/Sparkle/SUBasicUpdateDriver.m @@ -62,8 +62,9 @@ SUAppcast *appcast = [[SUAppcast alloc] init]; - [appcast setUserAgentString:[self.updater userAgentString]]; - [appcast setHttpHeaders:[self.updater httpHeaders]]; + id updater = self.updater; + [appcast setUserAgentString:[updater userAgentString]]; + [appcast setHttpHeaders:[updater httpHeaders]]; [appcast fetchAppcastFromURL:URL completionBlock:^(NSError *error) { if (error) { [self abortUpdateWithError:error]; @@ -76,10 +77,11 @@ - (id)versionComparator { id comparator = nil; - + id updater = self.updater; + // Give the delegate a chance to provide a custom version comparator - if ([[self.updater delegate] respondsToSelector:@selector(versionComparatorForUpdater:)]) { - comparator = [[self.updater delegate] versionComparatorForUpdater:(id)self.updater]; + if ([[updater delegate] respondsToSelector:@selector(versionComparatorForUpdater:)]) { + comparator = [[updater delegate] versionComparatorForUpdater:self.updater]; } // If we don't get a comparator from the delegate, use the default comparator @@ -149,8 +151,9 @@ - (void)appcastDidFinishLoading:(SUAppcast *)ac { - if ([[self.updater delegate] respondsToSelector:@selector(updater:didFinishLoadingAppcast:)]) { - [[self.updater delegate] updater:(id)self.updater didFinishLoadingAppcast:ac]; + id updater = self.updater; + if ([[updater delegate] respondsToSelector:@selector(updater:didFinishLoadingAppcast:)]) { + [[updater delegate] updater:self.updater didFinishLoadingAppcast:ac]; } NSDictionary *userInfo = (ac != nil) ? @{ SUUpdaterAppcastNotificationKey: ac } : nil; @@ -159,15 +162,15 @@ SUAppcastItem *item = nil; // Now we have to find the best valid update in the appcast. - if ([[self.updater delegate] respondsToSelector:@selector(bestValidUpdateInAppcast:forUpdater:)]) // Does the delegate want to handle it? + if ([[updater delegate] respondsToSelector:@selector(bestValidUpdateInAppcast:forUpdater:)]) // Does the delegate want to handle it? { - item = [[self.updater delegate] bestValidUpdateInAppcast:ac forUpdater:(id)self.updater]; + item = [[updater delegate] bestValidUpdateInAppcast:ac forUpdater:self.updater]; } if (item != nil) // Does the delegate want to handle it? { if ([item isDeltaUpdate]) { - self.nonDeltaUpdateItem = [[self.updater delegate] bestValidUpdateInAppcast:[ac copyWithoutDeltaUpdates] forUpdater:(id)self.updater]; + self.nonDeltaUpdateItem = [[updater delegate] bestValidUpdateInAppcast:[ac copyWithoutDeltaUpdates] forUpdater:self.updater]; } } else // If not, we'll take care of it ourselves. @@ -194,9 +197,11 @@ - (void)didFindValidUpdate { assert(self.updateItem); + + id updater = self.updater; - if ([[self.updater delegate] respondsToSelector:@selector(updater:didFindValidUpdate:)]) { - [[self.updater delegate] updater:(id)self.updater didFindValidUpdate:self.updateItem]; + if ([[updater delegate] respondsToSelector:@selector(updater:didFindValidUpdate:)]) { + [[updater delegate] updater:self.updater didFindValidUpdate:self.updateItem]; } [[NSNotificationCenter defaultCenter] postNotificationName:SUUpdaterDidFindValidUpdateNotification @@ -207,8 +212,10 @@ - (void)didNotFindUpdate { - if ([[self.updater delegate] respondsToSelector:@selector(updaterDidNotFindUpdate:)]) { - [[self.updater delegate] updaterDidNotFindUpdate:(id)self.updater]; + id updater = self.updater; + + if ([[updater delegate] respondsToSelector:@selector(updaterDidNotFindUpdate:)]) { + [[updater delegate] updaterDidNotFindUpdate:self.updater]; } [[NSNotificationCenter defaultCenter] postNotificationName:SUUpdaterDidNotFindUpdateNotification object:self.updater]; @@ -250,10 +257,12 @@ [[NSFileManager defaultManager] removeItemAtPath:appCachePath error:NULL]; } + id updater = self.updater; + NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[self.updateItem fileURL]]; - [request setValue:[self.updater userAgentString] forHTTPHeaderField:@"User-Agent"]; - if ([[self.updater delegate] respondsToSelector:@selector(updater:willDownloadUpdate:withRequest:)]) { - [[self.updater delegate] updater:(id)self.updater + [request setValue:[updater userAgentString] forHTTPHeaderField:@"User-Agent"]; + if ([[updater delegate] respondsToSelector:@selector(updater:willDownloadUpdate:withRequest:)]) { + [[updater delegate] updater:self.updater willDownloadUpdate:self.updateItem withRequest:request]; } @@ -299,9 +308,11 @@ if (!failingUrl) { failingUrl = [self.updateItem fileURL]; } + + id updater = self.updater; - if ([[self.updater delegate] respondsToSelector:@selector(updater:failedToDownloadUpdate:error:)]) { - [[self.updater delegate] updater:(id)self.updater + if ([[updater delegate] respondsToSelector:@selector(updater:failedToDownloadUpdate:error:)]) { + [[updater delegate] updater:self.updater failedToDownloadUpdate:self.updateItem error:error]; } @@ -326,7 +337,8 @@ - (void)extractUpdate { - id unarchiver = [SUUnarchiver unarchiverForPath:self.downloadPath updatingHostBundlePath:self.host.bundlePath decryptionPassword:self.updater.decryptionPassword]; + id updater = self.updater; + id unarchiver = [SUUnarchiver unarchiverForPath:self.downloadPath updatingHostBundlePath:self.host.bundlePath decryptionPassword:updater.decryptionPassword]; BOOL success; if (!unarchiver) { @@ -427,7 +439,8 @@ - (BOOL)mayUpdateAndRestart { - return (!self.updater.delegate || ![self.updater.delegate respondsToSelector:@selector(updaterShouldRelaunchApplication:)] || [self.updater.delegate updaterShouldRelaunchApplication:(id)self.updater]); + id updater = self.updater; + return (!updater.delegate || ![updater.delegate respondsToSelector:@selector(updaterShouldRelaunchApplication:)] || [updater.delegate updaterShouldRelaunchApplication:self.updater]); } - (void)installWithToolAndRelaunch:(BOOL)relaunch displayingUserInterface:(BOOL)showUI @@ -452,8 +465,9 @@ } // Give the host app an opportunity to postpone the install and relaunch. + id updater = self.updater; static BOOL postponedOnce = NO; - id updaterDelegate = [self.updater delegate]; + id updaterDelegate = [updater delegate]; if (!postponedOnce && [updaterDelegate respondsToSelector:@selector(updater:shouldPostponeRelaunchForUpdate:untilInvoking:)]) { NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:[[self class] instanceMethodSignatureForSelector:@selector(installWithToolAndRelaunch:)]]; @@ -461,17 +475,17 @@ [invocation setArgument:&relaunch atIndex:2]; [invocation setTarget:self]; postponedOnce = YES; - if ([updaterDelegate updater:(id)self.updater shouldPostponeRelaunchForUpdate:self.updateItem untilInvoking:invocation]) { + if ([updaterDelegate updater:self.updater shouldPostponeRelaunchForUpdate:self.updateItem untilInvoking:invocation]) { return; } } if ([updaterDelegate respondsToSelector:@selector(updater:willInstallUpdate:)]) { - [updaterDelegate updater:(id)self.updater willInstallUpdate:self.updateItem]; + [updaterDelegate updater:self.updater willInstallUpdate:self.updateItem]; } - NSBundle *sparkleBundle = self.updater.sparkleBundle; + NSBundle *sparkleBundle = updater.sparkleBundle; // Copy the relauncher into a temporary directory so we can get to it after the new version's installed. // Only the paranoid survive: if there's already a stray copy of relaunch there, we would have problems. @@ -515,7 +529,7 @@ self.relaunchPath = relaunchCopyTargetPath; // Set for backwards compatibility, in case any delegates modify it [[NSNotificationCenter defaultCenter] postNotificationName:SUUpdaterWillRestartNotification object:self]; if ([updaterDelegate respondsToSelector:@selector(updaterWillRelaunchApplication:)]) - [updaterDelegate updaterWillRelaunchApplication:(id)self.updater]; + [updaterDelegate updaterWillRelaunchApplication:self.updater]; NSString *relaunchToolPath = [[NSBundle bundleWithPath:self.relaunchPath] executablePath]; if (!relaunchToolPath || ![[NSFileManager defaultManager] fileExistsAtPath:self.relaunchPath]) { @@ -529,7 +543,7 @@ NSString *pathToRelaunch = [self.host bundlePath]; if ([updaterDelegate respondsToSelector:@selector(pathToRelaunchForUpdater:)]) { - NSString *delegateRelaunchPath = [updaterDelegate pathToRelaunchForUpdater:(id)self.updater]; + NSString *delegateRelaunchPath = [updaterDelegate pathToRelaunchForUpdater:self.updater]; if (delegateRelaunchPath != nil) { pathToRelaunch = delegateRelaunchPath; } @@ -599,9 +613,10 @@ } // Notify host app that update has aborted - id updaterDelegate = [self.updater delegate]; + id updater = self.updater; + id updaterDelegate = [updater delegate]; if ([updaterDelegate respondsToSelector:@selector(updater:didAbortWithError:)]) { - [updaterDelegate updater:(id)self.updater didAbortWithError:error]; + [updaterDelegate updater:self.updater didAbortWithError:error]; } [self abortUpdate]; diff --git a/Sparkle/SUProbingUpdateDriver.m b/Sparkle/SUProbingUpdateDriver.m index 872225de..a5af1d39 100644 --- a/Sparkle/SUProbingUpdateDriver.m +++ b/Sparkle/SUProbingUpdateDriver.m @@ -16,10 +16,11 @@ - (void)didFindValidUpdate { - id updaterDelegate = [self.updater delegate]; + id updater = self.updater; + id updaterDelegate = [updater delegate]; if ([updaterDelegate respondsToSelector:@selector(updater:didFindValidUpdate:)]) - [updaterDelegate updater:(id)self.updater didFindValidUpdate:self.updateItem]; + [updaterDelegate updater:self.updater didFindValidUpdate:self.updateItem]; NSDictionary *userInfo = (self.updateItem != nil) ? @{ SUUpdaterAppcastItemNotificationKey: self.updateItem } : nil; [[NSNotificationCenter defaultCenter] postNotificationName:SUUpdaterDidFindValidUpdateNotification object:self.updater userInfo:userInfo]; [self abortUpdate]; @@ -27,10 +28,11 @@ - (void)didNotFindUpdate { - id updaterDelegate = [self.updater delegate]; + id updater = self.updater; + id updaterDelegate = [updater delegate]; if ([updaterDelegate respondsToSelector:@selector(updaterDidNotFindUpdate:)]) { - [updaterDelegate updaterDidNotFindUpdate:(id)self.updater]; + [updaterDelegate updaterDidNotFindUpdate:self.updater]; } [[NSNotificationCenter defaultCenter] postNotificationName:SUUpdaterDidNotFindUpdateNotification object:self.updater]; diff --git a/Sparkle/SUScheduledUpdateDriver.m b/Sparkle/SUScheduledUpdateDriver.m index 5a5e2300..fcd1c853 100644 --- a/Sparkle/SUScheduledUpdateDriver.m +++ b/Sparkle/SUScheduledUpdateDriver.m @@ -28,10 +28,11 @@ - (void)didNotFindUpdate { - id updaterDelegate = [self.updater delegate]; + id updater = self.updater; + id updaterDelegate = [updater delegate]; if ([updaterDelegate respondsToSelector:@selector(updaterDidNotFindUpdate:)]) { - [updaterDelegate updaterDidNotFindUpdate:(id)self.updater]; + [updaterDelegate updaterDidNotFindUpdate:self.updater]; } [[NSNotificationCenter defaultCenter] postNotificationName:SUUpdaterDidNotFindUpdateNotification object:self.updater]; @@ -45,9 +46,10 @@ } else { // Call delegate separately here because otherwise it won't know we stopped. // Normally this gets called by the superclass - id updaterDelegate = [self.updater delegate]; + id updater = self.updater; + id updaterDelegate = [updater delegate]; if ([updaterDelegate respondsToSelector:@selector(updater:didAbortWithError:)]) { - [updaterDelegate updater:(id)self.updater didAbortWithError:error]; + [updaterDelegate updater:self.updater didAbortWithError:error]; } [self abortUpdate]; diff --git a/Sparkle/SUUIBasedUpdateDriver.m b/Sparkle/SUUIBasedUpdateDriver.m index 8fc57b76..6b602b44 100644 --- a/Sparkle/SUUIBasedUpdateDriver.m +++ b/Sparkle/SUUIBasedUpdateDriver.m @@ -56,8 +56,9 @@ - (void)didFindValidUpdate { - if ([[self.updater delegate] respondsToSelector:@selector(updater:didFindValidUpdate:)]) { - [[self.updater delegate] updater:(id)self.updater didFindValidUpdate:self.updateItem]; + id updater = self.updater; + if ([[updater delegate] respondsToSelector:@selector(updater:didFindValidUpdate:)]) { + [[updater delegate] updater:self.updater didFindValidUpdate:self.updateItem]; } if (self.automaticallyInstallUpdates) { @@ -70,8 +71,8 @@ }]; id versDisp = nil; - if ([[self.updater delegate] respondsToSelector:@selector(versionDisplayerForUpdater:)]) { - versDisp = [[self.updater delegate] versionDisplayerForUpdater:(id)self.updater]; + if ([[updater delegate] respondsToSelector:@selector(versionDisplayerForUpdater:)]) { + versDisp = [[updater delegate] versionDisplayerForUpdater:self.updater]; } [self.updateAlert setVersionDisplayer:versDisp]; @@ -92,8 +93,9 @@ - (void)didNotFindUpdate { - if ([[self.updater delegate] respondsToSelector:@selector(updaterDidNotFindUpdate:)]) - [[self.updater delegate] updaterDidNotFindUpdate:(id)self.updater]; + id updater = self.updater; + if ([[updater delegate] respondsToSelector:@selector(updaterDidNotFindUpdate:)]) + [[updater delegate] updaterDidNotFindUpdate:self.updater]; [[NSNotificationCenter defaultCenter] postNotificationName:SUUpdaterDidNotFindUpdateNotification object:self.updater]; if (!self.automaticallyInstallUpdates) { @@ -205,8 +207,10 @@ { if (self.download) { [self.download cancel]; - if ([[self.updater delegate] respondsToSelector:@selector(userDidCancelDownload:)]) { - [[self.updater delegate] userDidCancelDownload:(id)self.updater]; + + id updater = self.updater; + if ([[updater delegate] respondsToSelector:@selector(userDidCancelDownload:)]) { + [[updater delegate] userDidCancelDownload:self.updater]; } } [self abortUpdate]; @@ -293,8 +297,9 @@ - (void)showAlert:(NSAlert *)alert { - if ([[self.updater delegate] respondsToSelector:@selector(updaterWillShowModalAlert:)]) { - [[self.updater delegate] updaterWillShowModalAlert:(id)self.updater]; + id updater = self.updater; + if ([[updater delegate] respondsToSelector:@selector(updaterWillShowModalAlert:)]) { + [[updater delegate] updaterWillShowModalAlert:self.updater]; } // When showing a modal alert we need to ensure that background applications @@ -304,8 +309,8 @@ [alert setIcon:[SUApplicationInfo bestIconForBundle:self.host.bundle]]; [alert runModal]; - if ([[self.updater delegate] respondsToSelector:@selector(updaterDidShowModalAlert:)]) - [[self.updater delegate] updaterDidShowModalAlert:(id)self.updater]; + if ([[updater delegate] respondsToSelector:@selector(updaterDidShowModalAlert:)]) + [[updater delegate] updaterDidShowModalAlert:self.updater]; } @end diff --git a/Sparkle/SUUpdateDriver.h b/Sparkle/SUUpdateDriver.h index 05d9547e..7e132aa1 100644 --- a/Sparkle/SUUpdateDriver.h +++ b/Sparkle/SUUpdateDriver.h @@ -13,11 +13,14 @@ extern NSString *const SUUpdateDriverFinishedNotification; -@class SUHost; +@class SUHost, SUUpdater; @protocol SUUpdaterPrivate; @interface SUUpdateDriver : NSObject -@property (readonly, weak) id updater; +// We only have SUUpdater* forward declared intentionally (i.e, not #import'ing SUUpdater.h in the update drivers) +// This is so we can minimize what we can access using SUUpdaterPrivate +@property (readonly, weak) SUUpdater *updater; + @property (strong) SUHost *host; - (instancetype)initWithUpdater:(id)updater;