diff --git a/Sparkle.xcodeproj/project.pbxproj b/Sparkle.xcodeproj/project.pbxproj index 4c292ccb..54552499 100644 --- a/Sparkle.xcodeproj/project.pbxproj +++ b/Sparkle.xcodeproj/project.pbxproj @@ -1103,6 +1103,7 @@ 61CFB2C20E38496B007A1735 /* Drivers */ = { isa = PBXGroup; children = ( + 725CB9561C7120410064365A /* SUUserUpdaterDriver.h */, 61B93B250DD0FDD300DCD2F8 /* SUAutomaticUpdateDriver.h */, 61B93B260DD0FDD300DCD2F8 /* SUAutomaticUpdateDriver.m */, 61F83F6F0DBFE137006FDD30 /* SUBasicUpdateDriver.h */, @@ -1111,7 +1112,6 @@ 6101347A0DD2541A0049ACDF /* SUProbingUpdateDriver.m */, 61B93C070DD112FF00DCD2F8 /* SUScheduledUpdateDriver.h */, 61B93C080DD112FF00DCD2F8 /* SUScheduledUpdateDriver.m */, - 725CB9561C7120410064365A /* SUUserUpdaterDriver.h */, 61B93A390DD02D6400DCD2F8 /* SUUIBasedUpdateDriver.h */, 61B93A3A0DD02D6400DCD2F8 /* SUUIBasedUpdateDriver.m */, 610134710DD250470049ACDF /* SUUpdateDriver.h */, diff --git a/Sparkle/SUAutomaticUpdateDriver.m b/Sparkle/SUAutomaticUpdateDriver.m index 46363703..7b0bb1ca 100644 --- a/Sparkle/SUAutomaticUpdateDriver.m +++ b/Sparkle/SUAutomaticUpdateDriver.m @@ -43,14 +43,14 @@ static const NSTimeInterval SUAutomaticUpdatePromptImpatienceTimer = 60 * 60 * 2 { self.interruptible = NO; - [self.updater.userUpdaterDriver requestAutomaticUpdatePermissionWithAppcastItem:self.updateItem reply:^(SUAutomaticInstallationChoice choice) { + [self.updater.userUpdaterDriver showAutomaticUpdateFoundWithAppcastItem:self.updateItem reply:^(SUAutomaticInstallationChoice choice) { [self automaticUpdateAlertFinishedWithChoice:choice]; }]; } - (void)unarchiverDidFinish:(SUUnarchiver *)__unused ua { - [self.updater.userUpdaterDriver startListeningForTermination:^{ + [self.updater.userUpdaterDriver registerForAppTermination:^{ // We don't want to terminate the app if the user or someone else initiated a termination // Use a property instead of passing an argument to installWithToolAndRelaunch: // because we give the delegate an invocation to our install methods and @@ -96,7 +96,7 @@ static const NSTimeInterval SUAutomaticUpdatePromptImpatienceTimer = 60 * 60 * 2 { if (self.willUpdateOnTermination) { - [self.updater.userUpdaterDriver dismissAutomaticUpdateInstallation]; + [self.updater.userUpdaterDriver unregisterForAppTermination]; [[[NSWorkspace sharedWorkspace] notificationCenter] removeObserver:self name:NSWorkspaceWillPowerOffNotification object:nil]; @@ -125,6 +125,9 @@ static const NSTimeInterval SUAutomaticUpdatePromptImpatienceTimer = 60 * 60 * 2 self.isTerminating = NO; [self stopUpdatingOnTermination]; [self invalidateShowUpdateAlertTimer]; + + [self.updater.userUpdaterDriver dismissUpdateInstallation:SUAutomaticInstallationType]; + [super abortUpdate]; } diff --git a/Sparkle/SUSparkleUserUpdaterDriver.m b/Sparkle/SUSparkleUserUpdaterDriver.m index 81d860f7..7c9ddfe0 100644 --- a/Sparkle/SUSparkleUserUpdaterDriver.m +++ b/Sparkle/SUSparkleUserUpdaterDriver.m @@ -114,6 +114,18 @@ }); } +- (void)showAutomaticUpdateFoundWithAppcastItem:(SUAppcastItem *)appcastItem reply:(void (^)(SUAutomaticInstallationChoice))reply +{ + dispatch_async(dispatch_get_main_queue(), ^{ + SUAutomaticUpdateAlert *updateAlert = [[SUAutomaticUpdateAlert alloc] initWithAppcastItem:appcastItem host:self.host completionBlock:^(SUAutomaticInstallationChoice choice) { + reply(choice); + self.activeUpdateAlert = nil; + }]; + + [self setupActiveFocusForWindow:updateAlert]; + }); +} + - (void)showExtractionFinishedAndReadyToInstallAndRelaunch:(void (^)(void))installUpdateAndRelaunch { dispatch_async(dispatch_get_main_queue(), ^{ @@ -315,30 +327,7 @@ }); } -- (void)dismissUpdateInstallation -{ - dispatch_async(dispatch_get_main_queue(), ^{ - if (self.statusController) - { - [self.statusController close]; - self.statusController = nil; - } - }); -} - -- (void)requestAutomaticUpdatePermissionWithAppcastItem:(SUAppcastItem *)appcastItem reply:(void (^)(SUAutomaticInstallationChoice))reply -{ - dispatch_async(dispatch_get_main_queue(), ^{ - SUAutomaticUpdateAlert *updateAlert = [[SUAutomaticUpdateAlert alloc] initWithAppcastItem:appcastItem host:self.host completionBlock:^(SUAutomaticInstallationChoice choice) { - reply(choice); - self.activeUpdateAlert = nil; - }]; - - [self setupActiveFocusForWindow:updateAlert]; - }); -} - -- (void)startListeningForTermination:(void (^)(void))applicationWillTerminate +- (void)registerForAppTermination:(void (^)(void))applicationWillTerminate { dispatch_async(dispatch_get_main_queue(), ^{ // Sudden termination is available on 10.6+ @@ -350,21 +339,38 @@ }); } -- (void)applicationWillTerminate:(NSNotification *)__unused note -{ - if (self.applicationWillTerminate) { - self.applicationWillTerminate(); - self.applicationWillTerminate = nil; - } -} - -- (void)dismissAutomaticUpdateInstallation +- (void)unregisterForAppTermination { dispatch_async(dispatch_get_main_queue(), ^{ [[NSProcessInfo processInfo] enableSuddenTermination]; + [[NSNotificationCenter defaultCenter] removeObserver:self name:NSApplicationWillTerminateNotification object:nil]; self.applicationWillTerminate = nil; }); } +- (void)applicationWillTerminate:(NSNotification *)__unused note +{ + if (self.applicationWillTerminate) { + self.applicationWillTerminate(); + } +} + +- (void)dismissUpdateInstallation:(SUUpdateInstallationType)installationType +{ + dispatch_async(dispatch_get_main_queue(), ^{ + switch (installationType) { + case SUManualInstallationType: + if (self.statusController) + { + [self.statusController close]; + self.statusController = nil; + } + break; + case SUAutomaticInstallationType: + break; + } + }); +} + @end diff --git a/Sparkle/SUUIBasedUpdateDriver.m b/Sparkle/SUUIBasedUpdateDriver.m index b550a714..c2e4f618 100644 --- a/Sparkle/SUUIBasedUpdateDriver.m +++ b/Sparkle/SUUIBasedUpdateDriver.m @@ -145,7 +145,7 @@ // tabs open), the status window still stays on the screen and obscures // other windows; with this fix, it doesn't - [self.updater.userUpdaterDriver dismissUpdateInstallation]; + [self.updater.userUpdaterDriver dismissUpdateInstallation:SUManualInstallationType]; [super terminateApp]; } @@ -161,7 +161,7 @@ - (void)abortUpdate { - [self.updater.userUpdaterDriver dismissUpdateInstallation]; + [self.updater.userUpdaterDriver dismissUpdateInstallation:SUManualInstallationType]; [super abortUpdate]; } diff --git a/Sparkle/SUUserUpdaterDriver.h b/Sparkle/SUUserUpdaterDriver.h index d4e0f828..200b6d37 100644 --- a/Sparkle/SUUserUpdaterDriver.h +++ b/Sparkle/SUUserUpdaterDriver.h @@ -14,6 +14,12 @@ @protocol SUVersionDisplay; +#warning Is this really helpful and needed? +typedef NS_ENUM(NSUInteger, SUUpdateInstallationType) { + SUManualInstallationType, + SUAutomaticInstallationType +}; + @protocol SUUserUpdaterDriver #warning might need to whitelist class types for systemProfile.. need to test this @@ -24,6 +30,9 @@ - (void)showUpdateFoundWithAppcastItem:(SUAppcastItem *)appcastItem versionDisplayer:(id)versionDisplayer reply:(void (^)(SUUpdateAlertChoice))reply; +#warning maybe this should take a versionDisplayer too? +- (void)showAutomaticUpdateFoundWithAppcastItem:(SUAppcastItem *)appcastItem reply:(void (^)(SUAutomaticInstallationChoice))reply; + - (void)showUpdateNotFound; - (BOOL)showsUpdateNotFoundModally; @@ -39,12 +48,9 @@ - (void)showInstallingUpdate; -- (void)dismissUpdateInstallation; +- (void)registerForAppTermination:(void (^)(void))applicationWillTerminate; +- (void)unregisterForAppTermination; -#warning Automatic Installation stuff, should probably be put in a separate driver maybe? Hard to tell - -- (void)requestAutomaticUpdatePermissionWithAppcastItem:(SUAppcastItem *)appcastItem reply:(void (^)(SUAutomaticInstallationChoice))reply; -- (void)startListeningForTermination:(void (^)(void))applicationWillTerminate; -- (void)dismissAutomaticUpdateInstallation; +- (void)dismissUpdateInstallation:(SUUpdateInstallationType)installationType; @end diff --git a/TestApplication/SUUpdateSettingsWindowController.m b/TestApplication/SUUpdateSettingsWindowController.m index 77f08149..20d16721 100644 --- a/TestApplication/SUUpdateSettingsWindowController.m +++ b/TestApplication/SUUpdateSettingsWindowController.m @@ -43,6 +43,12 @@ reply(SUInstallUpdateChoice); } +- (void)showAutomaticUpdateFoundWithAppcastItem:(SUAppcastItem *)appcastItem reply:(void (^)(SUAutomaticInstallationChoice))reply +{ + NSLog(@"OK, requested automatic update permission.. replying.."); + reply(SUInstallLaterChoice); +} + - (void)showUpdateNotFound { NSLog(@":( there was no new update"); @@ -99,39 +105,39 @@ NSLog(@"Installing update..."); } -- (void)dismissUpdateInstallation +- (void)registerForAppTermination:(void (^)(void))applicationWillTerminate { - NSLog(@"Dismissing the installation."); -} - -- (void)requestAutomaticUpdatePermissionWithAppcastItem:(SUAppcastItem *)appcastItem reply:(void (^)(SUAutomaticInstallationChoice))reply -{ - NSLog(@"OK, requested automatic update permission.. replying.."); - reply(SUInstallLaterChoice); -} - -- (void)startListeningForTermination:(void (^)(void))applicationWillTerminate -{ - NSLog(@"Start listening for termination, eh?"); + NSLog(@"Registered for termination, eh?"); self.applicationWillTerminate = applicationWillTerminate; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationWillTerminate:) name:NSApplicationWillTerminateNotification object:nil]; } +- (void)unregisterForAppTermination +{ + self.applicationWillTerminate = nil; + + [[NSNotificationCenter defaultCenter] removeObserver:self name:NSApplicationWillTerminateNotification object:nil]; +} + - (void)applicationWillTerminate:(NSNotification *)__unused note { NSLog(@"Terminating app.."); if (self.applicationWillTerminate) { NSLog(@"App will terminate"); self.applicationWillTerminate(); - self.applicationWillTerminate = nil; } } -- (void)dismissAutomaticUpdateInstallation +- (void)dismissUpdateInstallation:(SUUpdateInstallationType)installationType { - NSLog(@"Done with automatic update installation"); - [[NSNotificationCenter defaultCenter] removeObserver:self name:NSApplicationWillTerminateNotification object:nil]; + NSLog(@"Dismissing the installation."); + switch (installationType) { + case SUManualInstallationType: + break; + case SUAutomaticInstallationType: + break; + } } @end