Cleaning up SUUserUpdateDriver protocol

This commit is contained in:
Zorg committed 2016-02-20 23:52:24 -05:00
1 parent 1ebb150a1b
commit 6b5a3547e7
6 files changed
+83 -62

No files matched your search

+1 -1
View File
@@ -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 */,
+6 -3
View File
@@ -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];
}
+39 -33
View File
@@ -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
+2 -2
View File
@@ -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];
}
+12 -6
View File
@@ -14,6 +14,12 @@
@protocol SUVersionDisplay;
#warning Is this really helpful and needed?
typedef NS_ENUM(NSUInteger, SUUpdateInstallationType) {
SUManualInstallationType,
SUAutomaticInstallationType
};
@protocol SUUserUpdaterDriver <NSObject>
#warning might need to whitelist class types for systemProfile.. need to test this
@@ -24,6 +30,9 @@
- (void)showUpdateFoundWithAppcastItem:(SUAppcastItem *)appcastItem versionDisplayer:(id<SUVersionDisplay>)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
@@ -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